Skip to content

Runbooks Style Guide

This document outlines the style guide for Runbooks.

Jsonnet

Imports

Group imports by type, separated by a newline. There are three kinds of imports:

  • Global imports: these are files referenced relative from the Jsonnet Library paths (jpath).
  • Local imports: these are files referenced relative to the current file. These must be prefixed with ./ the make it clear that they are local.
  • Derived imports: these are resources extracted from imported files and bound to a local variable (e.g., g.dashboard or g.query.prometheus).

Within these groups, imports should be sorted alphabetically by the imported filename, not the variable name. This is enforced by the jsonnetfmt tool.

Example:

local basic = import 'basic.libsonnet';
local g = import 'grafonnet.libsonnet';
local config = import 'knmi-metrics-config.libsonnet';
local variables = import 'lib/variables.libsonnet';
local ruleRegistry = import 'service-metrics/rule-registry.libsonnet';
local catalog = import 'service-metrics/metrics-catalog.libsonnet';
local wrapV1Manifest = import 'utils/wrap_v1.libsonnet';

local keyMetrics = import './key-metrics.libsonnet';
local keyPanels = import './panels.libsonnet';

local gDashboard = g.dashboard;
local gPromQuery = g.query.prometheus;

Grafonnet Derived Imports

Use the variable name g for Grafonnet library imports.

Our Jsonnet heavily relies on Grafonnet, which provides a lot of functionality. To make it clear that these are derived from the Grafonnet import, we prefix them with g followed by PascalCase.

Example:

1
2
3
4
local g = import 'grafonnet.libsonnet';

local gDashboard = g.dashboard;
local gPromQuery = g.query.prometheus;