Skip to content

Commit

Permalink
fix(http): fix NotificationEndpoint: (#15148)
Browse files Browse the repository at this point in the history
* Add TraceSpan parameter to GetNotificationEndpoints operation
* Fixed handler path for a list of all labels for a notification endpoint
* Fixed filter NotificationEndpoints by limit and offset
  • Loading branch information
bednar authored and russorat committed Sep 23, 2019
1 parent 85f0875 commit 9f0d9f6
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 3 deletions.
2 changes: 1 addition & 1 deletion http/notification_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func NewNotificationEndpointHandler(b *NotificationEndpointBackend) *Notificatio
LabelService: b.LabelService,
ResourceType: influxdb.TelegrafsResourceType,
}
h.HandlerFunc("GET", notificationEndpointsIDLabelsIDPath, newGetLabelsHandler(labelBackend))
h.HandlerFunc("GET", notificationEndpointsIDLabelsPath, newGetLabelsHandler(labelBackend))
h.HandlerFunc("POST", notificationEndpointsIDLabelsPath, newPostLabelHandler(labelBackend))
h.HandlerFunc("DELETE", notificationEndpointsIDLabelsIDPath, newDeleteLabelHandler(labelBackend))

Expand Down
1 change: 1 addition & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5745,6 +5745,7 @@ paths:
- NotificationEndpoints
summary: Get all notification endpoints
parameters:
- $ref: '#/components/parameters/TraceSpan'
- $ref: '#/components/parameters/Offset'
- $ref: '#/components/parameters/Limit'
- in: query
Expand Down
2 changes: 1 addition & 1 deletion kv/notification_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (s *Service) findNotificationEndpointByID(ctx context.Context, tx Tx,
// Additional options provide pagination & sorting.
func (s *Service) FindNotificationEndpoints(ctx context.Context, filter influxdb.NotificationEndpointFilter, opt ...influxdb.FindOptions) (edps []influxdb.NotificationEndpoint, n int, err error) {
err = s.kv.View(ctx, func(tx Tx) error {
edps, n, err = s.findNotificationEndpoints(ctx, tx, filter)
edps, n, err = s.findNotificationEndpoints(ctx, tx, filter, opt...)
return err
})
return edps, n, err
Expand Down
165 changes: 164 additions & 1 deletion testing/notification_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func FindNotificationEndpoints(
) {
type args struct {
filter influxdb.NotificationEndpointFilter
opts influxdb.FindOptions
}

type wants struct {
Expand Down Expand Up @@ -693,6 +694,168 @@ func FindNotificationEndpoints(
},
},
},
{
name: "find options limit",
fields: NotificationEndpointFields{
Orgs: []*influxdb.Organization{
{
ID: MustIDBase16(oneID),
Name: "org1",
},
{
ID: MustIDBase16(fourID),
Name: "org4",
},
},
NotificationEndpoints: []influxdb.NotificationEndpoint{
&endpoint.Slack{
Base: endpoint.Base{
ID: MustIDBase16(oneID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp1",
},
URL: "example-slack.com",
Token: influxdb.SecretField{Key: oneID + "-token"},
},
&endpoint.HTTP{
Base: endpoint.Base{
ID: MustIDBase16(twoID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp2",
},
URL: "example-webhook.com",
Method: http.MethodGet,
AuthMethod: "none",
},
&endpoint.PagerDuty{
Base: endpoint.Base{
ID: MustIDBase16(fourID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp3",
},
ClientURL: "example-pagerduty.com",
RoutingKey: influxdb.SecretField{Key: fourID + "-routing-key"},
},
},
},
args: args{
filter: influxdb.NotificationEndpointFilter{
Org: strPtr("org4"),
},
opts: influxdb.FindOptions{
Limit: 2,
},
},
wants: wants{
notificationEndpoints: []influxdb.NotificationEndpoint{
&endpoint.Slack{
Base: endpoint.Base{
ID: MustIDBase16(oneID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp1",
},
URL: "example-slack.com",
Token: influxdb.SecretField{Key: oneID + "-token"},
},
&endpoint.HTTP{
Base: endpoint.Base{
ID: MustIDBase16(twoID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp2",
},
URL: "example-webhook.com",
Method: http.MethodGet,
AuthMethod: "none",
},
},
},
},
{
name: "find options offset",
fields: NotificationEndpointFields{
Orgs: []*influxdb.Organization{
{
ID: MustIDBase16(oneID),
Name: "org1",
},
{
ID: MustIDBase16(fourID),
Name: "org4",
},
},
NotificationEndpoints: []influxdb.NotificationEndpoint{
&endpoint.Slack{
Base: endpoint.Base{
ID: MustIDBase16(oneID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp1",
},
URL: "example-slack.com",
Token: influxdb.SecretField{Key: oneID + "-token"},
},
&endpoint.HTTP{
Base: endpoint.Base{
ID: MustIDBase16(twoID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp2",
},
URL: "example-webhook.com",
Method: http.MethodGet,
AuthMethod: "none",
},
&endpoint.PagerDuty{
Base: endpoint.Base{
ID: MustIDBase16(fourID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp3",
},
ClientURL: "example-pagerduty.com",
RoutingKey: influxdb.SecretField{Key: fourID + "-routing-key"},
},
},
},
args: args{
filter: influxdb.NotificationEndpointFilter{
Org: strPtr("org4"),
},
opts: influxdb.FindOptions{
Offset: 1,
},
},
wants: wants{
notificationEndpoints: []influxdb.NotificationEndpoint{
&endpoint.HTTP{
Base: endpoint.Base{
ID: MustIDBase16(twoID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp2",
},
URL: "example-webhook.com",
Method: http.MethodGet,
AuthMethod: "none",
},
&endpoint.PagerDuty{
Base: endpoint.Base{
ID: MustIDBase16(fourID),
OrgID: MustIDBase16(fourID),
Status: influxdb.Active,
Name: "edp3",
},
ClientURL: "example-pagerduty.com",
RoutingKey: influxdb.SecretField{Key: fourID + "-routing-key"},
},
},
},
},
{
name: "find by id",
fields: NotificationEndpointFields{
Expand Down Expand Up @@ -876,7 +1039,7 @@ func FindNotificationEndpoints(
defer done()
ctx := context.Background()

edps, n, err := s.FindNotificationEndpoints(ctx, tt.args.filter)
edps, n, err := s.FindNotificationEndpoints(ctx, tt.args.filter, tt.args.opts)
ErrorsEqual(t, err, tt.wants.err)
if n != len(tt.wants.notificationEndpoints) {
t.Fatalf("notification endpoints length is different got %d, want %d", n, len(tt.wants.notificationEndpoints))
Expand Down

0 comments on commit 9f0d9f6

Please sign in to comment.