#!/bin/sh # CI lint: every literal `"service.name"=""` selector in a shipped grafana # dashboard must name a service.name that something emits. A dashboard # querying a name nobody sets renders empty panels with no error. # # `known` lists the emitted names, one `name|file|anchor` per line. The # anchor is a fixed string that must still appear in that file, so an entry # cannot outlive the code that sets the name. Regex selectors # (`"service.name"=~"$service"`) are template variables and are not checked. # set -eu dashboards_dir="nix/host-modules/swarm-grafana/dashboards" # bao: `collectorServiceName` upserted on the store's collector. # authelia, forgejo: `serviceName` of the journal forwarder in each module. # swarm-controller: the resource of the controller's own metrics. # otelcol-contrib: the unset default of the collector binary, which the hive # collector and swarm-otel both run (`pkgs.opentelemetry-collector-contrib`) # and which stamps their self-metrics. known='bao|nix/host-modules/swarm-bao.nix|collectorServiceName = "bao" authelia|nix/host-modules/swarm-authelia.nix|serviceName = "authelia" forgejo|nix/host-modules/hive-forge/default.nix|serviceName = "forgejo" swarm-controller|swarm-controller/src/vcs_metrics.rs|with_service_name("swarm-controller") otelcol-contrib|nix/host-modules/otel.nix|package = pkgs.opentelemetry-collector-contrib' violations=0 while IFS='|' read -r name file anchor; do if ! grep -qF -- "$anchor" "$file" 2>/dev/null; then violations=$((violations + 1)) printf '::error file=%s::service.name "%s" is listed as emitted but %s no longer contains: %s\n' \ "$file" "$name" "$file" "$anchor" fi done <&2 exit 1 fi if [ "$violations" -gt 0 ]; then printf 'check-dashboard-service-names: %s violation(s)\n' "$violations" >&2 exit 1 fi echo "check-dashboard-service-names: $checked selector name(s) checked, clean" >&2