textmachine/platform/docs/p8-review/axis4-metrics/40-exposition-check.sh

36 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# A4/metrics — mechanical check of the LIVE exposition against the norms STACK_DECISIONS §24
# declares for this axis (base units seconds/bytes; `_total` on counters; no unit in a label;
# route label is a PATTERN, never a path; the unparsed request folds into one row).
set -uo pipefail
M=${1:-http://127.0.0.1:9104/metrics}
T=$(mktemp); curl -s --noproxy '*' "$M" > "$T"
echo "=== series in our namespace (rows a scraper stores) ==="
grep -c '^tm_platform_' "$T"
echo "=== metric families by TYPE ==="
grep '^# TYPE tm_platform_' "$T"
echo
echo "=== RULE: every COUNTER family ends in _total ==="
grep '^# TYPE tm_platform_.* counter$' "$T" | awk '{print $3}' | while read -r n; do
case "$n" in *_total) echo "ok $n";; *) echo "BREAK $n (counter without _total)";; esac
done
echo "=== RULE: no non-counter family ends in _total ==="
grep '^# TYPE tm_platform_' "$T" | awk '$4!="counter"{print $3, $4}' | while read -r n t; do
case "$n" in *_total) echo "BREAK $n is a $t named _total";; *) echo "ok $n ($t)";; esac
done
echo "=== RULE: units live in the NAME (seconds/bytes) and never in a label ==="
grep '^tm_platform_' "$T" | grep -E 'unit=|_ms[ {]|_millis|_microseconds|_usd[ {]' && echo "BREAK: a unit-bearing label or non-base unit above" || echo "ok no unit label, no non-base unit"
echo
echo "=== RULE: no identifier reaches a label (book/run/user ids) ==="
grep '^tm_platform_' "$T" | grep -E 'bk_[A-Z0-9]|rn_[A-Za-z0-9]|u_[A-Z0-9]' && echo "BREAK: an id is in the exposition" || echo "ok no bk_/rn_/u_ in any label"
echo
echo "=== CARDINALITY: label names per family, and how many rows each family has ==="
grep '^tm_platform_' "$T" | sed 's/ .*//' | sed -E 's/\{(.*)\}/ LABELS[\1]/' | \
awk '{fam=$1; sub(/_bucket$|_sum$|_count$/,"",fam); labels=""; if (match($0,/LABELS\[.*\]/)) {labels=substr($0,RSTART+7,RLENGTH-8); gsub(/="[^"]*"/,"",labels)} print fam" "labels}' | sort | uniq -c | sort -rn
echo
echo "=== the route label's observed values (must be PATTERNS or (unmatched)) ==="
grep -o 'route="[^"]*"' "$T" | sort -u
echo "=== the method label's observed values ==="
grep -o 'method="[^"]*"' "$T" | sort -u
rm -f "$T"