feat(pkger): add env ref fields for remaining resources

pull/16735/head
Johnny Steenbergen 2020-02-04 17:23:28 -08:00 committed by Johnny Steenbergen
parent 64c8707594
commit 036ba49e12
7 changed files with 335 additions and 88 deletions

View File

@ -553,6 +553,91 @@ metadata:
envRef:
key: "bkt-1-name-ref"
spec:
---
apiVersion: %[1]s
kind: Label
metadata:
name:
envRef:
key: "label-1-name-ref"
spec:
---
apiVersion: influxdata.com/v2alpha1
kind: CheckDeadman
metadata:
name:
envRef:
key: check-1-name-ref
spec:
every: 5m
level: cRiT
query: >
from(bucket: "rucket_1") |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
statusMessageTemplate: "Check: ${ r._check_name } is: ${ r._level }"
---
apiVersion: influxdata.com/v2alpha1
kind: Dashboard
metadata:
name:
envRef:
key: dash-1-name-ref
spec:
---
apiVersion: influxdata.com/v2alpha1
kind: NotificationEndpointSlack
metadata:
name:
envRef:
key: endpoint-1-name-ref
spec:
url: https://hooks.slack.com/services/bip/piddy/boppidy
---
apiVersion: influxdata.com/v2alpha1
kind: NotificationRule
metadata:
name:
envRef:
key: rule-1-name-ref
spec:
endpointName:
envRef:
key: endpoint-1-name-ref
every: 10m
messageTemplate: "Notification Rule: ${ r._notification_rule_name } triggered by check: ${ r._check_name }: ${ r._message }"
statusRules:
- currentLevel: WARN
---
apiVersion: influxdata.com/v2alpha1
kind: Telegraf
metadata:
name:
envRef:
key: telegraf-1-name-ref
spec:
config: |
[agent]
interval = "10s"
---
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name:
envRef:
key: task-1-name-ref
spec:
cron: 15 * * * *
query: >
from(bucket: "rucket_1")
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name:
envRef:
key: var-1-name-ref
spec:
type: constant
values: [first val]
`, pkger.APIVersion)
pkg, err := pkger.Parse(pkger.EncodingYAML, pkger.FromString(pkgStr))
@ -563,14 +648,59 @@ spec:
require.Len(t, sum.Buckets, 1)
assert.Equal(t, "$bkt-1-name-ref", sum.Buckets[0].Name)
assert.Equal(t, []string{"bkt-1-name-ref"}, sum.MissingEnvs)
require.Len(t, sum.Checks, 1)
assert.Equal(t, "$check-1-name-ref", sum.Checks[0].Check.GetName())
require.Len(t, sum.Dashboards, 1)
assert.Equal(t, "$dash-1-name-ref", sum.Dashboards[0].Name)
require.Len(t, sum.Labels, 1)
assert.Equal(t, "$label-1-name-ref", sum.Labels[0].Name)
require.Len(t, sum.NotificationEndpoints, 1)
assert.Equal(t, "$endpoint-1-name-ref", sum.NotificationEndpoints[0].NotificationEndpoint.GetName())
require.Len(t, sum.NotificationRules, 1)
assert.Equal(t, "$rule-1-name-ref", sum.NotificationRules[0].Name)
require.Len(t, sum.TelegrafConfigs, 1)
assert.Equal(t, "$task-1-name-ref", sum.Tasks[0].Name)
require.Len(t, sum.TelegrafConfigs, 1)
assert.Equal(t, "$telegraf-1-name-ref", sum.TelegrafConfigs[0].TelegrafConfig.Name)
require.Len(t, sum.Variables, 1)
assert.Equal(t, "$var-1-name-ref", sum.Variables[0].Name)
expectedMissingEnvs := []string{
"bkt-1-name-ref",
"check-1-name-ref",
"dash-1-name-ref",
"endpoint-1-name-ref",
"label-1-name-ref",
"rule-1-name-ref",
"task-1-name-ref",
"telegraf-1-name-ref",
"var-1-name-ref",
}
assert.Equal(t, expectedMissingEnvs, sum.MissingEnvs)
sum, err = svc.Apply(timedCtx(time.Second), l.Org.ID, l.User.ID, pkg, pkger.ApplyWithEnvRefs(map[string]string{
"bkt-1-name-ref": "rucket_threeve",
"bkt-1-name-ref": "rucket_threeve",
"check-1-name-ref": "check_threeve",
"dash-1-name-ref": "dash_threeve",
"endpoint-1-name-ref": "endpoint_threeve",
"label-1-name-ref": "label_threeve",
"rule-1-name-ref": "rule_threeve",
"telegraf-1-name-ref": "telegraf_threeve",
"task-1-name-ref": "task_threeve",
"var-1-name-ref": "var_threeve",
}))
require.NoError(t, err)
assert.Equal(t, "rucket_threeve", sum.Buckets[0].Name)
assert.Equal(t, "check_threeve", sum.Checks[0].Check.GetName())
assert.Equal(t, "dash_threeve", sum.Dashboards[0].Name)
assert.Equal(t, "endpoint_threeve", sum.NotificationEndpoints[0].NotificationEndpoint.GetName())
assert.Equal(t, "label_threeve", sum.Labels[0].Name)
assert.Equal(t, "rule_threeve", sum.NotificationRules[0].Name)
assert.Equal(t, "endpoint_threeve", sum.NotificationRules[0].EndpointName)
assert.Equal(t, "telegraf_threeve", sum.TelegrafConfigs[0].TelegrafConfig.Name)
assert.Equal(t, "task_threeve", sum.Tasks[0].Name)
assert.Equal(t, "var_threeve", sum.Variables[0].Name)
assert.Empty(t, sum.MissingEnvs)
})
}

View File

@ -415,7 +415,7 @@ func newDiffNotificationRule(r *notificationRule, iEndpoint influxdb.Notificatio
sum := DiffNotificationRule{
Name: r.Name(),
Description: r.description,
EndpointName: r.endpointName,
EndpointName: r.endpointName.String(),
Every: r.every.String(),
Offset: r.offset.String(),
MessageTemplate: r.msgTemplate,
@ -444,7 +444,7 @@ type DiffTask struct {
func newDiffTask(t *task) DiffTask {
return DiffTask{
Name: t.name,
Name: t.Name(),
Cron: t.cron,
Description: t.description,
Every: durToStr(t.every),
@ -940,7 +940,7 @@ type check struct {
id influxdb.ID
orgID influxdb.ID
kind checkKind
name string
name *references
description string
every time.Duration
level string
@ -975,7 +975,7 @@ func (c *check) Labels() []*label {
}
func (c *check) Name() string {
return c.name
return c.name.String()
}
func (c *check) ResourceType() influxdb.ResourceType {
@ -1220,7 +1220,7 @@ const (
type label struct {
id influxdb.ID
OrgID influxdb.ID
name string
name *references
Color string
Description string
associationMapping
@ -1232,7 +1232,7 @@ type label struct {
}
func (l *label) Name() string {
return l.name
return l.name.String()
}
func (l *label) ID() influxdb.ID {
@ -1313,7 +1313,7 @@ func (s sortedLabels) Len() int {
}
func (s sortedLabels) Less(i, j int) bool {
return s[i].name < s[j].name
return s[i].Name() < s[j].Name()
}
func (s sortedLabels) Swap(i, j int) {
@ -1347,7 +1347,7 @@ type notificationEndpoint struct {
kind notificationKind
id influxdb.ID
OrgID influxdb.ID
name string
name *references
description string
method string
password *references
@ -1379,7 +1379,7 @@ func (n *notificationEndpoint) Labels() []*label {
}
func (n *notificationEndpoint) Name() string {
return n.name
return n.name.String()
}
func (n *notificationEndpoint) ResourceType() influxdb.ResourceType {
@ -1549,7 +1549,7 @@ const (
type notificationRule struct {
id influxdb.ID
orgID influxdb.ID
name string
name *references
channel string
description string
@ -1561,7 +1561,7 @@ type notificationRule struct {
tagRules []struct{ k, v, op string }
endpointID influxdb.ID
endpointName string
endpointName *references
endpointType string
labels sortedLabels
@ -1580,7 +1580,7 @@ func (r *notificationRule) Labels() []*label {
}
func (r *notificationRule) Name() string {
return r.name
return r.name.String()
}
func (r *notificationRule) ResourceType() influxdb.ResourceType {
@ -1599,7 +1599,7 @@ func (r *notificationRule) summarize() SummaryNotificationRule {
ID: SafeID(r.ID()),
Name: r.Name(),
EndpointID: SafeID(r.endpointID),
EndpointName: r.endpointName,
EndpointName: r.endpointName.String(),
EndpointType: r.endpointType,
Description: r.description,
Every: r.every.String(),
@ -1663,7 +1663,7 @@ func (r *notificationRule) toInfluxRule() influxdb.NotificationRule {
func (r *notificationRule) valid() []validationErr {
var vErrs []validationErr
if r.endpointName == "" {
if !r.endpointName.hasValue() {
vErrs = append(vErrs, validationErr{
Field: fieldNotificationRuleEndpointName,
Msg: "must be provided",
@ -1790,7 +1790,7 @@ const (
type task struct {
id influxdb.ID
orgID influxdb.ID
name string
name *references
cron string
description string
every time.Duration
@ -1814,7 +1814,7 @@ func (t *task) Labels() []*label {
}
func (t *task) Name() string {
return t.name
return t.name.String()
}
func (t *task) ResourceType() influxdb.ResourceType {
@ -1907,6 +1907,7 @@ const (
)
type telegraf struct {
name *references
config influxdb.TelegrafConfig
labels sortedLabels
@ -1921,7 +1922,7 @@ func (t *telegraf) Labels() []*label {
}
func (t *telegraf) Name() string {
return t.config.Name
return t.name.String()
}
func (t *telegraf) ResourceType() influxdb.ResourceType {
@ -1933,8 +1934,10 @@ func (t *telegraf) Exists() bool {
}
func (t *telegraf) summarize() SummaryTelegraf {
cfg := t.config
cfg.Name = t.Name()
return SummaryTelegraf{
TelegrafConfig: t.config,
TelegrafConfig: cfg,
LabelAssociations: toSummaryLabels(t.labels...),
}
}
@ -1958,7 +1961,7 @@ const (
type variable struct {
id influxdb.ID
OrgID influxdb.ID
name string
name *references
Description string
Type string
Query string
@ -1987,7 +1990,7 @@ func (v *variable) Labels() []*label {
}
func (v *variable) Name() string {
return v.name
return v.name.String()
}
func (v *variable) ResourceType() influxdb.ResourceType {
@ -2081,7 +2084,7 @@ const (
type dashboard struct {
id influxdb.ID
OrgID influxdb.ID
name string
name *references
Description string
Charts []chart
@ -2097,7 +2100,7 @@ func (d *dashboard) Labels() []*label {
}
func (d *dashboard) Name() string {
return d.name
return d.name.String()
}
func (d *dashboard) ResourceType() influxdb.ResourceType {

View File

@ -51,14 +51,14 @@ func TestPkg(t *testing.T) {
"2": {
id: influxdb.ID(2),
OrgID: influxdb.ID(100),
name: "name2",
name: &references{val: "name2"},
Description: "desc2",
Color: "blurple",
},
"1": {
id: influxdb.ID(1),
OrgID: influxdb.ID(100),
name: "name1",
name: &references{val: "name1"},
Description: "desc1",
Color: "peru",
},
@ -91,7 +91,7 @@ func TestPkg(t *testing.T) {
label1 := &label{
id: influxdb.ID(2),
OrgID: influxdb.ID(100),
name: "name2",
name: &references{val: "name2"},
Description: "desc2",
Color: "blurple",
associationMapping: associationMapping{

View File

@ -449,7 +449,7 @@ func (p *Pkg) labels() []*label {
func (p *Pkg) dashboards() []*dashboard {
dashes := p.mDashboards[:]
sort.Slice(dashes, func(i, j int) bool { return dashes[i].name < dashes[j].name })
sort.Slice(dashes, func(i, j int) bool { return dashes[i].Name() < dashes[j].Name() })
return dashes
}
@ -470,7 +470,7 @@ func (p *Pkg) notificationEndpoints() []*notificationEndpoint {
func (p *Pkg) notificationRules() []*notificationRule {
rules := p.mNotificationRules[:]
sort.Slice(rules, func(i, j int) bool { return rules[i].name < rules[j].name })
sort.Slice(rules, func(i, j int) bool { return rules[i].Name() < rules[j].Name() })
return rules
}
@ -485,6 +485,7 @@ func (p *Pkg) missingEnvRefs() []string {
break
}
}
sort.Strings(envRefs)
return envRefs
}
@ -508,7 +509,11 @@ func (p *Pkg) tasks() []*task {
}
func (p *Pkg) telegrafs() []*telegraf {
teles := p.mTelegrafs[:]
teles := make([]*telegraf, 0, len(p.mTelegrafs))
for _, t := range p.mTelegrafs {
t.config.Name = t.Name()
teles = append(teles, t)
}
sort.Slice(teles, func(i, j int) bool { return teles[i].Name() < teles[j].Name() })
return teles
}
@ -519,7 +524,7 @@ func (p *Pkg) variables() []*variable {
vars = append(vars, v)
}
sort.Slice(vars, func(i, j int) bool { return vars[i].name < vars[j].name })
sort.Slice(vars, func(i, j int) bool { return vars[i].Name() < vars[j].Name() })
return vars
}
@ -613,10 +618,10 @@ func (p *Pkg) graphResources() error {
func (p *Pkg) graphBuckets() *parseErr {
p.mBuckets = make(map[string]*bucket)
return p.eachResource(KindBucket, 2, func(k Object) []validationErr {
nameRef := k.Metadata.references("name")
nameRef := k.Metadata.references(fieldName)
if _, ok := p.mBuckets[nameRef.String()]; ok {
return []validationErr{{
Field: "name",
Field: fieldName,
Msg: "duplicate name: " + nameRef.String(),
}}
}
@ -653,17 +658,21 @@ func (p *Pkg) graphBuckets() *parseErr {
func (p *Pkg) graphLabels() *parseErr {
p.mLabels = make(map[string]*label)
return p.eachResource(KindLabel, 2, func(k Object) []validationErr {
if _, ok := p.mLabels[k.Name()]; ok {
nameRef := k.Metadata.references(fieldName)
if _, ok := p.mLabels[nameRef.String()]; ok {
return []validationErr{{
Field: "name",
Field: fieldName,
Msg: "duplicate name: " + k.Name(),
}}
}
p.mLabels[k.Name()] = &label{
name: k.Name(),
l := &label{
name: nameRef,
Color: k.Spec.stringShort(fieldLabelColor),
Description: k.Spec.stringShort(fieldDescription),
}
p.mLabels[l.Name()] = l
p.setRefs(nameRef)
return nil
})
@ -682,16 +691,17 @@ func (p *Pkg) graphChecks() *parseErr {
var pErr parseErr
for _, checkKind := range checkKinds {
err := p.eachResource(checkKind.kind, 1, func(k Object) []validationErr {
if _, ok := p.mChecks[k.Name()]; ok {
nameRef := k.Metadata.references(fieldName)
if _, ok := p.mChecks[nameRef.String()]; ok {
return []validationErr{{
Field: "name",
Field: fieldName,
Msg: "duplicate name: " + k.Name(),
}}
}
ch := &check{
kind: checkKind.checkKind,
name: k.Name(),
name: nameRef,
description: k.Spec.stringShort(fieldDescription),
every: k.Spec.durationShort(fieldEvery),
level: k.Spec.stringShort(fieldLevel),
@ -728,6 +738,7 @@ func (p *Pkg) graphChecks() *parseErr {
sort.Sort(ch.labels)
p.mChecks[ch.Name()] = ch
p.setRefs(nameRef)
return append(failures, ch.valid()...)
})
if err != nil {
@ -743,8 +754,9 @@ func (p *Pkg) graphChecks() *parseErr {
func (p *Pkg) graphDashboards() *parseErr {
p.mDashboards = make([]*dashboard, 0)
return p.eachResource(KindDashboard, 2, func(k Object) []validationErr {
nameRef := k.Metadata.references(fieldName)
dash := &dashboard{
name: k.Name(),
name: nameRef,
Description: k.Spec.stringShort(fieldDescription),
}
@ -769,6 +781,7 @@ func (p *Pkg) graphDashboards() *parseErr {
}
p.mDashboards = append(p.mDashboards, dash)
p.setRefs(nameRef)
return failures
})
@ -798,16 +811,17 @@ func (p *Pkg) graphNotificationEndpoints() *parseErr {
var pErr parseErr
for _, nk := range notificationKinds {
err := p.eachResource(nk.kind, 1, func(k Object) []validationErr {
if _, ok := p.mNotificationEndpoints[k.Name()]; ok {
nameRef := k.Metadata.references(fieldName)
if _, ok := p.mNotificationEndpoints[nameRef.String()]; ok {
return []validationErr{{
Field: "name",
Field: fieldName,
Msg: "duplicate name: " + k.Name(),
}}
}
endpoint := &notificationEndpoint{
kind: nk.notificationKind,
name: k.Name(),
name: nameRef,
description: k.Spec.stringShort(fieldDescription),
method: strings.TrimSpace(strings.ToUpper(k.Spec.stringShort(fieldNotificationEndpointHTTPMethod))),
httpType: normStr(k.Spec.stringShort(fieldType)),
@ -825,7 +839,7 @@ func (p *Pkg) graphNotificationEndpoints() *parseErr {
})
sort.Sort(endpoint.labels)
p.setRefs(endpoint.password, endpoint.routingKey, endpoint.token, endpoint.username)
p.setRefs(nameRef, endpoint.password, endpoint.routingKey, endpoint.token, endpoint.username)
p.mNotificationEndpoints[endpoint.Name()] = endpoint
return append(failures, endpoint.valid()...)
@ -844,8 +858,8 @@ func (p *Pkg) graphNotificationRules() *parseErr {
p.mNotificationRules = make([]*notificationRule, 0)
return p.eachResource(KindNotificationRule, 1, func(k Object) []validationErr {
rule := &notificationRule{
name: k.Name(),
endpointName: k.Spec.stringShort(fieldNotificationRuleEndpointName),
name: k.Metadata.references(fieldName),
endpointName: k.Spec.references(fieldNotificationRuleEndpointName),
description: k.Spec.stringShort(fieldDescription),
channel: k.Spec.stringShort(fieldNotificationRuleChannel),
every: k.Spec.durationShort(fieldEvery),
@ -877,6 +891,7 @@ func (p *Pkg) graphNotificationRules() *parseErr {
sort.Sort(rule.labels)
p.mNotificationRules = append(p.mNotificationRules, rule)
p.setRefs(rule.name, rule.endpointName)
return append(failures, rule.valid()...)
})
}
@ -885,7 +900,7 @@ func (p *Pkg) graphTasks() *parseErr {
p.mTasks = make([]*task, 0)
return p.eachResource(KindTask, 1, func(k Object) []validationErr {
t := &task{
name: k.Name(),
name: k.Metadata.references(fieldName),
cron: k.Spec.stringShort(fieldTaskCron),
description: k.Spec.stringShort(fieldDescription),
every: k.Spec.durationShort(fieldEvery),
@ -902,6 +917,7 @@ func (p *Pkg) graphTasks() *parseErr {
sort.Sort(t.labels)
p.mTasks = append(p.mTasks, t)
p.setRefs(t.name)
return append(failures, t.valid()...)
})
}
@ -909,8 +925,9 @@ func (p *Pkg) graphTasks() *parseErr {
func (p *Pkg) graphTelegrafs() *parseErr {
p.mTelegrafs = make([]*telegraf, 0)
return p.eachResource(KindTelegraf, 0, func(k Object) []validationErr {
tele := new(telegraf)
tele.config.Name = k.Name()
tele := &telegraf{
name: k.Metadata.references(fieldName),
}
tele.config.Description = k.Spec.stringShort(fieldDescription)
failures := p.parseNestedLabels(k.Spec, func(l *label) error {
@ -929,6 +946,7 @@ func (p *Pkg) graphTelegrafs() *parseErr {
}
p.mTelegrafs = append(p.mTelegrafs, tele)
p.setRefs(tele.name)
return failures
})
@ -937,15 +955,16 @@ func (p *Pkg) graphTelegrafs() *parseErr {
func (p *Pkg) graphVariables() *parseErr {
p.mVariables = make(map[string]*variable)
return p.eachResource(KindVariable, 1, func(k Object) []validationErr {
if _, ok := p.mVariables[k.Name()]; ok {
nameRef := k.Metadata.references(fieldName)
if _, ok := p.mVariables[nameRef.String()]; ok {
return []validationErr{{
Field: "name",
Msg: "duplicate name: " + k.Name(),
Msg: "duplicate name: " + nameRef.String(),
}}
}
newVar := &variable{
name: k.Name(),
name: nameRef,
Description: k.Spec.stringShort(fieldDescription),
Type: normStr(k.Spec.stringShort(fieldType)),
Query: strings.TrimSpace(k.Spec.stringShort(fieldQuery)),
@ -962,6 +981,7 @@ func (p *Pkg) graphVariables() *parseErr {
sort.Sort(newVar.labels)
p.mVariables[k.Name()] = newVar
p.setRefs(newVar.name)
return append(failures, newVar.valid()...)
})

View File

@ -113,14 +113,14 @@ metadata:
require.Len(t, labels, 2)
expectedLabel1 := label{
name: "label_1",
name: &references{val: "label_1"},
Description: "label 1 description",
Color: "#FFFFFF",
}
assert.Equal(t, expectedLabel1, *labels[0])
expectedLabel2 := label{
name: "label_2",
name: &references{val: "label_2"},
Description: "label 2 description",
Color: "#000000",
}
@ -3346,27 +3346,42 @@ spec:
testfileRunner(t, "testdata/env_refs.yml", func(t *testing.T, pkg *Pkg) {
sum := pkg.Summary()
bkts := sum.Buckets
require.Len(t, bkts, 1)
assert.Equal(t, "$bkt-1-name-ref", bkts[0].Name)
require.Len(t, sum.Buckets, 1)
assert.Equal(t, "$bkt-1-name-ref", sum.Buckets[0].Name)
hasEnv(t, pkg.mEnv, "bkt-1-name-ref")
endpoints := sum.NotificationEndpoints
require.Len(t, endpoints, 1)
require.Len(t, sum.Checks, 1)
assert.Equal(t, "$check-1-name-ref", sum.Checks[0].Check.GetName())
hasEnv(t, pkg.mEnv, "check-1-name-ref")
expected := &endpoint.PagerDuty{
Base: endpoint.Base{
Name: "pager_duty_notification_endpoint",
Status: influxdb.TaskStatusActive,
},
ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history",
}
actual, ok := endpoints[0].NotificationEndpoint.(*endpoint.PagerDuty)
require.True(t, ok)
assert.Equal(t, expected.Base.Name, actual.Name)
require.Nil(t, actual.RoutingKey.Value)
require.Len(t, sum.Dashboards, 1)
assert.Equal(t, "$dash-1-name-ref", sum.Dashboards[0].Name)
hasEnv(t, pkg.mEnv, "dash-1-name-ref")
hasEnv(t, pkg.mEnv, "routing-key")
require.Len(t, sum.NotificationEndpoints, 1)
assert.Equal(t, "$endpoint-1-name-ref", sum.NotificationEndpoints[0].NotificationEndpoint.GetName())
hasEnv(t, pkg.mEnv, "endpoint-1-name-ref")
require.Len(t, sum.Labels, 1)
assert.Equal(t, "$label-1-name-ref", sum.Labels[0].Name)
hasEnv(t, pkg.mEnv, "label-1-name-ref")
require.Len(t, sum.NotificationRules, 1)
assert.Equal(t, "$rule-1-name-ref", sum.NotificationRules[0].Name)
assert.Equal(t, "$endpoint-1-name-ref", sum.NotificationRules[0].EndpointName)
hasEnv(t, pkg.mEnv, "rule-1-name-ref")
require.Len(t, sum.Tasks, 1)
assert.Equal(t, "$task-1-name-ref", sum.Tasks[0].Name)
hasEnv(t, pkg.mEnv, "task-1-name-ref")
require.Len(t, sum.TelegrafConfigs, 1)
assert.Equal(t, "$telegraf-1-name-ref", sum.TelegrafConfigs[0].TelegrafConfig.Name)
hasEnv(t, pkg.mEnv, "telegraf-1-name-ref")
require.Len(t, sum.Variables, 1)
assert.Equal(t, "$var-1-name-ref", sum.Variables[0].Name)
hasEnv(t, pkg.mEnv, "var-1-name-ref")
})
})

View File

@ -865,9 +865,9 @@ func (s *Service) dryRunNotificationRules(ctx context.Context, orgID influxdb.ID
diffs := make([]DiffNotificationRule, 0, len(mExisting))
for _, r := range pkg.notificationRules() {
e, ok := mExisting[r.endpointName]
e, ok := mExisting[r.endpointName.String()]
if !ok {
pkgerEndpoint, ok := pkg.mNotificationEndpoints[r.endpointName]
pkgerEndpoint, ok := pkg.mNotificationEndpoints[r.endpointName.String()]
if !ok {
err := fmt.Errorf("failed to find endpoint by name: %q", r.endpointName)
return nil, &influxdb.Error{Code: influxdb.EUnprocessableEntity, Err: err}
@ -1660,7 +1660,7 @@ func (s *Service) applyNotificationRulesGenerator(ctx context.Context, orgID inf
var errs applyErrs
for _, r := range rules {
v, ok := mEndpoints[r.endpointName]
v, ok := mEndpoints[r.endpointName.String()]
if !ok {
errs = append(errs, &applyErrBody{
name: r.Name(),
@ -1851,7 +1851,7 @@ func (s *Service) applyTelegrafs(teles []*telegraf) applier {
var cfg influxdb.TelegrafConfig
mutex.Do(func() {
teles[i].config.OrgID = orgID
cfg = teles[i].config
cfg = teles[i].summarize().TelegrafConfig
})
err := s.teleSVC.CreateTelegrafConfig(ctx, &cfg, userID)

View File

@ -1,18 +1,97 @@
apiVersion: influxdata.com/v2alpha1
kind: NotificationEndpointPagerDuty
metadata:
name: pager_duty_notification_endpoint
spec:
description: pager duty desc
url: http://localhost:8080/orgs/7167eb6719fa34e5/alert-history
routingKey:
envRef:
key: "routing-key"
---
apiVersion: influxdata.com/v2alpha1
kind: Bucket
metadata:
name:
envRef:
key: "bkt-1-name-ref"
key: bkt-1-name-ref
spec:
---
apiVersion: influxdata.com/v2alpha1
kind: Label
metadata:
name:
envRef:
key: label-1-name-ref
spec:
---
apiVersion: influxdata.com/v2alpha1
kind: CheckDeadman
metadata:
name:
envRef:
key: check-1-name-ref
spec:
every: 5m
level: cRiT
query: >
from(bucket: "rucket_1") |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
statusMessageTemplate: "Check: ${ r._check_name } is: ${ r._level }"
---
apiVersion: influxdata.com/v2alpha1
kind: Dashboard
metadata:
name:
envRef:
key: dash-1-name-ref
spec:
---
apiVersion: influxdata.com/v2alpha1
kind: NotificationEndpointSlack
metadata:
name:
envRef:
key: endpoint-1-name-ref
spec:
url: https://hooks.slack.com/services/bip/piddy/boppidy
---
apiVersion: influxdata.com/v2alpha1
kind: NotificationRule
metadata:
name:
envRef:
key: rule-1-name-ref
spec:
endpointName:
envRef:
key: endpoint-1-name-ref
every: 10m
messageTemplate: "Notification Rule: ${ r._notification_rule_name } triggered by check: ${ r._check_name }: ${ r._message }"
statusRules:
- currentLevel: WARN
---
apiVersion: influxdata.com/v2alpha1
kind: Telegraf
metadata:
name:
envRef:
key: telegraf-1-name-ref
spec:
config: |
[agent]
interval = "10s"
[[outputs.influxdb_v2]]
urls = ["http://localhost:9999"]
token = "$INFLUX_TOKEN"
organization = "rg"
bucket = "rucket_3"
---
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name:
envRef:
key: task-1-name-ref
spec:
cron: 15 * * * *
query: >
from(bucket: "rucket_1")
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name:
envRef:
key: var-1-name-ref
spec:
type: constant
values: [first val]