feat(pkger): update dashboards with unique constraints
parent
dd432360cc
commit
845718c0d6
|
@ -48,7 +48,7 @@ func exec(dbPath, out string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg.Objects = append(pkg.Objects, pkger.DashboardToObject(d2, d2.Name))
|
pkg.Objects = append(pkg.Objects, pkger.DashboardToObject(d2.Name, d2))
|
||||||
|
|
||||||
for _, v := range vs {
|
for _, v := range vs {
|
||||||
name := strings.ToLower(v.Name)
|
name := strings.ToLower(v.Name)
|
||||||
|
|
|
@ -791,18 +791,30 @@ func (b *cmdPkgBuilder) printPkgDiff(diff pkger.Diff) error {
|
||||||
printer.Render()
|
printer.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
tablePrintFn := b.tablePrinterGen()
|
|
||||||
if dashes := diff.Dashboards; len(dashes) > 0 {
|
if dashes := diff.Dashboards; len(dashes) > 0 {
|
||||||
headers := []string{"New", "Name", "Description", "Num Charts"}
|
printer := diffPrinterGen("Dashboards", []string{"Description", "Num Charts"})
|
||||||
tablePrintFn("DASHBOARDS", headers, len(dashes), func(i int) []string {
|
|
||||||
d := dashes[i]
|
appendValues := func(id pkger.SafeID, pkgName string, v pkger.DiffDashboardValues) []string {
|
||||||
return []string{
|
return []string{pkgName, id.String(), v.Name, v.Desc, strconv.Itoa(len(v.Charts))}
|
||||||
boolDiff(true),
|
}
|
||||||
d.Name,
|
|
||||||
green(d.Desc),
|
for _, d := range dashes {
|
||||||
green(strconv.Itoa(len(d.Charts))),
|
var oldRow []string
|
||||||
|
if d.Old != nil {
|
||||||
|
oldRow = appendValues(d.ID, d.PkgName, *d.Old)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
newRow := appendValues(d.ID, d.PkgName, d.New)
|
||||||
|
switch {
|
||||||
|
case d.IsNew():
|
||||||
|
printer.AppendDiff(nil, newRow)
|
||||||
|
case d.Remove:
|
||||||
|
printer.AppendDiff(oldRow, nil)
|
||||||
|
default:
|
||||||
|
printer.AppendDiff(oldRow, newRow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printer.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
if endpoints := diff.NotificationEndpoints; len(endpoints) > 0 {
|
if endpoints := diff.NotificationEndpoints; len(endpoints) > 0 {
|
||||||
|
@ -873,6 +885,7 @@ func (b *cmdPkgBuilder) printPkgDiff(diff pkger.Diff) error {
|
||||||
printer.Render()
|
printer.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tablePrintFn := b.tablePrinterGen()
|
||||||
if teles := diff.Telegrafs; len(teles) > 0 {
|
if teles := diff.Telegrafs; len(teles) > 0 {
|
||||||
headers := []string{"New", "Name", "Description"}
|
headers := []string{"New", "Name", "Description"}
|
||||||
tablePrintFn("TELEGRAF CONFIGS", headers, len(teles), func(i int) []string {
|
tablePrintFn("TELEGRAF CONFIGS", headers, len(teles), func(i int) []string {
|
||||||
|
|
|
@ -217,7 +217,7 @@ func (ex *resourceExporter) resourceCloneToKind(ctx context.Context, r ResourceT
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mapResource(dash.OrganizationID, dash.ID, KindDashboard, DashboardToObject(*dash, r.Name))
|
mapResource(dash.OrganizationID, dash.ID, KindDashboard, DashboardToObject(r.Name, *dash))
|
||||||
case r.Kind.is(KindLabel):
|
case r.Kind.is(KindLabel):
|
||||||
l, err := ex.labelSVC.FindLabelByID(ctx, r.ID)
|
l, err := ex.labelSVC.FindLabelByID(ctx, r.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -761,7 +761,7 @@ func convertQueries(iQueries []influxdb.DashboardQuery) queries {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DashboardToObject converts an influxdb.Dashboard to an Object.
|
// DashboardToObject converts an influxdb.Dashboard to an Object.
|
||||||
func DashboardToObject(dash influxdb.Dashboard, name string) Object {
|
func DashboardToObject(name string, dash influxdb.Dashboard) Object {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = dash.Name
|
name = dash.Name
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,30 +275,76 @@ func (d DiffCheck) IsNew() bool {
|
||||||
return d.Old == nil
|
return d.Old == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiffDashboard is a diff of an individual dashboard. This resource is always new.
|
// DiffDashboardValues are values for a dashboard.
|
||||||
type DiffDashboard struct {
|
type DiffDashboardValues struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Desc string `json:"description"`
|
Desc string `json:"description"`
|
||||||
Charts []DiffChart `json:"charts"`
|
Charts []DiffChart `json:"charts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiffDashboard is a diff of an individual dashboard.
|
||||||
|
type DiffDashboard struct {
|
||||||
|
ID SafeID `json:"id"`
|
||||||
|
Remove bool `json:"remove"`
|
||||||
|
PkgName string `json:"pkgName"`
|
||||||
|
New DiffDashboardValues `json:"new"`
|
||||||
|
Old *DiffDashboardValues `json:"old"`
|
||||||
|
}
|
||||||
|
|
||||||
func newDiffDashboard(d *dashboard) DiffDashboard {
|
func newDiffDashboard(d *dashboard) DiffDashboard {
|
||||||
diff := DiffDashboard{
|
diff := DiffDashboard{
|
||||||
Name: d.Name(),
|
ID: SafeID(d.ID()),
|
||||||
Desc: d.Description,
|
PkgName: d.PkgName(),
|
||||||
|
New: DiffDashboardValues{
|
||||||
|
Name: d.Name(),
|
||||||
|
Desc: d.Description,
|
||||||
|
Charts: make([]DiffChart, 0, len(d.Charts)),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range d.Charts {
|
for _, c := range d.Charts {
|
||||||
diff.Charts = append(diff.Charts, DiffChart{
|
diff.New.Charts = append(diff.New.Charts, DiffChart{
|
||||||
Properties: c.properties(),
|
Properties: c.properties(),
|
||||||
Height: c.Height,
|
Height: c.Height,
|
||||||
Width: c.Width,
|
Width: c.Width,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !d.Exists() {
|
||||||
|
return diff
|
||||||
|
}
|
||||||
|
|
||||||
|
oldDiff := DiffDashboardValues{
|
||||||
|
Name: d.existing.Name,
|
||||||
|
Desc: d.existing.Description,
|
||||||
|
Charts: make([]DiffChart, 0, len(d.existing.Cells)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range d.existing.Cells {
|
||||||
|
var props influxdb.ViewProperties
|
||||||
|
if c.View != nil {
|
||||||
|
props = c.View.Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
oldDiff.Charts = append(oldDiff.Charts, DiffChart{
|
||||||
|
Properties: props,
|
||||||
|
XPosition: int(c.X),
|
||||||
|
YPosition: int(c.Y),
|
||||||
|
Height: int(c.H),
|
||||||
|
Width: int(c.W),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
diff.Old = &oldDiff
|
||||||
|
|
||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNew indicates whether the pkg dashboard is new to the platform.
|
||||||
|
func (d DiffDashboard) IsNew() bool {
|
||||||
|
return d.Old != nil
|
||||||
|
}
|
||||||
|
|
||||||
// DiffChart is a diff of oa chart. Since all charts are new right now.
|
// DiffChart is a diff of oa chart. Since all charts are new right now.
|
||||||
// the SummaryChart is reused here.
|
// the SummaryChart is reused here.
|
||||||
type DiffChart SummaryChart
|
type DiffChart SummaryChart
|
||||||
|
@ -2317,6 +2363,8 @@ type dashboard struct {
|
||||||
Charts []chart
|
Charts []chart
|
||||||
|
|
||||||
labels sortedLabels
|
labels sortedLabels
|
||||||
|
|
||||||
|
existing *influxdb.Dashboard
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dashboard) ID() influxdb.ID {
|
func (d *dashboard) ID() influxdb.ID {
|
||||||
|
@ -2332,7 +2380,7 @@ func (d *dashboard) ResourceType() influxdb.ResourceType {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dashboard) Exists() bool {
|
func (d *dashboard) Exists() bool {
|
||||||
return false
|
return d.existing != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dashboard) summarize() SummaryDashboard {
|
func (d *dashboard) summarize() SummaryDashboard {
|
||||||
|
|
Loading…
Reference in New Issue