Skip to content

Commit

Permalink
nit: conditional valueMaps in overrides in signals lib (#1365)
Browse files Browse the repository at this point in the history
* clean: conditional valueMaps in overrides in signals lib

* Update panels.libsonnet (#1364)

Co-authored-by: v-zhuravlev <v-zhuravlev@users.noreply.github.com>

* Fix tests

---------

Co-authored-by: Jan-Otto Kröpke <github@jkroepke.de>
  • Loading branch information
v-zhuravlev and jkroepke authored Dec 10, 2024
1 parent 560e361 commit 30f5ba1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
12 changes: 8 additions & 4 deletions common-lib/common/signal/base.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +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)
+ g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps))
(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)
+ g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps))
(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.',
],
Expand Down
2 changes: 1 addition & 1 deletion common-lib/common/signal/test_counter.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
19 changes: 19 additions & 0 deletions common-lib/common/signal/test_gauge.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}],
},
]
);
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion common-lib/common/signal/test_histogram.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion common-lib/common/signal/test_table.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 30f5ba1

Please sign in to comment.