feat(pkger): add support for exporting notification endpoints
parent
b8652ee178
commit
d42bbb3c64
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
### Features
|
||||
|
||||
1. [16234](https://github.com/influxdata/influxdb/pull/16234): add support for notification endpoints to influx templates/pkgs.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
1. [16235](https://github.com/influxdata/influxdb/pull/16235): Removed default frontend sorting when flux queries specify sorting
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ type cmdPkgBuilder struct {
|
|||
resourceType string
|
||||
buckets string
|
||||
dashboards string
|
||||
endpoints string
|
||||
labels string
|
||||
telegrafs string
|
||||
variables string
|
||||
|
|
@ -231,6 +232,7 @@ func (b *cmdPkgBuilder) cmdPkgExport() *cobra.Command {
|
|||
cmd.Flags().StringVar(&b.exportOpts.resourceType, "resource-type", "", "The resource type provided will be associated with all IDs via stdin.")
|
||||
cmd.Flags().StringVar(&b.exportOpts.buckets, "buckets", "", "List of bucket ids comma separated")
|
||||
cmd.Flags().StringVar(&b.exportOpts.dashboards, "dashboards", "", "List of dashboard ids comma separated")
|
||||
cmd.Flags().StringVar(&b.exportOpts.endpoints, "endpoints", "", "List of notification endpoint ids comma separated")
|
||||
cmd.Flags().StringVar(&b.exportOpts.labels, "labels", "", "List of label ids comma separated")
|
||||
cmd.Flags().StringVar(&b.exportOpts.telegrafs, "telegraf-configs", "", "List of telegraf config ids comma separated")
|
||||
cmd.Flags().StringVar(&b.exportOpts.variables, "variables", "", "List of variable ids comma separated")
|
||||
|
|
@ -255,6 +257,7 @@ func (b *cmdPkgBuilder) pkgExportRunEFn() func(*cobra.Command, []string) error {
|
|||
}{
|
||||
{kind: pkger.KindBucket, idStrs: strings.Split(b.exportOpts.buckets, ",")},
|
||||
{kind: pkger.KindDashboard, idStrs: strings.Split(b.exportOpts.dashboards, ",")},
|
||||
{kind: pkger.KindNotificationEndpoint, idStrs: strings.Split(b.exportOpts.endpoints, ",")},
|
||||
{kind: pkger.KindLabel, idStrs: strings.Split(b.exportOpts.labels, ",")},
|
||||
{kind: pkger.KindTelegraf, idStrs: strings.Split(b.exportOpts.telegrafs, ",")},
|
||||
{kind: pkger.KindVariable, idStrs: strings.Split(b.exportOpts.variables, ",")},
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointPagerDuty
|
||||
- kind: Notification_Endpoint_Pager_Duty
|
||||
name: pager_duty_notification_endpoint
|
||||
url: http://localhost:8080/orgs/7167eb6719fa34e5/alert-history
|
||||
routingKey: secret-sauce
|
||||
|
|
@ -310,7 +310,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointPagerDuty
|
||||
- kind: Notification_Endpoint_Pager_Duty
|
||||
name: pager_duty_notification_endpoint
|
||||
url: http://localhost:8080/orgs/7167eb6719fa34e5/alert-history
|
||||
routingKey:
|
||||
|
|
@ -342,6 +342,10 @@ spec:
|
|||
Kind: pkger.KindLabel,
|
||||
ID: influxdb.ID(labels[0].ID),
|
||||
},
|
||||
{
|
||||
Kind: pkger.KindNotificationEndpoint,
|
||||
ID: endpoints[0].NotificationEndpoint.GetID(),
|
||||
},
|
||||
{
|
||||
Kind: pkger.KindTelegraf,
|
||||
ID: teles[0].TelegrafConfig.ID,
|
||||
|
|
@ -392,9 +396,16 @@ spec:
|
|||
require.Len(t, dashs[0].Charts, 1)
|
||||
assert.Equal(t, influxdb.ViewPropertyTypeSingleStat, dashs[0].Charts[0].Properties.GetType())
|
||||
|
||||
newEndpoints := newSum.NotificationEndpoints
|
||||
require.Len(t, newEndpoints, 1)
|
||||
assert.Equal(t, endpoints[0].NotificationEndpoint.GetName(), newEndpoints[0].NotificationEndpoint.GetName())
|
||||
assert.Equal(t, endpoints[0].NotificationEndpoint.GetDescription(), newEndpoints[0].NotificationEndpoint.GetDescription())
|
||||
hasLabelAssociations(t, newEndpoints[0].LabelAssociations, 1, "label_1")
|
||||
|
||||
require.Len(t, newSum.TelegrafConfigs, 1)
|
||||
assert.Equal(t, teles[0].TelegrafConfig.Name, newSum.TelegrafConfigs[0].TelegrafConfig.Name)
|
||||
assert.Equal(t, teles[0].TelegrafConfig.Description, newSum.TelegrafConfigs[0].TelegrafConfig.Description)
|
||||
hasLabelAssociations(t, newSum.TelegrafConfigs[0].LabelAssociations, 1, "label_1")
|
||||
|
||||
vars := newSum.Variables
|
||||
require.Len(t, vars, 1)
|
||||
|
|
@ -528,7 +539,7 @@ spec:
|
|||
bucket = "rucket_3"
|
||||
[[inputs.cpu]]
|
||||
percpu = true
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: http_none_auth_notification_endpoint
|
||||
type: none
|
||||
description: http none auth desc
|
||||
|
|
@ -567,7 +578,7 @@ spec:
|
|||
associations:
|
||||
- kind: Label
|
||||
name: label_1
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: http_none_auth_notification_endpoint
|
||||
type: none
|
||||
description: new desc
|
||||
|
|
|
|||
|
|
@ -7131,6 +7131,7 @@ components:
|
|||
- bucket
|
||||
- dashboard
|
||||
- label
|
||||
- notification_endpoint
|
||||
- variable
|
||||
name:
|
||||
type: string
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"github.com/influxdata/influxdb"
|
||||
"github.com/influxdata/influxdb/notification/endpoint"
|
||||
)
|
||||
|
||||
// ResourceToClone is a resource that will be cloned.
|
||||
|
|
@ -301,6 +302,46 @@ func labelToResource(l influxdb.Label, name string) Resource {
|
|||
return r
|
||||
}
|
||||
|
||||
func endpointToResource(e influxdb.NotificationEndpoint, name string) Resource {
|
||||
if name == "" {
|
||||
name = e.GetName()
|
||||
}
|
||||
r := Resource{
|
||||
fieldName: name,
|
||||
}
|
||||
assignNonZeroStrings(r, map[string]string{
|
||||
fieldDescription: e.GetDescription(),
|
||||
fieldStatus: string(e.GetStatus()),
|
||||
})
|
||||
|
||||
switch actual := e.(type) {
|
||||
case *endpoint.HTTP:
|
||||
r[fieldKind] = KindNotificationEndpointHTTP.title()
|
||||
r[fieldNotificationEndpointHTTPMethod] = actual.Method
|
||||
r[fieldNotificationEndpointURL] = actual.URL
|
||||
r[fieldType] = actual.AuthMethod
|
||||
assignNonZeroSecrets(r, map[string]influxdb.SecretField{
|
||||
fieldNotificationEndpointPassword: actual.Password,
|
||||
fieldNotificationEndpointToken: actual.Token,
|
||||
fieldNotificationEndpointUsername: actual.Username,
|
||||
})
|
||||
case *endpoint.PagerDuty:
|
||||
r[fieldKind] = KindNotificationEndpointPagerDuty.title()
|
||||
r[fieldNotificationEndpointURL] = actual.ClientURL
|
||||
assignNonZeroSecrets(r, map[string]influxdb.SecretField{
|
||||
fieldNotificationEndpointRoutingKey: actual.RoutingKey,
|
||||
})
|
||||
case *endpoint.Slack:
|
||||
r[fieldKind] = KindNotificationEndpointSlack.title()
|
||||
r[fieldNotificationEndpointURL] = actual.URL
|
||||
assignNonZeroSecrets(r, map[string]influxdb.SecretField{
|
||||
fieldNotificationEndpointToken: actual.Token,
|
||||
})
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func telegrafToResource(t influxdb.TelegrafConfig, name string) Resource {
|
||||
if name == "" {
|
||||
name = t.Name
|
||||
|
|
@ -379,6 +420,19 @@ func assignNonZeroStrings(r Resource, m map[string]string) {
|
|||
}
|
||||
}
|
||||
|
||||
func assignNonZeroSecrets(r Resource, m map[string]influxdb.SecretField) {
|
||||
for field, secret := range m {
|
||||
if secret.Key == "" {
|
||||
continue
|
||||
}
|
||||
r[field] = Resource{
|
||||
fieldReferencesSecret: Resource{
|
||||
fieldKey: secret.Key,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stringsToColors(clrs []string) colors {
|
||||
newColors := make(colors, 0)
|
||||
for _, x := range clrs {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ const (
|
|||
KindBucket Kind = "bucket"
|
||||
KindDashboard Kind = "dashboard"
|
||||
KindLabel Kind = "label"
|
||||
KindNotificationEndpoint Kind = "notificationendpoint"
|
||||
KindNotificationEndpointPagerDuty Kind = "notificationendpointpagerduty"
|
||||
KindNotificationEndpointHTTP Kind = "notificationendpointhttp"
|
||||
KindNotificationEndpointSlack Kind = "notificationendpointslack"
|
||||
KindNotificationEndpoint Kind = "notification_endpoint"
|
||||
KindNotificationEndpointPagerDuty Kind = "notification_endpoint_pager_duty"
|
||||
KindNotificationEndpointHTTP Kind = "notification_endpoint_http"
|
||||
KindNotificationEndpointSlack Kind = "notification_endpoint_slack"
|
||||
KindPackage Kind = "package"
|
||||
KindTelegraf Kind = "telegraf"
|
||||
KindVariable Kind = "variable"
|
||||
|
|
@ -33,6 +33,7 @@ var kinds = map[Kind]bool{
|
|||
KindBucket: true,
|
||||
KindDashboard: true,
|
||||
KindLabel: true,
|
||||
KindNotificationEndpoint: true,
|
||||
KindNotificationEndpointHTTP: true,
|
||||
KindNotificationEndpointPagerDuty: true,
|
||||
KindNotificationEndpointSlack: true,
|
||||
|
|
|
|||
|
|
@ -2807,7 +2807,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointSlack
|
||||
- kind: Notification_Endpoint_Slack
|
||||
name: name1
|
||||
`,
|
||||
},
|
||||
|
|
@ -2826,7 +2826,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointPagerDuty
|
||||
- kind: Notification_Endpoint_Pager_Duty
|
||||
name: name1
|
||||
`,
|
||||
},
|
||||
|
|
@ -2845,7 +2845,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
method: GET
|
||||
`,
|
||||
|
|
@ -2865,7 +2865,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: none
|
||||
method: POST
|
||||
|
|
@ -2887,7 +2887,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: none
|
||||
url: http://example.com
|
||||
|
|
@ -2908,7 +2908,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: none
|
||||
method: GUT
|
||||
|
|
@ -2930,7 +2930,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: basic
|
||||
url: example.com
|
||||
|
|
@ -2953,7 +2953,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: basic
|
||||
method: POST
|
||||
|
|
@ -2976,7 +2976,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: basic
|
||||
method: POST
|
||||
|
|
@ -2998,7 +2998,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: bearer
|
||||
method: GET
|
||||
|
|
@ -3020,7 +3020,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: name1
|
||||
type: threeve
|
||||
method: GET
|
||||
|
|
@ -3042,10 +3042,10 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointSlack
|
||||
- kind: Notification_Endpoint_Slack
|
||||
name: dupe
|
||||
url: example.com
|
||||
- kind: NotificationEndpointSlack
|
||||
- kind: Notification_Endpoint_Slack
|
||||
name: dupe
|
||||
url: example.com
|
||||
`,
|
||||
|
|
@ -3065,7 +3065,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointSlack
|
||||
- kind: Notification_Endpoint_Slack
|
||||
name: dupe
|
||||
url: example.com
|
||||
status: rando bad status
|
||||
|
|
|
|||
|
|
@ -274,9 +274,13 @@ func (s *Service) cloneOrgResources(ctx context.Context, orgID influxdb.ID) ([]R
|
|||
resType: KindLabel.ResourceType(),
|
||||
cloneFn: s.cloneOrgLabels,
|
||||
},
|
||||
{
|
||||
resType: KindNotificationEndpoint.ResourceType(),
|
||||
cloneFn: s.cloneOrgNotificationEndpoints,
|
||||
},
|
||||
{
|
||||
resType: KindTelegraf.ResourceType(),
|
||||
cloneFn: s.cloneTelegrafs,
|
||||
cloneFn: s.cloneOrgTelegrafs,
|
||||
},
|
||||
{
|
||||
resType: KindVariable.ResourceType(),
|
||||
|
|
@ -353,11 +357,30 @@ func (s *Service) cloneOrgLabels(ctx context.Context, orgID influxdb.ID) ([]Reso
|
|||
return resources, nil
|
||||
}
|
||||
|
||||
func (s *Service) cloneTelegrafs(ctx context.Context, orgID influxdb.ID) ([]ResourceToClone, error) {
|
||||
func (s *Service) cloneOrgNotificationEndpoints(ctx context.Context, orgID influxdb.ID) ([]ResourceToClone, error) {
|
||||
endpoints, _, err := s.endpointSVC.FindNotificationEndpoints(ctx, influxdb.NotificationEndpointFilter{
|
||||
OrgID: &orgID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resources := make([]ResourceToClone, 0, len(endpoints))
|
||||
for _, e := range endpoints {
|
||||
resources = append(resources, ResourceToClone{
|
||||
Kind: KindNotificationEndpoint,
|
||||
ID: e.GetID(),
|
||||
})
|
||||
}
|
||||
return resources, nil
|
||||
}
|
||||
|
||||
func (s *Service) cloneOrgTelegrafs(ctx context.Context, orgID influxdb.ID) ([]ResourceToClone, error) {
|
||||
teles, _, err := s.teleSVC.FindTelegrafConfigs(ctx, influxdb.TelegrafConfigFilter{OrgID: &orgID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resources := make([]ResourceToClone, 0, len(teles))
|
||||
for _, t := range teles {
|
||||
resources = append(resources, ResourceToClone{
|
||||
|
|
@ -413,6 +436,15 @@ func (s *Service) resourceCloneToResource(ctx context.Context, r ResourceToClone
|
|||
return nil, err
|
||||
}
|
||||
newResource = labelToResource(*l, r.Name)
|
||||
case r.Kind.is(KindNotificationEndpoint),
|
||||
r.Kind.is(KindNotificationEndpointHTTP),
|
||||
r.Kind.is(KindNotificationEndpointPagerDuty),
|
||||
r.Kind.is(KindNotificationEndpointSlack):
|
||||
e, err := s.endpointSVC.FindNotificationEndpointByID(ctx, r.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newResource = endpointToResource(e, r.Name)
|
||||
case r.Kind.is(KindTelegraf):
|
||||
t, err := s.teleSVC.FindTelegrafConfigByID(ctx, r.ID)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1399,6 +1399,133 @@ func TestService(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("notification endpoints", func(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
newName string
|
||||
expected influxdb.NotificationEndpoint
|
||||
}{
|
||||
{
|
||||
name: "pager duty",
|
||||
expected: &endpoint.PagerDuty{
|
||||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pager duty with new name",
|
||||
newName: "new name",
|
||||
expected: &endpoint.PagerDuty{
|
||||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "slack",
|
||||
expected: &endpoint.Slack{
|
||||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
},
|
||||
URL: "http://example.com",
|
||||
Token: influxdb.SecretField{Key: "tokne"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "http basic",
|
||||
expected: &endpoint.HTTP{
|
||||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "basic",
|
||||
Method: "POST",
|
||||
URL: "http://example.com",
|
||||
Password: influxdb.SecretField{Key: "password"},
|
||||
Username: influxdb.SecretField{Key: "username"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "http bearer",
|
||||
expected: &endpoint.HTTP{
|
||||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "bearer",
|
||||
Method: "GET",
|
||||
URL: "http://example.com",
|
||||
Token: influxdb.SecretField{Key: "token"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "http none",
|
||||
expected: &endpoint.HTTP{
|
||||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "none",
|
||||
Method: "GET",
|
||||
URL: "http://example.com",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
fn := func(t *testing.T) {
|
||||
id := influxdb.ID(1)
|
||||
tt.expected.SetID(id)
|
||||
|
||||
endpointSVC := mock.NewNotificationEndpointService()
|
||||
endpointSVC.FindNotificationEndpointByIDF = func(ctx context.Context, id influxdb.ID) (influxdb.NotificationEndpoint, error) {
|
||||
if id != tt.expected.GetID() {
|
||||
return nil, errors.New("uh ohhh, wrong id here: " + id.String())
|
||||
}
|
||||
return tt.expected, nil
|
||||
}
|
||||
|
||||
svc := newTestService(WithNoticationEndpointSVC(endpointSVC))
|
||||
|
||||
resToClone := ResourceToClone{
|
||||
Kind: KindNotificationEndpoint,
|
||||
ID: tt.expected.GetID(),
|
||||
Name: tt.newName,
|
||||
}
|
||||
pkg, err := svc.CreatePkg(context.TODO(), CreateWithExistingResources(resToClone))
|
||||
require.NoError(t, err)
|
||||
|
||||
endpoints := pkg.Summary().NotificationEndpoints
|
||||
require.Len(t, endpoints, 1)
|
||||
|
||||
actual := endpoints[0].NotificationEndpoint
|
||||
expectedName := tt.expected.GetName()
|
||||
if tt.newName != "" {
|
||||
expectedName = tt.newName
|
||||
}
|
||||
assert.Equal(t, expectedName, actual.GetName())
|
||||
assert.Equal(t, tt.expected.GetDescription(), actual.GetDescription())
|
||||
assert.Equal(t, tt.expected.GetStatus(), actual.GetStatus())
|
||||
assert.Equal(t, tt.expected.SecretFields(), actual.SecretFields())
|
||||
}
|
||||
t.Run(tt.name, fn)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("variable", func(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
@ -1653,6 +1780,28 @@ func TestService(t *testing.T) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
endpointSVC := mock.NewNotificationEndpointService()
|
||||
endpointSVC.FindNotificationEndpointsF = func(ctx context.Context, f influxdb.NotificationEndpointFilter, _ ...influxdb.FindOptions) ([]influxdb.NotificationEndpoint, int, error) {
|
||||
id := influxdb.ID(2)
|
||||
endpoints := []influxdb.NotificationEndpoint{
|
||||
&endpoint.HTTP{Base: endpoint.Base{ID: &id}},
|
||||
}
|
||||
return endpoints, len(endpoints), nil
|
||||
}
|
||||
endpointSVC.FindNotificationEndpointByIDF = func(ctx context.Context, id influxdb.ID) (influxdb.NotificationEndpoint, error) {
|
||||
return &endpoint.HTTP{
|
||||
Base: endpoint.Base{
|
||||
ID: &id,
|
||||
Name: "http",
|
||||
},
|
||||
URL: "http://example.com",
|
||||
Username: influxdb.SecretField{Key: id.String() + "-username"},
|
||||
Password: influxdb.SecretField{Key: id.String() + "-password"},
|
||||
AuthMethod: "basic",
|
||||
Method: "POST",
|
||||
}, nil
|
||||
}
|
||||
|
||||
labelSVC := mock.NewLabelService()
|
||||
labelSVC.FindLabelsFn = func(_ context.Context, f influxdb.LabelFilter) ([]*influxdb.Label, error) {
|
||||
if f.OrgID == nil || *f.OrgID != orgID {
|
||||
|
|
@ -1685,25 +1834,31 @@ func TestService(t *testing.T) {
|
|||
WithBucketSVC(bktSVC),
|
||||
WithDashboardSVC(dashSVC),
|
||||
WithLabelSVC(labelSVC),
|
||||
WithNoticationEndpointSVC(endpointSVC),
|
||||
WithVariableSVC(varSVC),
|
||||
)
|
||||
|
||||
pkg, err := svc.CreatePkg(context.TODO(), CreateWithAllOrgResources(orgID))
|
||||
require.NoError(t, err)
|
||||
|
||||
bkts := pkg.Summary().Buckets
|
||||
summary := pkg.Summary()
|
||||
bkts := summary.Buckets
|
||||
require.Len(t, bkts, 1)
|
||||
assert.Equal(t, "bucket", bkts[0].Name)
|
||||
|
||||
dashs := pkg.Summary().Dashboards
|
||||
dashs := summary.Dashboards
|
||||
require.Len(t, dashs, 1)
|
||||
assert.Equal(t, "dashboard", dashs[0].Name)
|
||||
|
||||
labels := pkg.Summary().Labels
|
||||
labels := summary.Labels
|
||||
require.Len(t, labels, 1)
|
||||
assert.Equal(t, "label", labels[0].Name)
|
||||
|
||||
vars := pkg.Summary().Variables
|
||||
endpoints := summary.NotificationEndpoints
|
||||
require.Len(t, endpoints, 1)
|
||||
assert.Equal(t, "http", endpoints[0].NotificationEndpoint.GetName())
|
||||
|
||||
vars := summary.Variables
|
||||
require.Len(t, vars, 1)
|
||||
assert.Equal(t, "variable", vars[0].Name)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
"name": "label_1"
|
||||
},
|
||||
{
|
||||
"kind": "NotificationEndpointSlack",
|
||||
"kind": "Notification_Endpoint_Slack",
|
||||
"name": "slack_notification_endpoint",
|
||||
"description": "slack desc",
|
||||
"url": "https://hooks.slack.com/services/bip/piddy/boppidy",
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"kind": "NotificationEndpointHTTP",
|
||||
"kind": "Notification_Endpoint_HTTP",
|
||||
"name": "http_none_auth_notification_endpoint",
|
||||
"description": "http none auth desc",
|
||||
"method": "GET",
|
||||
|
|
@ -42,7 +42,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"kind": "NotificationEndpointHTTP",
|
||||
"kind": "Notification_Endpoint_HTTP",
|
||||
"name": "http_basic_auth_notification_endpoint",
|
||||
"description": "http basic auth desc",
|
||||
"method": "POST",
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"kind": "NotificationEndpointHTTP",
|
||||
"kind": "Notification_Endpoint_HTTP",
|
||||
"name": "http_bearer_auth_notification_endpoint",
|
||||
"description": "http bearer auth desc",
|
||||
"type": "bearer",
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"kind": "NotificationEndpointPagerDuty",
|
||||
"kind": "Notification_Endpoint_Pager_Duty",
|
||||
"name": "pager_duty_notification_endpoint",
|
||||
"description": "pager duty desc",
|
||||
"url": "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ spec:
|
|||
resources:
|
||||
- kind: Label
|
||||
name: label_1
|
||||
- kind: NotificationEndpointSlack
|
||||
- kind: Notification_Endpoint_Slack
|
||||
name: slack_notification_endpoint
|
||||
description: slack desc
|
||||
url: https://hooks.slack.com/services/bip/piddy/boppidy
|
||||
|
|
@ -17,7 +17,7 @@ spec:
|
|||
associations:
|
||||
- kind: Label
|
||||
name: label_1
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: http_none_auth_notification_endpoint
|
||||
type: none
|
||||
description: http none auth desc
|
||||
|
|
@ -27,7 +27,7 @@ spec:
|
|||
associations:
|
||||
- kind: Label
|
||||
name: label_1
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: http_basic_auth_notification_endpoint
|
||||
description: http basic auth desc
|
||||
type: basic
|
||||
|
|
@ -39,7 +39,7 @@ spec:
|
|||
associations:
|
||||
- kind: Label
|
||||
name: label_1
|
||||
- kind: NotificationEndpointHTTP
|
||||
- kind: Notification_Endpoint_HTTP
|
||||
name: http_bearer_auth_notification_endpoint
|
||||
description: http bearer auth desc
|
||||
type: bearer
|
||||
|
|
@ -49,7 +49,7 @@ spec:
|
|||
associations:
|
||||
- kind: Label
|
||||
name: label_1
|
||||
- kind: NotificationEndpointPagerDuty
|
||||
- kind: Notification_Endpoint_Pager_Duty
|
||||
name: pager_duty_notification_endpoint
|
||||
description: pager duty desc
|
||||
url: http://localhost:8080/orgs/7167eb6719fa34e5/alert-history
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ meta:
|
|||
description: pack description
|
||||
spec:
|
||||
resources:
|
||||
- kind: NotificationEndpointPagerDuty
|
||||
- kind: Notification_Endpoint_Pager_Duty
|
||||
name: pager_duty_notification_endpoint
|
||||
url: http://localhost:8080/orgs/7167eb6719fa34e5/alert-history
|
||||
routingKey:
|
||||
|
|
|
|||
Loading…
Reference in New Issue