diff --git a/common-lib/common/signal/base.libsonnet b/common-lib/common/signal/base.libsonnet index e5bf77663..843e00ee6 100644 --- a/common-lib/common/signal/base.libsonnet +++ b/common-lib/common/signal/base.libsonnet @@ -118,20 +118,18 @@ local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet'; if override == 'byQuery' then g.panel.timeSeries.fieldOverride.byQuery.new(name) + g.panel.timeSeries.fieldOverride.byQuery.withPropertiesFromOptions( - g.panel.timeSeries.standardOptions.withUnit(self.unit) - + (if std.length(this.getValueMappings(sourceMaps)) > 0 then g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps)) else {}) + + g.panel.timeSeries.standardOptions.withUnit(self.unit) ) else if override == 'byName' then g.panel.timeSeries.fieldOverride.byName.new(name) + g.panel.timeSeries.fieldOverride.byName.withPropertiesFromOptions( - g.panel.timeSeries.standardOptions.withUnit(self.unit) - + (if std.length(this.getValueMappings(sourceMaps)) > 0 then g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps)) else {}) + + g.panel.timeSeries.standardOptions.withUnit(self.unit) ) else error 'Unknown override type, only "byName", "byQuery" are supported.', ], diff --git a/common-lib/common/signal/test_counter.libsonnet b/common-lib/common/signal/test_counter.libsonnet index 389fd6863..d226301e4 100644 --- a/common-lib/common/signal/test_counter.libsonnet +++ b/common-lib/common/signal/test_counter.libsonnet @@ -46,7 +46,7 @@ local m1 = signal.init( expect: 'API server requests', }, testUnit: { - actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[1].value, + actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[0].value, expect: 'rps', }, testTStype: { diff --git a/common-lib/common/signal/test_gauge.libsonnet b/common-lib/common/signal/test_gauge.libsonnet index 99b846420..ebb3fdf23 100644 --- a/common-lib/common/signal/test_gauge.libsonnet +++ b/common-lib/common/signal/test_gauge.libsonnet @@ -15,6 +15,21 @@ local gauge1 = signal.init( rangeFunction: null, aggKeepLabels: [], legendCustomTemplate: null, + valueMappings: [{ + type: 'value', + options: { + '1': { + text: 'Up', + color: 'light-green', + index: 1, + }, + '0': { + text: 'Down', + color: 'light-red', + index: 0, + }, + }, + }], }, ] ); @@ -46,6 +61,10 @@ local gauge1 = signal.init( actual: gauge1.asTimeSeries().fieldConfig.overrides[0].properties[1].value, expect: 'short', }, + testValueMapping: { + actual: gauge1.asTimeSeries().fieldConfig.overrides[0].properties[0].value, + expect: [{ options: { '0': { color: 'light-red', index: 0, text: 'Down' }, '1': { color: 'light-green', index: 1, text: 'Up' } }, type: 'value' }], + }, testTStype: { actual: gauge1.asTimeSeries().type, expect: 'timeseries', diff --git a/common-lib/common/signal/test_histogram.libsonnet b/common-lib/common/signal/test_histogram.libsonnet index ee3862600..1ca944ee2 100644 --- a/common-lib/common/signal/test_histogram.libsonnet +++ b/common-lib/common/signal/test_histogram.libsonnet @@ -45,7 +45,7 @@ local m1 = signal.init( expect: 'API server duration', }, testUnit: { - actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[1].value, + actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[0].value, expect: 'seconds', }, testTStype: { diff --git a/common-lib/common/signal/test_table.libsonnet b/common-lib/common/signal/test_table.libsonnet index 4d963b5bd..7ed7f5fda 100644 --- a/common-lib/common/signal/test_table.libsonnet +++ b/common-lib/common/signal/test_table.libsonnet @@ -68,7 +68,7 @@ local m1 = signal.init( expect: 'API server requests', }, testUnit: { - actual: m1.asTable().fieldConfig.overrides[0].properties[1].value, + actual: m1.asTable().fieldConfig.overrides[0].properties[0].value, expect: 'rps', }, testTStype: {