Skip to content

Commit acb7cdf

Browse files
authored
Merge branch 'master' into feat/couchbase-modernization
2 parents 37c390d + afeacf2 commit acb7cdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4186
-793
lines changed

common-lib/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
# 0.4.0
2+
- [Signal] Add defaultSignalSource param to set default signal source.
3+
4+
# 0.3.5
5+
- [Variables] Add queriesSelectorGroupOnly, queriesSelectorFilterOnly attributes
6+
- [Signal] Add %(queriesSelectorGroupOnly)s, %(queriesSequeriesSelectorFilterOnly)s templates
7+
- [Signal] Fix legend rendering when aggLevel is none
8+
- [Panel] Fix id conflict if topkPercentage panel is used with signal.asTarget()
9+
110
# 0.3.4
211
- [Signal] Fix interval template for increase/delta functions.
312

413
# 0.3.3
5-
- [Signal] add `withQuantile(quantile=0.95)` to histogram signals.
14+
- [Signal] Add `withQuantile(quantile=0.95)` to histogram signals.
615

716
# 0.3.2
817
- [Signal] Fix combining info metrics.

common-lib/common/panels/generic/timeSeries/topk_percentage.libsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ base {
2424
);
2525
local meanTarget = target
2626
{ expr: 'avg(' + target.expr + ')' }
27-
+ g.query.prometheus.withLegendFormat('Mean');
27+
+ g.query.prometheus.withLegendFormat('Mean')
28+
+ g.query.prometheus.withRefId('Mean');
2829
super.new(title, targets=[topTarget, meanTarget], description=description)
2930
+ self.withDataLink(instanceLabels, drillDownDashboardUid),
3031

common-lib/common/signal/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Init level:
8484
|varAdHocEnabled| Attach ad hoc labels to variables generated. |`true`,`false`|`false`|`false`|
8585
|varAdHocLabels| Limit ad hoc to the specific labels |*|`["environment"]`|`[]`|
8686
|enableLokiLogs| Add additional loki datasource to variables generation |`true`,`false`|`true`|`false`|
87+
|defaultSignalSource| Set default signal source (see below) | * | `prometheus` |
8788

8889
Signal's level:
8990

@@ -111,6 +112,8 @@ Signal's level:
111112
The following is supported in expressions and legends:
112113

113114
- `%(queriesSelector)s` - expands to filteringSelector matchers and matchers based on instanceLabels, and groupLabels
115+
- `%(queriesSelectorGroupOnly)s` - expands to filteringSelector matchers and matchers based on groupLabels only
116+
- `%(queriesSelectorFilterOnly)s` - expands to filteringSelector matchers only
114117
- `%(filteringSelector)s` - expands to filteringSelector matchers
115118
- `%(groupLabels)s` - expands to groupLabels list
116119
- `%(instanceLabels)s` - expands to instanceLabels list
@@ -122,7 +125,7 @@ The following is supported in expressions and legends:
122125

123126
## Making signals optional
124127

125-
When defining signals from multiple sources, you can make some of the signals optional. In this case, rendering will not throw a validation error that signal is missing for the specific source, while internal 'stub' type will be used and empty panel will be rendered instead.
128+
When defining signals from multiple sources, you can make some of the signals optional. In this case, rendering will not throw a validation error that signal is missing for the specific source (and also in source defined as `defaultSignalSource`), while internal 'stub' type will be used and empty panel will be rendered instead.
126129

127130
## Example 1: From JSON
128131

common-lib/common/signal/base.libsonnet

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';
8282
(
8383
if aggLevel == 'group' then super.groupLabels
8484
else if aggLevel == 'instance' then super.instanceLabels
85-
else if aggLevel == 'none' then []
85+
else if aggLevel == 'none' then super.instanceLabels
8686
),
8787
aggLegend: utils.labelsToPanelLegend(
8888
// keep last label
@@ -123,6 +123,8 @@ local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';
123123
),
124124
],
125125
queriesSelector+: ',' + mixin,
126+
queriesSelectorGroupOnly+: ',' + mixin,
127+
queriesSelectorFilterOnly+: ',' + mixin,
126128
},
127129
},
128130

@@ -287,6 +289,8 @@ local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';
287289
interval: this.vars.alertsInterval,
288290
// keep only filteringSelector, remove any Grafana dashboard variables:
289291
queriesSelector: this.vars.filteringSelector[0],
292+
queriesSelectorGroupOnly: this.vars.filteringSelector[0],
293+
queriesSelectorFilterOnly: this.vars.filteringSelector[0],
290294
}
291295
for source in this.sourceMaps
292296
]

common-lib/common/signal/signal.libsonnet

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local info = import './info.libsonnet';
88
local log = import './log.libsonnet';
99
local raw = import './raw.libsonnet';
1010
local stub = import './stub.libsonnet';
11+
local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';
1112
{
1213
//Expected signalsJson format:
1314
// {
@@ -86,6 +87,7 @@ local stub = import './stub.libsonnet';
8687
else //array
8788
type
8889
);
90+
local defaultSignalSource = std.get(signalsJson, 'defaultSignalSource', 'prometheus');
8991

9092
self.init(
9193
datasource=std.get(signalsJson, 'datasource', if std.get(signalsJson, 'enableLokiLogs', false) then 'prometheus_datasource' else 'datasource'),
@@ -95,7 +97,7 @@ local stub = import './stub.libsonnet';
9597
instanceLabels=signalsJson.instanceLabels,
9698
interval=std.get(signalsJson, 'interval', '$__rate_interval'),
9799
alertsInterval=std.get(signalsJson, 'alertsInterval', '5m'),
98-
varMetric=self.getVarMetric(signalsJson, type),
100+
varMetric=self.getVarMetric(signalsJson, type, defaultSignalSource),
99101
aggLevel=std.get(signalsJson, 'aggLevel', 'none'),
100102
aggFunction=std.get(signalsJson, 'aggFunction', 'avg'),
101103
aggKeepLabels=std.get(signalsJson, 'aggKeepLabels', []),
@@ -117,9 +119,18 @@ local stub = import './stub.libsonnet';
117119
if
118120
std.get(signalsJson.signals[s], 'optional', false) == false
119121
&&
120-
!std.objectHas(signalsJson.signals[s].sources, sourceName)
122+
(
123+
!std.objectHas(signalsJson.signals[s].sources, sourceName)
124+
&&
125+
!std.objectHas(signalsJson.signals[s].sources, defaultSignalSource)
126+
)
121127
then error 'must provide source for signal %s of type=%s' % [s, sourceName]
122-
else sourceName
128+
else (
129+
if
130+
std.objectHas(signalsJson.signals[s].sources, sourceName) then sourceName
131+
else if
132+
std.objectHas(signalsJson.signals[s].sources, defaultSignalSource) then defaultSignalSource
133+
)
123134
for sourceName in typeArr
124135
];
125136
local sourceMaps =
@@ -211,6 +222,8 @@ local stub = import './stub.libsonnet';
211222
groupLabels: groupLabels,
212223
instanceLabels: instanceLabels,
213224
queriesSelector: grafanaVariables.queriesSelector,
225+
queriesSelectorGroupOnly: grafanaVariables.queriesSelectorGroupOnly,
226+
queriesSelectorFilterOnly: grafanaVariables.queriesSelectorFilterOnly,
214227
interval: interval,
215228
alertsInterval: alertsInterval,
216229
},
@@ -345,14 +358,14 @@ local stub = import './stub.libsonnet';
345358
),
346359
},
347360

348-
getVarMetric(signalsJson, type):
361+
getVarMetric(signalsJson, type, defaultSignalSource):
349362
if std.objectHas(signalsJson, 'discoveryMetric')
350363
then
351364
if std.type(type) == 'array' then
352365
std.prune(
353-
[std.get(signalsJson.discoveryMetric, t, null) for t in type]
366+
[std.get(signalsJson.discoveryMetric, t, std.get(signalsJson.discoveryMetric, defaultSignalSource, null)) for t in type]
354367
)
355368
else
356-
std.get(signalsJson.discoveryMetric, type, 'up')
369+
std.get(signalsJson.discoveryMetric, type, std.get(signalsJson.discoveryMetric, defaultSignalSource, 'up'))
357370
else 'up',
358371
}

0 commit comments

Comments
 (0)