...

Text file src/github.com/letsencrypt/boulder/test/grafana/lint.py

Documentation: github.com/letsencrypt/boulder/test/grafana

     1# Check dashboard JSON files for common errors, like forgetting to templatize a
     2# datasource.
     3import json
     4import os
     5with open(os.path.join(os.path.dirname(os.path.realpath(__file__)),
     6    "boulderdash.json")) as f:
     7    dashboard = json.load(f)
     8
     9# When exporting, the current value of templated variables is saved. We don't
    10# want to save a specific value for datasource, since that's
    11# deployment-specific, so we ensure that the dashboard was exported with the
    12# datasource template variable set to "Default."
    13for li in dashboard["templating"]["list"]:
    14    if li["type"] == "datasource":
    15        assert(li["current"]["value"] == "default")
    16
    17# Additionally, ensure each panel's datasource is using the template variable
    18# rather than a hardcoded datasource. Grafana will choose a hardcoded
    19# datasource on new panels by default, so this is an easy mistake to make.
    20for ro in dashboard["rows"]:
    21    for pa in ro["panels"]:
    22        assert(pa["datasource"] == "$datasource")
    23
    24# It seems that __inputs is non-empty when template variables at the top of the
    25# dashboard have been modified from the defaults; check for that.
    26assert(len(dashboard["__inputs"]) == 0)

View as plain text