Skip to content

Commit

Permalink
fix(pkger): fix bug where tasks are exported for notification rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenb2 committed Feb 27, 2020
1 parent 2295247 commit 1a12ebc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
10 changes: 10 additions & 0 deletions pkger/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ func (s *Service) cloneOrgTasks(ctx context.Context, orgID influxdb.ID) ([]Resou
return nil, err
}

rules, _, err := s.ruleSVC.FindNotificationRules(ctx, influxdb.NotificationRuleFilter{
OrgID: &orgID,
})
if err != nil {
return nil, err
}

mTeles := make(map[influxdb.ID]*influxdb.Task)
for i := range teles {
t := teles[i]
Expand All @@ -465,6 +472,9 @@ func (s *Service) cloneOrgTasks(ctx context.Context, orgID influxdb.ID) ([]Resou
for _, c := range checks {
delete(mTeles, c.GetTaskID())
}
for _, r := range rules {
delete(mTeles, r.GetTaskID())
}

resources := make([]ResourceToClone, 0, len(mTeles))
for _, t := range mTeles {
Expand Down
28 changes: 15 additions & 13 deletions pkger/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2634,21 +2634,22 @@ func TestService(t *testing.T) {
}, nil
}

expectedRule := &rule.HTTP{
Base: rule.Base{
ID: 12,
Name: "rule_0",
EndpointID: 2,
Every: mustDuration(t, time.Minute),
StatusRules: []notification.StatusRule{{CurrentLevel: notification.Critical}},
},
}
ruleSVC := mock.NewNotificationRuleStore()
ruleSVC.FindNotificationRulesF = func(ctx context.Context, f influxdb.NotificationRuleFilter, _ ...influxdb.FindOptions) ([]influxdb.NotificationRule, int, error) {
out := []influxdb.NotificationRule{&rule.HTTP{Base: rule.Base{ID: 91}}}
out := []influxdb.NotificationRule{expectedRule}
return out, len(out), nil
}
ruleSVC.FindNotificationRuleByIDF = func(ctx context.Context, id influxdb.ID) (influxdb.NotificationRule, error) {
return &rule.HTTP{
Base: rule.Base{
ID: id,
Name: "rule_0",
EndpointID: 2,
Every: mustDuration(t, time.Minute),
StatusRules: []notification.StatusRule{{CurrentLevel: notification.Critical}},
},
}, nil
return expectedRule, nil
}

labelSVC := mock.NewLabelService()
Expand All @@ -2670,6 +2671,7 @@ func TestService(t *testing.T) {
return []*influxdb.Task{
{ID: 31},
{ID: expectedCheck.TaskID}, // this one should be ignored in the return
{ID: expectedRule.TaskID}, // this one should be ignored in the return as well
{ID: 99, Type: influxdb.TaskSystemType}, // this one should be skipped since it is a system task
}, 3, nil
}
Expand Down Expand Up @@ -2722,7 +2724,7 @@ func TestService(t *testing.T) {

checks := summary.Checks
require.Len(t, checks, 1)
assert.Equal(t, "check_1", checks[0].Check.GetName())
assert.Equal(t, expectedCheck.Name, checks[0].Check.GetName())

dashs := summary.Dashboards
require.Len(t, dashs, 1)
Expand All @@ -2738,8 +2740,8 @@ func TestService(t *testing.T) {

rules := summary.NotificationRules
require.Len(t, rules, 1)
assert.Equal(t, "rule_0", rules[0].Name)
assert.Equal(t, "http", rules[0].EndpointName)
assert.Equal(t, expectedRule.Name, rules[0].Name)
assert.Equal(t, expectedRule.Type(), rules[0].EndpointName)

require.Len(t, summary.Tasks, 1)
task1 := summary.Tasks[0]
Expand Down

0 comments on commit 1a12ebc

Please sign in to comment.