Skip to content

Simple dashboard sanity checks #96

@maxbrunet

Description

@maxbrunet

Not sure if this can be part of this project, I just want to share this somewhere.

It can be quiet cumbersome to check for things like unique UID and titles, so I integrated the logic in Jsonnet, and then generating the deployment simply fails if the condition are not met.

local folderDashboards = {
  // Example
  AWS: import 'aws/folder.libsonnet',
  Datastores: import 'datastores/folder.libsonnet',
  Kubernetes: import 'kubernetes/folder.libsonnet',
  myServices: import 'myServices/folder.libsonnet',
  System: import 'system/folder.libsonnet',
};

local titles = [
  folderDashboards[folder][filename].title
  for folder in std.objectFields(folderDashboards)
  for filename in std.objectFields(folderDashboards[folder])
];

local filenames = [
  filename
  for folder in std.objectFields(folderDashboards)
  for filename in std.objectFields(folderDashboards[folder])
];

local isTitleUnique(title) =
  if std.count(titles, title) > 1 then
    error 'Title "%s" is used more than once' % [title]
  else true;

local isFilenameUnique(filename) =  // Means UID will be unique
  if std.count(filenames, filename) > 1 then
    error 'Filename "%s" is used more than once' % [filename]
  else true;

{
  [folder]: {
    [filename]: folderDashboards[folder][filename] {
      uid:
        // Checks need to be included into a non-hidden field
        // else they would never be evaluated
        if isFilenameUnique(filename) && isTitleUnique(self.title) then
          // We could hash folder+filename, but this would break
          // the dashboard URL if it is moved
          std.md5(filename),
    }
    for filename in std.objectFields(folderDashboards[folder])
  }
  for folder in std.objectFields(folderDashboards)
}

Every dashboard needs a UID, so the checks are called while setting it.

and then, pass the output to _config.grafana.folderDashboards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions