[tools] "github:google/go-jsonnet" = "0.22.0" "go:github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb" = "0.6.0" "github:cloudflare/pint" = "0.89.2" "github:grafana/dashboard-linter" = "0.3.0" "github:prometheus/prometheus" = "3.15.0" [vars] sources = "*.libsonnet *.jsonnet lib/*.libsonnet rules/*.libsonnet alerts/*.libsonnet dashboards/*.libsonnet tests/*.libsonnet tests/*.jsonnet" fmt_flags = "-n 2 --max-blank-lines 2 --string-style s --comment-style s" dashboards = "../../dashboard" [tasks.generate] description = "Generate Prometheus rules, alerts, and the dashboard" alias = "default" depends = ["rules", "dashboard"] [tasks.rules] description = "Generate Prometheus rules and alerts" run = [ "jsonnet -S rules.jsonnet > windows_rules.yaml", "jsonnet -S alerts.jsonnet > windows_alerts.yaml", ] [tasks.vendor] description = "Install dashboard Jsonnet libraries" run = "jb install" [tasks.dashboard] description = "Regenerate the committed Grafana dashboards" alias = "dashboards" depends = ["vendor"] run = ''' set -eu out=$(mktemp -d) trap 'rm -rf "$out"' EXIT jsonnet -J vendor -S -m "$out" dashboard.jsonnet > /dev/null rm -f {{vars.dashboards}}/windows-exporter-*.json cp "$out"/*.json {{vars.dashboards}}/ ''' [tasks.check-dashboards] description = "Regenerate the dashboards and fail on uncommitted changes" depends = ["dashboard"] run = ''' set -eu git add --intent-to-add -- {{vars.dashboards}}/windows-exporter-*.json git diff --exit-code -- {{vars.dashboards}} ''' [tasks.lint-dashboards] description = "Lint the committed dashboards in strict mode" run = ''' set -eu for file in {{vars.dashboards}}/windows-exporter-*.json; do dashboard-linter lint --strict --config .dashboard-lint.yaml "$file" done ''' [tasks.fmt] description = "Format all mixin Jsonnet sources" run = "jsonnetfmt {{vars.fmt_flags}} -i {{vars.sources}}" [tasks.custom-rules] description = "Generate rules and alerts with the test configuration" hide = true run = [ '''jsonnet -S -e 'std.manifestYamlDoc((import "tests/config.libsonnet").prometheusRules)' > tests/custom_rules.yaml''', '''jsonnet -S -e 'std.manifestYamlDoc((import "tests/config.libsonnet").prometheusAlerts)' > tests/custom_alerts.yaml''', ] [tasks.lint] description = "Check Jsonnet formatting and lint, dashboard drift, and Prometheus rules" depends = ["rules", "custom-rules", "vendor", "lint-dashboards"] run = ''' set -eu for file in {{vars.sources}}; do jsonnetfmt {{vars.fmt_flags}} "$file" | diff -u "$file" - jsonnet-lint -J vendor "$file" done out=$(mktemp -d) trap 'rm -rf "$out"' EXIT jsonnet -J vendor -S -m "$out" dashboard.jsonnet > /dev/null (cd "$out" && ls windows-exporter-*.json) > "$out/generated" (cd {{vars.dashboards}} && ls windows-exporter-*.json) | diff -u "$out/generated" - \ || { echo "{{vars.dashboards}} has missing or stale dashboards; run mise run dashboard"; exit 1; } for file in $(cat "$out/generated"); do diff -u {{vars.dashboards}}/"$file" "$out/$file" \ || { echo "{{vars.dashboards}}/$file is out of date; run mise run dashboard"; exit 1; } done promtool check rules windows_rules.yaml windows_alerts.yaml tests/custom_rules.yaml tests/custom_alerts.yaml ../../docs/upgrade/0.32.prom pint --offline lint windows_rules.yaml windows_alerts.yaml pint --offline lint tests/custom_rules.yaml tests/custom_alerts.yaml ''' [tasks.check-runbooks] description = "Check runbook coverage for all alerts, including opt-in alerts" run = '''jsonnet -e '(import "mixin.libsonnet") { _config+:: { enableActiveDirectory: true, enableTime: true } }.prometheusAlerts' | python3 tests/check_runbooks.py ../../docs/runbooks''' [tasks.test] description = "Run all mixin lint, runbook, and rule tests" depends = ["lint", "check-runbooks", "vendor"] run = [ "jsonnet tests/runbooks.test.jsonnet", "jsonnet -J vendor tests/dashboard.test.jsonnet > /dev/null", "promtool test rules tests/*.test.yaml", ] [tasks.clean] description = "Remove generated rule and alert files" run = "rm -f windows_rules.yaml windows_alerts.yaml tests/custom_rules.yaml tests/custom_alerts.yaml"