From cee77081b2abef340be05d1871488014c6777bfd Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Wed, 8 Apr 2020 13:54:00 -0700 Subject: [PATCH] feat(pkger): extend tasks with unique constraints --- cmd/influx/pkg.go | 33 +++++--- http/swagger.yml | 207 +++++++++++++++++++++++++++++++++++----------- pkger/models.go | 20 ++++- 3 files changed, 197 insertions(+), 63 deletions(-) diff --git a/cmd/influx/pkg.go b/cmd/influx/pkg.go index c807da8095..23afa2474f 100644 --- a/cmd/influx/pkg.go +++ b/cmd/influx/pkg.go @@ -885,17 +885,29 @@ func (b *cmdPkgBuilder) printPkgDiff(diff pkger.Diff) error { printer.Render() } - tablePrintFn := b.tablePrinterGen() if teles := diff.Telegrafs; len(teles) > 0 { - headers := []string{"New", "Name", "Description"} - tablePrintFn("TELEGRAF CONFIGS", headers, len(teles), func(i int) []string { - t := teles[i] - return []string{ - boolDiff(true), - t.Name, - green(t.Description), + printer := diffPrinterGen("Telegraf Configurations", []string{"Description"}) + appendValues := func(id pkger.SafeID, pkgName string, v influxdb.TelegrafConfig) []string { + return []string{pkgName, id.String(), v.Name, v.Description} + } + + for _, e := range teles { + var oldRow []string + if e.Old != nil { + oldRow = appendValues(e.ID, e.PkgName, *e.Old) } - }) + + newRow := appendValues(e.ID, e.PkgName, e.New) + switch { + case e.IsNew(): + printer.AppendDiff(nil, newRow) + case e.Remove: + printer.AppendDiff(oldRow, nil) + default: + printer.AppendDiff(oldRow, newRow) + } + } + printer.Render() } if tasks := diff.Tasks; len(tasks) > 0 { @@ -905,7 +917,7 @@ func (b *cmdPkgBuilder) printPkgDiff(diff pkger.Diff) error { if v.Cron == "" { timing = fmt.Sprintf("every: %s offset: %s", v.Every, v.Offset) } - return []string{pkgName, id.String(), v.Description, timing} + return []string{pkgName, id.String(), v.Name, v.Description, timing} } for _, e := range tasks { @@ -957,6 +969,7 @@ func (b *cmdPkgBuilder) printPkgDiff(diff pkger.Diff) error { printer.Render() } + tablePrintFn := b.tablePrinterGen() if len(diff.LabelMappings) > 0 { headers := []string{"New", "Resource Type", "Resource Name", "Resource ID", "Label Name", "Label ID"} tablePrintFn("LABEL MAPPINGS", headers, len(diff.LabelMappings), func(i int) []string { diff --git a/http/swagger.yml b/http/swagger.yml index 7ca7534f62..2e1230ebc1 100644 --- a/http/swagger.yml +++ b/http/swagger.yml @@ -7560,14 +7560,34 @@ components: items: type: object properties: - name: + remove: + type: boolean + id: type: string - description: + pkgName: type: string - charts: - type: array - items: - $ref: "#/components/schemas/PkgChart" + new: + type: object + properties: + name: + type: string + description: + type: string + charts: + type: array + items: + $ref: "#/components/schemas/PkgChart" + old: + type: object + properties: + name: + type: string + description: + type: string + charts: + type: array + items: + $ref: "#/components/schemas/PkgChart" labels: type: array items: @@ -7634,67 +7654,154 @@ components: items: type: object properties: - name: - type: string - description: - type: string - endpointName: - type: string - endpointID: - type: string - endpointType: - type: string - every: - type: string - offset: - type: string - messageTemplate: - type: string - status: - type: string - statusRules: - type: array - items: + remove: + type: boolean + id: + type: string + pkgName: + type: string + new: type: object properties: - currentLevel: - type: string - previousLevel: - type: string - tagRules: - type: array - items: + name: + type: string + description: + type: string + endpointName: + type: string + endpointID: + type: string + endpointType: + type: string + every: + type: string + offset: + type: string + messageTemplate: + type: string + status: + type: string + statusRules: + type: array + items: + type: object + properties: + currentLevel: + type: string + previousLevel: + type: string + tagRules: + type: array + items: + type: object + properties: + key: + type: string + value: + type: string + operator: + type: string + old: type: object properties: - key: + name: type: string - value: + description: type: string - operator: + endpointName: type: string + endpointID: + type: string + endpointType: + type: string + every: + type: string + offset: + type: string + messageTemplate: + type: string + status: + type: string + statusRules: + type: array + items: + type: object + properties: + currentLevel: + type: string + previousLevel: + type: string + tagRules: + type: array + items: + type: object + properties: + key: + type: string + value: + type: string + operator: + type: string tasks: type: array items: type: object properties: - name: + remove: + type: boolean + id: type: string - cron: - type: string - description: - type: string - every: - type: string - offset: - type: string - query: - type: string - status: + pkgName: type: string + new: + type: object + properties: + name: + type: string + cron: + type: string + description: + type: string + every: + type: string + offset: + type: string + query: + type: string + status: + type: string + old: + type: object + properties: + name: + type: string + cron: + type: string + description: + type: string + every: + type: string + offset: + type: string + query: + type: string + status: + type: string telegrafConfigs: type: array items: - $ref: "#/components/schemas/TelegrafRequest" + type: object + properties: + remove: + type: boolean + id: + type: string + pkgName: + type: string + new: + $ref: "#/components/schemas/TelegrafRequest" + old: + $ref: "#/components/schemas/TelegrafRequest" variables: type: array items: diff --git a/pkger/models.go b/pkger/models.go index 871cd0ac2c..5c03e55c82 100644 --- a/pkger/models.go +++ b/pkger/models.go @@ -623,12 +623,21 @@ func newDiffTask(t *task) DiffTask { // DiffTelegraf is a diff of an individual telegraf. This resource is always new. type DiffTelegraf struct { - influxdb.TelegrafConfig + DiffIdentifier + + New influxdb.TelegrafConfig + Old *influxdb.TelegrafConfig } func newDiffTelegraf(t *telegraf) DiffTelegraf { return DiffTelegraf{ - TelegrafConfig: t.config, + DiffIdentifier: DiffIdentifier{ + ID: SafeID(t.ID()), + Remove: t.shouldRemove, + PkgName: t.PkgName(), + }, + New: t.config, + Old: t.existing, } } @@ -2194,9 +2203,14 @@ type telegraf struct { config influxdb.TelegrafConfig labels sortedLabels + + existing *influxdb.TelegrafConfig } func (t *telegraf) ID() influxdb.ID { + if t.existing != nil { + return t.existing.ID + } return t.config.ID } @@ -2209,7 +2223,7 @@ func (t *telegraf) ResourceType() influxdb.ResourceType { } func (t *telegraf) Exists() bool { - return false + return t.existing != nil } func (t *telegraf) summarize() SummaryTelegraf {