From 53d9caf1c66336dc84912d1c79f9d3b9e3c83774 Mon Sep 17 00:00:00 2001 From: Kelvin Wang Date: Wed, 5 Feb 2020 11:01:57 -0500 Subject: [PATCH] fix(kv): fix patching panics --- CHANGELOG.md | 6 ++ kv/notification_rule.go | 6 +- testing/notification_rule.go | 139 +++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63a24803876..4f08f9c434d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Undecided + +### Bug Fixes + +1. [16733](https://github.com/influxdata/influxdb/pull/16733): Fix notification rule renaming panics from UI + ## v2.0.0-beta.2 [2020-01-24] ### Features diff --git a/kv/notification_rule.go b/kv/notification_rule.go index 004288ed7e3..5894b6fdc24 100644 --- a/kv/notification_rule.go +++ b/kv/notification_rule.go @@ -240,6 +240,10 @@ func (s *Service) patchNotificationRule(ctx context.Context, tx Tx, id influxdb. if upd.Description != nil { nr.SetDescription(*upd.Description) } + var status *string + if upd.Status != nil { + status = strPtr(string(*upd.Status)) + } nr.SetUpdatedAt(s.TimeGenerator.Now()) @@ -247,7 +251,7 @@ func (s *Service) patchNotificationRule(ctx context.Context, tx Tx, id influxdb. return nil, err } - _, err = s.updateNotificationTask(ctx, tx, nr, strPtr(string(*upd.Status))) + _, err = s.updateNotificationTask(ctx, tx, nr, status) if err != nil { return nil, err } diff --git a/testing/notification_rule.go b/testing/notification_rule.go index c273cf9a772..ee88e10cdc4 100644 --- a/testing/notification_rule.go +++ b/testing/notification_rule.go @@ -2002,6 +2002,145 @@ func PatchNotificationRule( }, }, }, + { + name: "patch without status", + fields: NotificationRuleFields{ + TimeGenerator: fakeGenerator, + IDGenerator: mock.NewIDGenerator(twoID, t), + Tasks: []influxdb.TaskCreate{ + { + OwnerID: MustIDBase16(sixID), + OrganizationID: MustIDBase16(fourID), + Flux: `from(bucket: "foo") |> range(start: -1m) + option task = {name: "bar", every: 1m} + `, + }, + }, + UserResourceMappings: []*influxdb.UserResourceMapping{ + { + ResourceID: MustIDBase16(oneID), + UserID: MustIDBase16(sixID), + UserType: influxdb.Owner, + ResourceType: influxdb.NotificationRuleResourceType, + }, + { + ResourceID: MustIDBase16(twoID), + UserID: MustIDBase16(sixID), + UserType: influxdb.Member, + ResourceType: influxdb.NotificationRuleResourceType, + }, + }, + Endpoints: []influxdb.NotificationEndpoint{ + &endpoint.Slack{ + URL: "http://localhost:7777", + Token: influxdb.SecretField{ + // TODO(desa): not sure why this has to end in token, but it does + Key: "020f755c3c082001-token", + Value: strPtr("abc123"), + }, + Base: endpoint.Base{ + OrgID: MustIDBase16Ptr(fourID), + Name: "foo", + Status: influxdb.Active, + }, + }, + }, + NotificationRules: []influxdb.NotificationRule{ + &rule.Slack{ + Base: rule.Base{ + ID: MustIDBase16(oneID), + Name: "name1", + OwnerID: MustIDBase16(sixID), + OrgID: MustIDBase16(fourID), + EndpointID: MustIDBase16(twoID), + RunbookLink: "runbooklink1", + SleepUntil: &time3, + Every: mustDuration("1h"), + StatusRules: []notification.StatusRule{ + { + CurrentLevel: notification.Critical, + }, + { + CurrentLevel: notification.Info, + }, + }, + CRUDLog: influxdb.CRUDLog{ + CreatedAt: timeGen1.Now(), + UpdatedAt: timeGen2.Now(), + }, + }, + Channel: "channel1", + MessageTemplate: "msg1", + }, + &rule.Slack{ + Base: rule.Base{ + ID: MustIDBase16(twoID), + Name: "name2", + OwnerID: MustIDBase16(sixID), + EndpointID: MustIDBase16(twoID), + TaskID: MustIDBase16(twoID), + StatusRules: []notification.StatusRule{ + { + CurrentLevel: notification.Critical, + }, + { + CurrentLevel: notification.Info, + }, + }, + OrgID: MustIDBase16(fourID), + RunbookLink: "runbooklink2", + SleepUntil: &time3, + Every: mustDuration("1h"), + CRUDLog: influxdb.CRUDLog{ + CreatedAt: timeGen1.Now(), + UpdatedAt: timeGen2.Now(), + }, + }, + MessageTemplate: "msg", + }, + }, + Orgs: []*influxdb.Organization{ + { + ID: MustIDBase16(fourID), + Name: "foo", + }, + }, + }, + args: args{ + id: MustIDBase16(twoID), + upd: influxdb.NotificationRuleUpdate{ + Name: &name3, + }, + }, + wants: wants{ + notificationRule: &rule.Slack{ + Base: rule.Base{ + ID: MustIDBase16(twoID), + Name: name3, + OwnerID: MustIDBase16(sixID), + OrgID: MustIDBase16(fourID), + EndpointID: MustIDBase16(twoID), + TaskID: MustIDBase16(twoID), + StatusRules: []notification.StatusRule{ + { + CurrentLevel: notification.Critical, + }, + { + CurrentLevel: notification.Info, + }, + }, + RunbookLink: "runbooklink2", + SleepUntil: &time3, + Every: mustDuration("1h"), + CRUDLog: influxdb.CRUDLog{ + CreatedAt: timeGen1.Now(), + UpdatedAt: fakeDate, + }, + }, + MessageTemplate: "msg", + }, + }, + }, { name: "regular patch", fields: NotificationRuleFields{