Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Copy some dashboard opinions from kubernete-mixin and apply to all da…
…shboards.

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]>
  • Loading branch information
tomwilkie committed Apr 8, 2020
commit 062651217749217cd0145a75c25fe3913b6649b4
41 changes: 36 additions & 5 deletions prometheus-ksonnet/grafana/dashboards.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,48 @@
// New API: Mixins go in the mixins map.
mixins+:: {},

// emptyMixin allows us to reliably do `mixin.grafanaDashboards` without
// mixinProto allows us to reliably do `mixin.grafanaDashboards` without
// having to check the field exists first. Some mixins don't declare all
// the fields, and thats fine.
local emptyMixin = {
grafanaDashboards+: {},
//
// We also use this to add a little "opinion":
// - Dashboard UIDs should be the md5 hash of their filename.
// - Timezone should be "default" (ie local).
// - Tooltip should only show a single value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should sounds like we do validation here – but we actually just force this behaviour

local mixinProto = {
grafanaDashboards+:: {},
} + {
local grafanaDashboards = super.grafanaDashboards,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to clarify, super here is the already merged $.mixins[mixinName] + { grafanaDashboards+:: {} }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats just there so we can reliably reference super.grafanaDashboards (you can do std.hasField(super, ...).


grafanaDashboards+:: {
[filename]:
local dashboard = grafanaDashboards[filename];
dashboard {
uid: std.md5(filename),
timezone: '',

[if std.objectHas(dashboard, 'rows') then 'rows']: [
row {
panels: [
panel {
tooltip+: {
shared: false,
},
}
for panel in super.panels
],
}
for row in super.rows
],
}
for filename in std.objectFields(grafanaDashboards)
},
},

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

dashboardsByFolder+:: std.foldr(
function(mixinName, acc)
local mixin = $.mixins[mixinName] + emptyMixin;
local mixin = $.mixins[mixinName] + mixinProto;
if std.objectHas(mixin, 'grafanaDashboardFolder')
then acc {
[mixin.grafanaDashboardFolder]: mixin.grafanaDashboards,
Expand Down