feat(pkger): extend template Summary with discrete kinds for each summary type

references: #18804
pull/18818/head
Johnny Steenbergen 2020-06-30 15:43:01 -07:00 committed by Johnny Steenbergen
parent b9e6744807
commit ffe5d941d3
6 changed files with 194 additions and 78 deletions

View File

@ -2629,12 +2629,14 @@ spec:
labels := sum1.Labels
require.Len(t, labels, 2)
assert.Equal(t, pkger.KindLabel, labels[0].Kind)
assert.NotZero(t, labels[0].ID)
assert.Equal(t, "label-1", labels[0].Name)
assert.Equal(t, "the 2nd label", labels[1].Name)
bkts := sum1.Buckets
require.Len(t, bkts, 1)
assert.Equal(t, pkger.KindBucket, bkts[0].Kind)
assert.NotZero(t, bkts[0].ID)
assert.NotEmpty(t, bkts[0].MetaName)
assert.Equal(t, "rucketeer", bkts[0].Name)
@ -2643,8 +2645,10 @@ spec:
checks := sum1.Checks
require.Len(t, checks, 2)
assert.Equal(t, "check 0 name", checks[0].Check.GetName())
assert.Equal(t, pkger.KindCheckThreshold, checks[0].Kind)
hasLabelAssociations(t, checks[0].LabelAssociations, 1, "label-1")
assert.Equal(t, "check-1", checks[1].Check.GetName())
assert.Equal(t, pkger.KindCheckDeadman, checks[1].Kind)
hasLabelAssociations(t, checks[1].LabelAssociations, 1, "label-1")
for _, ch := range checks {
assert.NotZero(t, ch.Check.GetID())
@ -2652,6 +2656,7 @@ spec:
dashs := sum1.Dashboards
require.Len(t, dashs, 1)
assert.Equal(t, pkger.KindDashboard, dashs[0].Kind)
assert.NotZero(t, dashs[0].ID)
assert.NotEmpty(t, dashs[0].Name)
assert.Equal(t, "dash_1", dashs[0].Name)
@ -2662,6 +2667,7 @@ spec:
endpoints := sum1.NotificationEndpoints
require.Len(t, endpoints, 1)
assert.Equal(t, pkger.KindNotificationEndpointHTTP, endpoints[0].Kind)
assert.NotZero(t, endpoints[0].NotificationEndpoint.GetID())
assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName())
assert.Equal(t, "http none auth desc", endpoints[0].NotificationEndpoint.GetDescription())
@ -2670,6 +2676,7 @@ spec:
require.Len(t, sum1.NotificationRules, 1)
rule := sum1.NotificationRules[0]
assert.Equal(t, pkger.KindNotificationRule, rule.Kind)
assert.NotZero(t, rule.ID)
assert.Equal(t, "rule_0", rule.Name)
assert.Equal(t, pkger.SafeID(endpoints[0].NotificationEndpoint.GetID()), rule.EndpointID)
@ -2678,12 +2685,14 @@ spec:
require.Len(t, sum1.Tasks, 1)
task := sum1.Tasks[0]
assert.Equal(t, pkger.KindTask, task.Kind)
assert.NotZero(t, task.ID)
assert.Equal(t, "task_1", task.Name)
assert.Equal(t, "desc_1", task.Description)
teles := sum1.TelegrafConfigs
require.Len(t, teles, 1)
assert.Equal(t, pkger.KindTelegraf, teles[0].Kind)
assert.NotZero(t, teles[0].TelegrafConfig.ID)
assert.Equal(t, l.Org.ID, teles[0].TelegrafConfig.OrgID)
assert.Equal(t, "first tele config", teles[0].TelegrafConfig.Name)
@ -2692,6 +2701,7 @@ spec:
vars := sum1.Variables
require.Len(t, vars, 1)
assert.Equal(t, pkger.KindVariable, vars[0].Kind)
assert.NotZero(t, vars[0].ID)
assert.Equal(t, "query var", vars[0].Name)
assert.Equal(t, []string{"rucketeer"}, vars[0].Selected)

View File

@ -7801,6 +7801,8 @@ components:
type: string
orgID:
type: string
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
name:
@ -7822,6 +7824,8 @@ components:
- $ref: "#/components/schemas/CheckDiscriminator"
- type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
labelAssociations:
@ -7830,10 +7834,6 @@ components:
$ref: "#/components/schemas/TemplateSummaryLabel"
envReferences:
$ref: "#/components/schemas/TemplateEnvReferences"
labels:
type: array
items:
$ref: "#/components/schemas/TemplateSummaryLabel"
dashboards:
type: array
items:
@ -7843,6 +7843,8 @@ components:
type: "string"
orgID:
type: "string"
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
name:
@ -7859,6 +7861,10 @@ components:
$ref: "#/components/schemas/TemplateChart"
envReferences:
$ref: "#/components/schemas/TemplateEnvReferences"
labels:
type: array
items:
$ref: "#/components/schemas/TemplateSummaryLabel"
labelMappings:
type: array
items:
@ -7895,6 +7901,8 @@ components:
- $ref: "#/components/schemas/NotificationEndpointDiscrimator"
- type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
labelAssociations:
@ -7908,6 +7916,8 @@ components:
items:
type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
name:
@ -7959,6 +7969,8 @@ components:
items:
type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
id:
@ -7986,6 +7998,8 @@ components:
- $ref: "#/components/schemas/TelegrafRequest"
- type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
labelAssociations:
@ -7999,6 +8013,8 @@ components:
items:
type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
id:
@ -8368,6 +8384,8 @@ components:
type: string
orgID:
type: string
kind:
$ref: "#/components/schemas/TemplateKind"
templateMetaName:
type: string
name:

View File

@ -447,33 +447,39 @@ type Summary struct {
Variables []SummaryVariable `json:"variables"`
}
// SummaryIdentifier establishes the shared identifiers for a given resource
// within a template.
type SummaryIdentifier struct {
Kind Kind `json:"kind"`
MetaName string `json:"templateMetaName"`
EnvReferences []SummaryReference `json:"envReferences"`
}
// SummaryBucket provides a summary of a pkg bucket.
type SummaryBucket struct {
SummaryIdentifier
ID SafeID `json:"id,omitempty"`
OrgID SafeID `json:"orgID,omitempty"`
Name string `json:"name"`
MetaName string `json:"templateMetaName"`
Description string `json:"description"`
// TODO: return retention rules?
RetentionPeriod time.Duration `json:"retentionPeriod"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
// SummaryCheck provides a summary of a pkg check.
type SummaryCheck struct {
MetaName string `json:"templateMetaName"`
Check influxdb.Check `json:"check"`
Status influxdb.Status `json:"status"`
SummaryIdentifier
Check influxdb.Check `json:"check"`
Status influxdb.Status `json:"status"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
func (s *SummaryCheck) UnmarshalJSON(b []byte) error {
var out struct {
MetaName string `json:"templateMetaName"`
SummaryIdentifier
Status string `json:"status"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
Check json.RawMessage `json:"check"`
@ -481,7 +487,7 @@ func (s *SummaryCheck) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &out); err != nil {
return err
}
s.MetaName = out.MetaName
s.SummaryIdentifier = out.SummaryIdentifier
s.Status = influxdb.Status(out.Status)
s.LabelAssociations = out.LabelAssociations
@ -492,15 +498,14 @@ func (s *SummaryCheck) UnmarshalJSON(b []byte) error {
// SummaryDashboard provides a summary of a pkg dashboard.
type SummaryDashboard struct {
SummaryIdentifier
ID SafeID `json:"id"`
OrgID SafeID `json:"orgID"`
MetaName string `json:"templateMetaName"`
Name string `json:"name"`
Description string `json:"description"`
Charts []SummaryChart `json:"charts"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
// SummaryChart provides a summary of a pkg dashboard's chart.
@ -554,25 +559,24 @@ func (s *SummaryChart) UnmarshalJSON(b []byte) error {
// SummaryNotificationEndpoint provides a summary of a pkg notification endpoint.
type SummaryNotificationEndpoint struct {
MetaName string `json:"templateMetaName"`
SummaryIdentifier
NotificationEndpoint influxdb.NotificationEndpoint `json:"notificationEndpoint"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
// UnmarshalJSON unmarshals the notificatio endpoint. This is necessary b/c of
// the notification endpoint does not have a means ot unmarshal itself.
func (s *SummaryNotificationEndpoint) UnmarshalJSON(b []byte) error {
var a struct {
PkgName string `json:"templateMetaName"`
SummaryIdentifier
NotificationEndpoint json.RawMessage `json:"notificationEndpoint"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
if err := json.Unmarshal(b, &a); err != nil {
return err
}
s.MetaName = a.PkgName
s.SummaryIdentifier = a.SummaryIdentifier
s.LabelAssociations = a.LabelAssociations
e, err := endpoint.UnmarshalJSON(a.NotificationEndpoint)
@ -583,8 +587,8 @@ func (s *SummaryNotificationEndpoint) UnmarshalJSON(b []byte) error {
// Summary types for NotificationRules which provide a summary of a pkg notification rule.
type (
SummaryNotificationRule struct {
SummaryIdentifier
ID SafeID `json:"id"`
MetaName string `json:"templateMetaName"`
Name string `json:"name"`
Description string `json:"description"`
@ -600,8 +604,7 @@ type (
StatusRules []SummaryStatusRule `json:"statusRules"`
TagRules []SummaryTagRule `json:"tagRules"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
SummaryStatusRule struct {
@ -618,16 +621,14 @@ type (
// SummaryLabel provides a summary of a pkg label.
type SummaryLabel struct {
SummaryIdentifier
ID SafeID `json:"id"`
OrgID SafeID `json:"orgID"`
MetaName string `json:"templateMetaName"`
Name string `json:"name"`
Properties struct {
Color string `json:"color"`
Description string `json:"description"`
} `json:"properties"`
EnvReferences []SummaryReference `json:"envReferences"`
}
// SummaryLabelMapping provides a summary of a label mapped with a single resource.
@ -654,8 +655,8 @@ type SummaryReference struct {
// SummaryTask provides a summary of a task.
type SummaryTask struct {
SummaryIdentifier
ID SafeID `json:"id"`
MetaName string `json:"templateMetaName"`
Name string `json:"name"`
Cron string `json:"cron"`
Description string `json:"description"`
@ -664,29 +665,26 @@ type SummaryTask struct {
Query string `json:"query"`
Status influxdb.Status `json:"status"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
// SummaryTelegraf provides a summary of a pkg telegraf config.
type SummaryTelegraf struct {
MetaName string `json:"templateMetaName"`
SummaryIdentifier
TelegrafConfig influxdb.TelegrafConfig `json:"telegrafConfig"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}
// SummaryVariable provides a summary of a pkg variable.
type SummaryVariable struct {
SummaryIdentifier
ID SafeID `json:"id,omitempty"`
MetaName string `json:"templateMetaName"`
OrgID SafeID `json:"orgID,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Selected []string `json:"variables"`
Arguments *influxdb.VariableArguments `json:"arguments"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

View File

@ -89,12 +89,15 @@ type bucket struct {
func (b *bucket) summarize() SummaryBucket {
return SummaryBucket{
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: b.MetaName(),
EnvReferences: summarizeCommonReferences(b.identity, b.labels),
},
Name: b.Name(),
MetaName: b.MetaName(),
Description: b.Description,
RetentionPeriod: b.RetentionRules.RP(),
LabelAssociations: toSummaryLabels(b.labels...),
EnvReferences: summarizeCommonReferences(b.identity, b.labels),
}
}
@ -248,18 +251,22 @@ func (c *check) summarize() SummaryCheck {
}
sum := SummaryCheck{
MetaName: c.MetaName(),
SummaryIdentifier: SummaryIdentifier{
MetaName: c.MetaName(),
EnvReferences: summarizeCommonReferences(c.identity, c.labels),
},
Status: c.Status(),
LabelAssociations: toSummaryLabels(c.labels...),
EnvReferences: summarizeCommonReferences(c.identity, c.labels),
}
switch c.kind {
case checkKindThreshold:
sum.Kind = KindCheckThreshold
sum.Check = &icheck.Threshold{
Base: base,
Thresholds: toInfluxThresholds(c.thresholds...),
}
case checkKindDeadman:
sum.Kind = KindCheckDeadman
sum.Check = &icheck.Deadman{
Base: base,
Level: notification.ParseCheckLevel(strings.ToUpper(c.level)),
@ -463,11 +470,14 @@ func (d *dashboard) ResourceType() influxdb.ResourceType {
func (d *dashboard) summarize() SummaryDashboard {
iDash := SummaryDashboard{
MetaName: d.MetaName(),
SummaryIdentifier: SummaryIdentifier{
Kind: KindDashboard,
MetaName: d.MetaName(),
EnvReferences: summarizeCommonReferences(d.identity, d.labels),
},
Name: d.Name(),
Description: d.Description,
LabelAssociations: toSummaryLabels(d.labels...),
EnvReferences: summarizeCommonReferences(d.identity, d.labels),
}
for _, c := range d.Charts {
iDash.Charts = append(iDash.Charts, SummaryChart{
@ -1131,8 +1141,12 @@ type label struct {
func (l *label) summarize() SummaryLabel {
return SummaryLabel{
MetaName: l.MetaName(),
Name: l.Name(),
SummaryIdentifier: SummaryIdentifier{
Kind: KindLabel,
MetaName: l.MetaName(),
EnvReferences: l.identity.summarizeReferences(),
},
Name: l.Name(),
Properties: struct {
Color string `json:"color"`
Description string `json:"description"`
@ -1140,7 +1154,6 @@ func (l *label) summarize() SummaryLabel {
Color: l.Color,
Description: l.Description,
},
EnvReferences: l.identity.summarizeReferences(),
}
}
@ -1284,13 +1297,16 @@ func (n *notificationEndpoint) base() endpoint.Base {
func (n *notificationEndpoint) summarize() SummaryNotificationEndpoint {
base := n.base()
sum := SummaryNotificationEndpoint{
MetaName: n.MetaName(),
SummaryIdentifier: SummaryIdentifier{
MetaName: n.MetaName(),
EnvReferences: summarizeCommonReferences(n.identity, n.labels),
},
LabelAssociations: toSummaryLabels(n.labels...),
EnvReferences: summarizeCommonReferences(n.identity, n.labels),
}
switch n.kind {
case notificationKindHTTP:
sum.Kind = KindNotificationEndpointHTTP
e := &endpoint.HTTP{
Base: base,
URL: n.url,
@ -1309,12 +1325,14 @@ func (n *notificationEndpoint) summarize() SummaryNotificationEndpoint {
}
sum.NotificationEndpoint = e
case notificationKindPagerDuty:
sum.Kind = KindNotificationEndpointPagerDuty
sum.NotificationEndpoint = &endpoint.PagerDuty{
Base: base,
ClientURL: n.url,
RoutingKey: n.routingKey.SecretField(),
}
case notificationKindSlack:
sum.Kind = KindNotificationEndpointSlack
sum.NotificationEndpoint = &endpoint.Slack{
Base: base,
URL: n.url,
@ -1487,14 +1505,17 @@ func (r *notificationRule) summarize() SummaryNotificationRule {
}
return SummaryNotificationRule{
MetaName: r.MetaName(),
SummaryIdentifier: SummaryIdentifier{
Kind: KindNotificationRule,
MetaName: r.MetaName(),
EnvReferences: envRefs,
},
Name: r.Name(),
EndpointMetaName: endpointPkgName,
EndpointType: endpointType,
Description: r.description,
Every: r.every.String(),
LabelAssociations: toSummaryLabels(r.labels...),
EnvReferences: envRefs,
Offset: r.offset.String(),
MessageTemplate: r.msgTemplate,
Status: r.Status(),
@ -1721,7 +1742,11 @@ func (t *task) flux() string {
func (t *task) summarize() SummaryTask {
return SummaryTask{
MetaName: t.MetaName(),
SummaryIdentifier: SummaryIdentifier{
Kind: KindTask,
MetaName: t.MetaName(),
EnvReferences: summarizeCommonReferences(t.identity, t.labels),
},
Name: t.Name(),
Cron: t.cron,
Description: t.description,
@ -1730,7 +1755,6 @@ func (t *task) summarize() SummaryTask {
Query: t.query,
Status: t.Status(),
EnvReferences: summarizeCommonReferences(t.identity, t.labels),
LabelAssociations: toSummaryLabels(t.labels...),
}
}
@ -1856,10 +1880,13 @@ func (t *telegraf) summarize() SummaryTelegraf {
cfg := t.config
cfg.Name = t.Name()
return SummaryTelegraf{
MetaName: t.MetaName(),
SummaryIdentifier: SummaryIdentifier{
Kind: KindTelegraf,
MetaName: t.MetaName(),
EnvReferences: summarizeCommonReferences(t.identity, t.labels),
},
TelegrafConfig: cfg,
LabelAssociations: toSummaryLabels(t.labels...),
EnvReferences: summarizeCommonReferences(t.identity, t.labels),
}
}
@ -1935,13 +1962,16 @@ func (v *variable) summarize() SummaryVariable {
}
return SummaryVariable{
MetaName: v.MetaName(),
SummaryIdentifier: SummaryIdentifier{
Kind: KindVariable,
MetaName: v.MetaName(),
EnvReferences: envRefs,
},
Name: v.Name(),
Description: v.Description,
Selected: v.Selected(),
Arguments: v.influxVarArgs(),
LabelAssociations: toSummaryLabels(v.labels...),
EnvReferences: envRefs,
}
}

View File

@ -30,22 +30,28 @@ func TestParse(t *testing.T) {
actual := buckets[0]
expectedBucket := SummaryBucket{
MetaName: "rucket-11",
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-11",
EnvReferences: []SummaryReference{},
},
Name: "rucket-11",
Description: "bucket 1 description",
RetentionPeriod: time.Hour,
LabelAssociations: []SummaryLabel{},
EnvReferences: []SummaryReference{},
}
assert.Equal(t, expectedBucket, actual)
actual = buckets[1]
expectedBucket = SummaryBucket{
MetaName: "rucket-22",
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-22",
EnvReferences: []SummaryReference{},
},
Name: "display name",
Description: "bucket 2 description",
LabelAssociations: []SummaryLabel{},
EnvReferences: []SummaryReference{},
}
assert.Equal(t, expectedBucket, actual)
})
@ -483,6 +489,7 @@ spec:
require.Len(t, sum.Checks, 2)
check1 := sum.Checks[0]
assert.Equal(t, KindCheckThreshold, check1.Kind)
thresholdCheck, ok := check1.Check.(*icheck.Threshold)
require.Truef(t, ok, "got: %#v", check1)
@ -529,6 +536,7 @@ spec:
assert.Len(t, check1.LabelAssociations, 1)
check2 := sum.Checks[1]
assert.Equal(t, KindCheckDeadman, check2.Kind)
deadmanCheck, ok := check2.Check.(*icheck.Deadman)
require.Truef(t, ok, "got: %#v", check2)
@ -951,6 +959,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-1", actual.Name)
assert.Equal(t, "desc1", actual.Description)
@ -1035,6 +1044,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-0", actual.Name)
assert.Equal(t, "a dashboard w/ heatmap chart", actual.Description)
@ -1153,6 +1163,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-0", actual.Name)
assert.Equal(t, "a dashboard w/ single histogram chart", actual.Description)
@ -1227,6 +1238,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-0", actual.Name)
assert.Equal(t, "a dashboard w/ single markdown chart", actual.Description)
@ -1248,6 +1260,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-0", actual.Name)
assert.Equal(t, "a dashboard w/ single scatter chart", actual.Description)
@ -1525,6 +1538,7 @@ spec:
require.Len(t, sum.Dashboards, 2)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-1", actual.MetaName)
assert.Equal(t, "display name", actual.Name)
assert.Equal(t, "desc1", actual.Description)
@ -1692,6 +1706,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-1", actual.Name)
assert.Equal(t, "desc1", actual.Description)
@ -1970,6 +1985,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-1", actual.Name)
assert.Equal(t, "desc1", actual.Description)
@ -2147,6 +2163,7 @@ spec:
require.Len(t, sum.Dashboards, 1)
actual := sum.Dashboards[0]
assert.Equal(t, KindDashboard, actual.Kind)
assert.Equal(t, "dash-1", actual.Name)
assert.Equal(t, "desc1", actual.Description)
@ -2432,7 +2449,10 @@ spec:
testfileRunner(t, "testdata/notification_endpoint", func(t *testing.T, template *Template) {
expectedEndpoints := []SummaryNotificationEndpoint{
{
MetaName: "http-basic-auth-notification-endpoint",
SummaryIdentifier: SummaryIdentifier{
Kind: KindNotificationEndpointHTTP,
MetaName: "http-basic-auth-notification-endpoint",
},
NotificationEndpoint: &endpoint.HTTP{
Base: endpoint.Base{
Name: "basic endpoint name",
@ -2447,7 +2467,10 @@ spec:
},
},
{
MetaName: "http-bearer-auth-notification-endpoint",
SummaryIdentifier: SummaryIdentifier{
Kind: KindNotificationEndpointHTTP,
MetaName: "http-bearer-auth-notification-endpoint",
},
NotificationEndpoint: &endpoint.HTTP{
Base: endpoint.Base{
Name: "http-bearer-auth-notification-endpoint",
@ -2461,7 +2484,10 @@ spec:
},
},
{
MetaName: "http-none-auth-notification-endpoint",
SummaryIdentifier: SummaryIdentifier{
Kind: KindNotificationEndpointHTTP,
MetaName: "http-none-auth-notification-endpoint",
},
NotificationEndpoint: &endpoint.HTTP{
Base: endpoint.Base{
Name: "http-none-auth-notification-endpoint",
@ -2474,7 +2500,10 @@ spec:
},
},
{
MetaName: "pager-duty-notification-endpoint",
SummaryIdentifier: SummaryIdentifier{
Kind: KindNotificationEndpointPagerDuty,
MetaName: "pager-duty-notification-endpoint",
},
NotificationEndpoint: &endpoint.PagerDuty{
Base: endpoint.Base{
Name: "pager duty name",
@ -2486,7 +2515,10 @@ spec:
},
},
{
MetaName: "slack-notification-endpoint",
SummaryIdentifier: SummaryIdentifier{
Kind: KindNotificationEndpointHTTP,
MetaName: "slack-notification-endpoint",
},
NotificationEndpoint: &endpoint.Slack{
Base: endpoint.Base{
Name: "slack name",
@ -2818,6 +2850,7 @@ spec:
require.Len(t, rules, 1)
rule := rules[0]
assert.Equal(t, KindNotificationRule, rule.Kind)
assert.Equal(t, "rule_0", rule.Name)
assert.Equal(t, "endpoint-0", rule.EndpointMetaName)
assert.Equal(t, "desc_0", rule.Description)
@ -3152,6 +3185,11 @@ spec:
sum := template.Summary()
tasks := sum.Tasks
require.Len(t, tasks, 2)
for _, ta := range tasks {
assert.Equal(t, KindTask, ta.Kind)
}
sort.Slice(tasks, func(i, j int) bool {
return tasks[i].MetaName < tasks[j].MetaName
})
@ -3374,6 +3412,7 @@ spec:
require.Len(t, sum.TelegrafConfigs, 2)
actual := sum.TelegrafConfigs[0]
assert.Equal(t, KindTelegraf, actual.Kind)
assert.Equal(t, "display name", actual.TelegrafConfig.Name)
assert.Equal(t, "desc", actual.TelegrafConfig.Description)
@ -3473,6 +3512,9 @@ spec:
sum := template.Summary()
require.Len(t, sum.Variables, 4)
for _, v := range sum.Variables {
assert.Equal(t, KindVariable, v.Kind)
}
varEquals := func(t *testing.T, name, vType string, vals interface{}, selected []string, v SummaryVariable) {
t.Helper()
@ -3869,28 +3911,37 @@ spec:
bkts := []SummaryBucket{
{
MetaName: "rucket-1",
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-1",
EnvReferences: []SummaryReference{},
},
Name: "rucket-1",
Description: "desc_1",
RetentionPeriod: 10000 * time.Second,
LabelAssociations: labels,
EnvReferences: []SummaryReference{},
},
{
MetaName: "rucket-2",
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-2",
EnvReferences: []SummaryReference{},
},
Name: "rucket-2",
Description: "desc-2",
RetentionPeriod: 20000 * time.Second,
LabelAssociations: labels,
EnvReferences: []SummaryReference{},
},
{
MetaName: "rucket-3",
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-3",
EnvReferences: []SummaryReference{},
},
Name: "rucket-3",
Description: "desc_3",
RetentionPeriod: 30000 * time.Second,
LabelAssociations: labels,
EnvReferences: []SummaryReference{},
},
}
assert.Equal(t, bkts, sum.Buckets)
@ -4424,8 +4475,12 @@ func sumLabelGen(metaName, name, color, desc string, envRefs ...SummaryReference
envRefs = make([]SummaryReference, 0)
}
return SummaryLabel{
MetaName: metaName,
Name: name,
SummaryIdentifier: SummaryIdentifier{
Kind: KindLabel,
MetaName: metaName,
EnvReferences: envRefs,
},
Name: name,
Properties: struct {
Color string `json:"color"`
Description string `json:"description"`
@ -4433,7 +4488,6 @@ func sumLabelGen(metaName, name, color, desc string, envRefs ...SummaryReference
Color: color,
Description: desc,
},
EnvReferences: envRefs,
}
}

View File

@ -785,14 +785,17 @@ func TestService(t *testing.T) {
require.Len(t, sum.Buckets, 2)
expected := SummaryBucket{
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-11",
EnvReferences: []SummaryReference{},
},
ID: SafeID(time.Hour),
OrgID: SafeID(orgID),
MetaName: "rucket-11",
Name: "rucket-11",
Description: "bucket 1 description",
RetentionPeriod: time.Hour,
LabelAssociations: []SummaryLabel{},
EnvReferences: []SummaryReference{},
}
assert.Contains(t, sum.Buckets, expected)
})
@ -837,14 +840,17 @@ func TestService(t *testing.T) {
require.Len(t, sum.Buckets, 2)
expected := SummaryBucket{
SummaryIdentifier: SummaryIdentifier{
Kind: KindBucket,
MetaName: "rucket-11",
EnvReferences: []SummaryReference{},
},
ID: SafeID(3),
OrgID: SafeID(orgID),
MetaName: "rucket-11",
Name: "rucket-11",
Description: "bucket 1 description",
RetentionPeriod: time.Hour,
LabelAssociations: []SummaryLabel{},
EnvReferences: []SummaryReference{},
}
assert.Contains(t, sum.Buckets, expected)
assert.Zero(t, fakeBktSVC.CreateBucketCalls.Count())