Skip to content

Commit

Permalink
chore: added missing dashboard raw configuration fields (#1428)
Browse files Browse the repository at this point in the history
Merging the pr by squash and merge
  • Loading branch information
RavitejaSurampudi authored Mar 8, 2023
1 parent 342db7c commit 91863cf
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
88 changes: 79 additions & 9 deletions internal/utils/terraform/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ var (
)

type DashboardWidgetRawConfiguration struct {
DataFormatters []DataFormatter `json:"dataFormatters"`
NRQLQueries []DashboardWidgetNRQLQuery `json:"nrqlQueries"`
LinkedEntityGUIDs []string `json:"linkedEntityGuids"`
Text string `json:"text"`
Facet DashboardWidgetFacet `json:"facet"`
Legend DashboardWidgetLegend `json:"legend"`
YAxisLeft DashboardWidgetYAxisLeft `json:"yAxisLeft"`
DataFormatters []DataFormatter `json:"dataFormatters"`
NRQLQueries []DashboardWidgetNRQLQuery `json:"nrqlQueries"`
LinkedEntityGUIDs []string `json:"linkedEntityGuids"`
Text string `json:"text"`
Facet DashboardWidgetFacet `json:"facet,omitempty"`
Legend DashboardWidgetLegend `json:"legend,omitempty"`
YAxisLeft DashboardWidgetYAxisLeft `json:"yAxisLeft,omitempty"`
NullValues DashboardWidgetNullValues `json:"nullValues,omitempty"`
Units DashboardWidgetUnits `json:"units,omitempty"`
Colors DashboardWidgetColors `json:"colors,omitempty"`
PlatformOptions DashboardWidgetPlatformOptions `json:"platformOptions,omitempty"`
}

type DataFormatter struct {
Expand All @@ -55,11 +59,44 @@ type DashboardWidgetNRQLQuery struct {
}

type DashboardWidgetLegend struct {
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled,omitempty"`
}

type DashboardWidgetYAxisLeft struct {
Zero bool `json:"zero"`
Max float64 `json:"max,omitempty"`
Min float64 `json:"min,omitempty"`
}

type DashboardWidgetNullValues struct {
NullValue string `json:"nullValue,omitempty"`
SeriesOverrides []DashboardWidgetNullValueOverrides `json:"seriesOverrides,omitempty"`
}

type DashboardWidgetNullValueOverrides struct {
NullValue string `json:"nullValue,omitempty"`
SeriesName string `json:"seriesName,omitempty"`
}
type DashboardWidgetUnits struct {
Unit string `json:"unit,omitempty"`
SeriesOverrides []DashboardWidgetUnitOverrides `json:"seriesOverrides,omitempty"`
}

type DashboardWidgetUnitOverrides struct {
Unit string `json:"unit,omitempty"`
SeriesName string `json:"seriesName,omitempty"`
}

type DashboardWidgetColors struct {
Color string `json:"color,omitempty"`
SeriesOverrides []DashboardWidgetColorOverrides `json:"seriesOverrides,omitempty"`
}

type DashboardWidgetColorOverrides struct {
Color string `json:"color,omitempty"`
SeriesName string `json:"seriesName,omitempty"`
}
type DashboardWidgetPlatformOptions struct {
IgnoreTimeRange bool `json:"ignoreTimeRange,omitempty"`
}

func GenerateDashboardHCL(resourceLabel string, shiftWidth int, input []byte) (string, error) {
Expand Down Expand Up @@ -100,6 +137,39 @@ func GenerateDashboardHCL(resourceLabel string, shiftWidth int, input []byte) (s
h.WriteMultilineStringAttribute("query", q.Query)
})
}
h.WriteBooleanAttribute("facet_show_other_series", config.Facet.ShowOtherSeries)
h.WriteBooleanAttribute("legend_enabled", config.Legend.Enabled)
h.WriteBooleanAttribute("ignore_time_range", config.PlatformOptions.IgnoreTimeRange)
h.WriteFloatAttribute("y_axis_left_min", config.YAxisLeft.Min)
h.WriteFloatAttribute("y_axis_left_max", config.YAxisLeft.Max)
h.WriteBlock("null_values", []string{}, func() {
h.WriteStringAttribute("null_value", config.NullValues.NullValue)
for _, so := range config.NullValues.SeriesOverrides {
h.WriteBlock("series_overrides", []string{}, func() {
h.WriteStringAttribute("null_value", so.NullValue)
h.WriteStringAttribute("series_name", so.SeriesName)
})
}
})
h.WriteBlock("units", []string{}, func() {
h.WriteStringAttribute("unit", config.Units.Unit)
for _, so := range config.Units.SeriesOverrides {
h.WriteBlock("series_overrides", []string{}, func() {
h.WriteStringAttribute("unit", so.Unit)
h.WriteStringAttribute("series_name", so.SeriesName)
})
}
})
h.WriteBlock("colors", []string{}, func() {
h.WriteStringAttribute("color", config.Colors.Color)
for _, so := range config.Colors.SeriesOverrides {
h.WriteBlock("series_overrides", []string{}, func() {
h.WriteStringAttribute("color", so.Color)
h.WriteStringAttribute("series_name", so.SeriesName)
})
}
})

})
}
})
Expand Down
7 changes: 7 additions & 0 deletions internal/utils/terraform/hcl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func (h *HCLGen) WriteStringAttribute(label string, value string) {
h.WriteString(fmt.Sprintf("%s%s = \"%s\"\n", h.i, label, strings.ReplaceAll(value, "\"", "\\\"")))
}

func (h *HCLGen) WriteBooleanAttribute(label string, value bool) {
h.WriteString(fmt.Sprintf("%s%s = %t\n", h.i, label, value))
}
func (h *HCLGen) WriteFloatAttribute(label string, value float64) {
h.WriteString(fmt.Sprintf("%s%s = %g\n", h.i, label, value))
}

func (h *HCLGen) WriteStringAttributeIfNotEmpty(label string, value string) {
if value != "" {
h.WriteStringAttribute(label, value)
Expand Down

0 comments on commit 91863cf

Please sign in to comment.