Skip to content

Commit 5490026

Browse files
authored
Copy some dashboard opinions from kubernete-mixin and apply to all dashboards. (#235)
* Copy some dashboard opinions from kubernete-mixin and apply to all dashboards. Previously, this would happen automatically as all mixins were merged into one. Now we keep mixins in different namespaces, this needs to be done by out grafana jsonnet code. Opinions are: // - Dashboard UIDs should be the md5 hash of their filename. // - Timezone should be default (ie local). // - Tooltip should only show a single value. Signed-off-by: Tom Wilkie <[email protected]> * review feedback Signed-off-by: Tom Wilkie <[email protected]>
1 parent fe0f55c commit 5490026

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

prometheus-ksonnet/grafana/dashboards.libsonnet

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,48 @@
1010
// New API: Mixins go in the mixins map.
1111
mixins+:: {},
1212

13-
// emptyMixin allows us to reliably do `mixin.grafanaDashboards` without
13+
// mixinProto allows us to reliably do `mixin.grafanaDashboards` without
1414
// having to check the field exists first. Some mixins don't declare all
1515
// the fields, and thats fine.
16-
local emptyMixin = {
17-
grafanaDashboards+: {},
16+
//
17+
// We also use this to add a little "opinion":
18+
// - Dashboard UIDs are set to the md5 hash of their filename.
19+
// - Timezone are set to be "default" (ie local).
20+
// - Tooltip only show a single value.
21+
local mixinProto = {
22+
grafanaDashboards+:: {},
23+
} + {
24+
local grafanaDashboards = super.grafanaDashboards,
25+
26+
grafanaDashboards+:: {
27+
[filename]:
28+
local dashboard = grafanaDashboards[filename];
29+
dashboard {
30+
uid: std.md5(filename),
31+
timezone: '',
32+
33+
[if std.objectHas(dashboard, 'rows') then 'rows']: [
34+
row {
35+
panels: [
36+
panel {
37+
tooltip+: {
38+
shared: false,
39+
},
40+
}
41+
for panel in super.panels
42+
],
43+
}
44+
for row in super.rows
45+
],
46+
}
47+
for filename in std.objectFields(grafanaDashboards)
48+
},
1849
},
1950

2051
// Legacy extension points for you to add your own dashboards.
2152
grafanaDashboards+:: std.foldr(
2253
function(mixinName, acc)
23-
local mixin = $.mixins[mixinName] + emptyMixin;
54+
local mixin = $.mixins[mixinName] + mixinProto;
2455
if !std.objectHas(mixin, 'grafanaDashboardFolder')
2556
then acc + mixin.grafanaDashboards
2657
else acc,
@@ -30,7 +61,7 @@
3061

3162
dashboardsByFolder+:: std.foldr(
3263
function(mixinName, acc)
33-
local mixin = $.mixins[mixinName] + emptyMixin;
64+
local mixin = $.mixins[mixinName] + mixinProto;
3465
if std.objectHas(mixin, 'grafanaDashboardFolder')
3566
then acc {
3667
[mixin.grafanaDashboardFolder]: mixin.grafanaDashboards,

0 commit comments

Comments
 (0)