Skip to content
Merged
Changes from all commits
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
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 are set to the md5 hash of their filename.
// - Timezone are set to be "default" (ie local).
// - Tooltip only show a single value.
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