Skip to content

Commit 30f5ba1

Browse files
nit: conditional valueMaps in overrides in signals lib (#1365)
* clean: conditional valueMaps in overrides in signals lib * Update panels.libsonnet (#1364) Co-authored-by: v-zhuravlev <[email protected]> * Fix tests --------- Co-authored-by: Jan-Otto Kröpke <[email protected]>
1 parent 560e361 commit 30f5ba1

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

common-lib/common/signal/base.libsonnet

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,18 @@ local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';
118118
if override == 'byQuery' then
119119
g.panel.timeSeries.fieldOverride.byQuery.new(name)
120120
+ g.panel.timeSeries.fieldOverride.byQuery.withPropertiesFromOptions(
121-
g.panel.timeSeries.standardOptions.withUnit(self.unit)
122-
+ g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps))
121+
(if std.length(this.getValueMappings(sourceMaps)) > 0 then
122+
g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps))
123+
else {})
124+
+ g.panel.timeSeries.standardOptions.withUnit(self.unit)
123125
)
124126
else if override == 'byName' then
125127
g.panel.timeSeries.fieldOverride.byName.new(name)
126128
+ g.panel.timeSeries.fieldOverride.byName.withPropertiesFromOptions(
127-
g.panel.timeSeries.standardOptions.withUnit(self.unit)
128-
+ g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps))
129+
(if std.length(this.getValueMappings(sourceMaps)) > 0 then
130+
g.panel.timeSeries.standardOptions.withMappings(this.getValueMappings(sourceMaps))
131+
else {})
132+
+ g.panel.timeSeries.standardOptions.withUnit(self.unit)
129133
)
130134
else error 'Unknown override type, only "byName", "byQuery" are supported.',
131135
],

common-lib/common/signal/test_counter.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local m1 = signal.init(
4646
expect: 'API server requests',
4747
},
4848
testUnit: {
49-
actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[1].value,
49+
actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[0].value,
5050
expect: 'rps',
5151
},
5252
testTStype: {

common-lib/common/signal/test_gauge.libsonnet

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ local gauge1 = signal.init(
1515
rangeFunction: null,
1616
aggKeepLabels: [],
1717
legendCustomTemplate: null,
18+
valueMappings: [{
19+
type: 'value',
20+
options: {
21+
'1': {
22+
text: 'Up',
23+
color: 'light-green',
24+
index: 1,
25+
},
26+
'0': {
27+
text: 'Down',
28+
color: 'light-red',
29+
index: 0,
30+
},
31+
},
32+
}],
1833
},
1934
]
2035
);
@@ -46,6 +61,10 @@ local gauge1 = signal.init(
4661
actual: gauge1.asTimeSeries().fieldConfig.overrides[0].properties[1].value,
4762
expect: 'short',
4863
},
64+
testValueMapping: {
65+
actual: gauge1.asTimeSeries().fieldConfig.overrides[0].properties[0].value,
66+
expect: [{ options: { '0': { color: 'light-red', index: 0, text: 'Down' }, '1': { color: 'light-green', index: 1, text: 'Up' } }, type: 'value' }],
67+
},
4968
testTStype: {
5069
actual: gauge1.asTimeSeries().type,
5170
expect: 'timeseries',

common-lib/common/signal/test_histogram.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local m1 = signal.init(
4545
expect: 'API server duration',
4646
},
4747
testUnit: {
48-
actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[1].value,
48+
actual: m1.asTimeSeries().fieldConfig.overrides[0].properties[0].value,
4949
expect: 'seconds',
5050
},
5151
testTStype: {

common-lib/common/signal/test_table.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ local m1 = signal.init(
6868
expect: 'API server requests',
6969
},
7070
testUnit: {
71-
actual: m1.asTable().fieldConfig.overrides[0].properties[1].value,
71+
actual: m1.asTable().fieldConfig.overrides[0].properties[0].value,
7272
expect: 'rps',
7373
},
7474
testTStype: {

0 commit comments

Comments
 (0)