Skip to content

feat(registrar): export the snapshot content hash as a gauge value; plain divergence rule (#1329) - #1346

Merged
bpalermo merged 5 commits into
mainfrom
registrar-content-hash-gauge-1329
Oct 7, 2026
Merged

bpalermo merged 5 commits into
mainfrom
registrar-content-hash-gauge-1329

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Closes #1329

What

New registrar gauge aether.registrar.snapshot.content_hash (Prometheus: aether_registrar_snapshot_content_hash) whose value is the snapshot's content hash. One series per replica, no label that changes, so a content change moves the value and nothing is left in Prometheus's 5-minute lookback.

  • Value: the first 13 hex digits of the 16-digit content hash, as an integer in [0, 2^52). snapshotversion.ContentHashValue does the conversion, next to the existing version parser (no new parser: it takes the hash ContentHash() / State.ContentHash already yield).
  • Bit budget: a float64 has a 53-bit significand, so every integer up to 2^53 is exact and 53 bits would fit. I kept 52 because it is a whole number of hex digits: printf '%013x' <value> is the start of the <hash> in a version string.
  • Collision: two replicas serving different contents report the same value with probability 2^-52 (about 2.2e-16) per compared pair. It is a divergence check between a few replicas at one revision, not an identifier. The resume token still compares all 16 digits.
  • Where it is recorded: in the existing ObserveSnapshot callback, from the same single Snapshot.State() read as the revision gauges, so the hash and revision of one collection always describe the same contents. The hash itself is still computed under the mutation lock; nothing new runs there.
  • Every version form: clean <rev>.<hash>, dirty <rev>+<hash> and hash:<hash> all report the hash of what is served now.
  • kubernetes backend: the gauge is reported (it names the contents), snapshot_revision is not, so the rule returns nothing there. Two replicas can differ briefly on that backend because health derives from each replica's clock, so it is for reading by hand and is not alerted on.
  • Old metric: aether.registrar.snapshot.content{content_hash} is still exported, marked deprecated in its description, the code comment, the README and the runbook. Remove it in the release after this one.

The rule

count by (job, revision) (
  count_values by (job, revision) (
    "hash",
    aether_registrar_snapshot_content_hash
    * ignoring (revision) group_left (revision)
    count_values without () ("revision", aether_registrar_snapshot_revision)
  )
) > 1
unless on (job) (max by (job) (aether_registrar_writebehind_queue_depth) > 0)

for: 3m, same labels and alert identity ({job, revision}) as #1328. No timestamp() filter.

Do the two metrics' timestamps matter?

No. What I checked:

  • SDK (go.opentelemetry.io/otel/sdk/metric v1.47.0): pipeline.produce runs every callback first, then collects each aggregation; lastvalue.go stamps each instrument's data point with its own now(). So revision and hash come from one callback (one State()), with timestamps microseconds apart.
  • Live (talos-main, read-only query): timestamp(aether_registrar_snapshot_revision) - timestamp(aether_registrar_store_revision) per replica peaked at 4 ms over 24 h. The stamps are not identical, so a rule that paired on timestamp() equality across two metrics would be wrong.
  • Path: registrar -> OTLP -> collector batch (no send_batch_max_size, so it does not split a request) -> otlphttp -> Prometheus's OTLP receiver. I did not trace the receiver's commit path in the Prometheus source; I am relying on its documented one-appender-per-request behaviour.
  • The expression matches on labels, and an instant selector takes each series' latest sample, so it needs none of the above to be exact. If a pipeline ever delivered the two metrics apart, one evaluation could pair a new revision with the old hash on one replica. for: 3m (kept for the RPC-between-syncs window) covers that.

Rolling upgrade

A rule on the new metric cannot see a replica on an older image: before the registrar is upgraded it is empty, and mid-roll it compares only the new replicas. So docs/observability/registrar-alerts.yml carries the plain rule, and the runbook gives a two-arm form (new or #1328, one unless) for the upgrade. Both arms return {job, revision}, so one divergence is one alert. Order: deploy the two-arm rule, upgrade the registrar, drop the second arm, then take the release that removes the labelled metric.

GitOps mirror: not opened

bpalermo/k8s-talos-main#152 (which adds this alert in its #1328 form) is still open (checks green, mergeable), so I did not open a PR against that repo. The patch below applies on top of #152's head (9b33a0c); apply it after #152 merges. It switches the live rule to the two-arm form and adds tests.

Validated the way that repo's CI does, with promtool 3.6.0, on #152's head plus the patch:

  • kubectl kustomize clusters/talos-main: exit 0
  • promtool check rules: 67 rules, SUCCESS
  • promtool test rules: SUCCESS
Case Expect
value gauge, same revision, same hash (2^52-1 on both) quiet; by-hand query returns one row per replica
value gauge only (no labelled metric, no queue-depth series), hashes one apart fires at 13m (diverged at 10m)
both metrics, one divergence exactly one alert
both replicas change hash and revision together quiet at 9, 10, 11, 13, 15, 16, 30m; arm 1 alone counts 1
one replica a revision behind quiet
same revision, different hash, write-behind intent pending quiet (arm 1 alone counts 2)
mid-roll: old-image replica (labelled only) and new-image replica diverge fires at 13m through arm 2; arm 1 alone is pinned to 1 (blind)
mid-roll, replicas agree through a content change quiet
value gauge, no revision (kubernetes backend), different hashes quiet
the four #152 tests, unchanged inputs (only the old metric present) unchanged results; only the description text differs
k8s-talos-main patch (on top of #152)
diff --git a/clusters/talos-main/prometheus/rules_test.yaml b/clusters/talos-main/prometheus/rules_test.yaml
index bcf75ab..d74d4ce 100644
--- a/clusters/talos-main/prometheus/rules_test.yaml
+++ b/clusters/talos-main/prometheus/rules_test.yaml
@@ -1770,10 +1770,14 @@ tests:
 
 
   # ---------------------------------------------------------------------------
-  # AetherRegistrarSnapshotDiverged (aether#1322). `node` is the registrar POD on
-  # talos-main. content_hash is a label, so a content change ends one series and
-  # starts another; OTLP sends no staleness marker, so the old series stays visible
-  # for the 5m lookback. `_` is exactly that: the series stops, nothing marks it.
+  # AetherRegistrarSnapshotDiverged, ARM 2: replicas on an image BEFORE aether#1329,
+  # which export only aether_registrar_snapshot_content{content_hash} (aether#1322).
+  # `node` is the registrar POD on talos-main. content_hash is a label, so a content
+  # change ends one series and starts another; OTLP sends no staleness marker, so the
+  # old series stays visible for the 5m lookback. `_` is exactly that: the series
+  # stops, nothing marks it. These four tests are "only the old metric present": the
+  # rule must keep working on it until the registrar has rolled. Delete them with
+  # arm 2.
   # ---------------------------------------------------------------------------
   - interval: 1m
     name: registrar replicas at the same revision with the same hash are quiet
@@ -1826,12 +1830,14 @@ tests:
               summary: "registrar replicas serve 2 different endpoint sets at store revision 100"
               description: >-
                 Registrar replicas report the same aether_registrar_snapshot_revision
-                (100) with different content_hash labels on
-                aether_registrar_snapshot_content, and no write-behind intent is
+                (100) with different values of
+                aether_registrar_snapshot_content_hash (or, on an image before
+                aether#1329, different content_hash labels on
+                aether_registrar_snapshot_content), and no write-behind intent is
                 pending. The listing is a pure function of the revision, so at least
                 one replica is not serving what the store holds, and the agents
                 watching it program different endpoints from the rest of the fleet.
-                Compare `aether_registrar_snapshot_content` per replica, then the
+                Compare `aether_registrar_snapshot_content_hash` per replica, then the
                 registrar logs for sync errors and
                 `aether_registrar_sync_errors_total`. Restarting the odd replica
                 makes it list again, but keep its logs first: this is a bug, see
@@ -1923,6 +1929,348 @@ tests:
         exp_alerts: []
 
 
+  # ---------------------------------------------------------------------------
+  # AetherRegistrarSnapshotDiverged, ARM 1 (aether#1329): the hash is the VALUE of
+  # aether_registrar_snapshot_content_hash, a 52-bit integer. The values below are
+  # real-sized (2^52-1 and its neighbour) so the tests also pin that Prometheus keeps
+  # two adjacent hashes apart. An image with the value gauge exports the labelled
+  # metric too for one release, so both are present unless a test says otherwise.
+  # ---------------------------------------------------------------------------
+  - interval: 1m
+    name: (value gauge) registrar replicas at the same revision with the same hash are quiet
+    input_series:
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-a"}'
+        values: "4503599627370495x30"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "4503599627370495x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="ffffffffffffffff"}'
+        values: "1x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="ffffffffffffffff"}'
+        values: "1x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "100x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x30"
+    promql_expr_test:
+      # the by-hand query: one row per replica, value = hash, revision as a label
+      - eval_time: 5m
+        expr: |
+          aether_registrar_snapshot_content_hash
+            * ignoring (revision) group_left (revision)
+            count_values without () ("revision", aether_registrar_snapshot_revision)
+        exp_samples:
+          - labels: '{job="aether-registrar",node="registrar-a",revision="100"}'
+            value: 4503599627370495
+          - labels: '{job="aether-registrar",node="registrar-b",revision="100"}'
+            value: 4503599627370495
+    alert_rule_test:
+      - eval_time: 20m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+
+  # No labelled metric and no queue-depth series at all: arm 1 stands on its own.
+  # This is the state after the labelled metric is removed.
+  - interval: 1m
+    name: (value gauge only) same revision, hashes one apart, alert after 3m
+    input_series:
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-a"}'
+        values: "4503599627370495x30"
+      # b agrees until 10m, then serves something else at the same revision
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "4503599627370495x9 4503599627370494x20"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "100x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x30"
+    alert_rule_test:
+      - eval_time: 9m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+      # diverged at 10m; pending for 3m
+      - eval_time: 12m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+      - eval_time: 13m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts:
+          - exp_labels:
+              alertname: AetherRegistrarSnapshotDiverged
+              severity: warning
+              component: aether-registrar
+              job: aether-registrar
+              revision: "100"
+            exp_annotations:
+              summary: "registrar replicas serve 2 different endpoint sets at store revision 100"
+              description: >-
+                Registrar replicas report the same aether_registrar_snapshot_revision
+                (100) with different values of
+                aether_registrar_snapshot_content_hash (or, on an image before
+                aether#1329, different content_hash labels on
+                aether_registrar_snapshot_content), and no write-behind intent is
+                pending. The listing is a pure function of the revision, so at least
+                one replica is not serving what the store holds, and the agents
+                watching it program different endpoints from the rest of the fleet.
+                Compare `aether_registrar_snapshot_content_hash` per replica, then the
+                registrar logs for sync errors and
+                `aether_registrar_sync_errors_total`. Restarting the odd replica
+                makes it list again, but keep its logs first: this is a bug, see
+                docs/runbook.md, "Stored vs in place vs applied".
+
+  # Both arms see the same divergence (new image: both metrics). `or` must leave ONE
+  # alert, not two.
+  - interval: 1m
+    name: (both metrics) one divergence is one alert
+    input_series:
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-a"}'
+        values: "111x30"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "111x9 222x20"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="aaaa"}'
+        values: "1x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="aaaa"}'
+        values: "1x9 _x20"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="bbbb"}'
+        values: "_x10 1x20"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "100x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x30"
+    alert_rule_test:
+      - eval_time: 12m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+      - eval_time: 13m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts:
+          - exp_labels:
+              alertname: AetherRegistrarSnapshotDiverged
+              severity: warning
+              component: aether-registrar
+              job: aether-registrar
+              revision: "100"
+            exp_annotations:
+              summary: "registrar replicas serve 2 different endpoint sets at store revision 100"
+              description: >-
+                Registrar replicas report the same aether_registrar_snapshot_revision
+                (100) with different values of
+                aether_registrar_snapshot_content_hash (or, on an image before
+                aether#1329, different content_hash labels on
+                aether_registrar_snapshot_content), and no write-behind intent is
+                pending. The listing is a pure function of the revision, so at least
+                one replica is not serving what the store holds, and the agents
+                watching it program different endpoints from the rest of the fleet.
+                Compare `aether_registrar_snapshot_content_hash` per replica, then the
+                registrar logs for sync errors and
+                `aether_registrar_sync_errors_total`. Restarting the odd replica
+                makes it list again, but keep its logs first: this is a bug, see
+                docs/runbook.md, "Stored vs in place vs applied".
+
+  # Both replicas move from revision 100 to 101 and to a new hash in the same minute.
+  # With the hash as a value there is no second series: quiet at every step, with no
+  # staleness handling. (The labelled series of the same image are here too, stale
+  # inside the lookback, so arm 2 is exercised against the same change.)
+  - interval: 1m
+    name: (value gauge) a content change on both replicas is quiet at every step
+    input_series:
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-a"}'
+        values: "111x9 222x30"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "111x9 222x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="aaaa"}'
+        values: "1x9 _x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="bbbb"}'
+        values: "_x10 1x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="aaaa"}'
+        values: "1x9 _x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="bbbb"}'
+        values: "_x10 1x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "100x9 101x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x9 101x30"
+    promql_expr_test:
+      # arm 1 alone, the plain count, at the step of the change and through the lookback
+      - eval_time: 10m
+        expr: &arm1 |
+          count by (job, revision) (
+            count_values by (job, revision) (
+              "hash",
+              aether_registrar_snapshot_content_hash
+              * ignoring (revision) group_left (revision)
+              count_values without () ("revision", aether_registrar_snapshot_revision)
+            )
+          )
+        exp_samples:
+          - labels: '{job="aether-registrar",revision="101"}'
+            value: 1
+      - eval_time: 12m
+        expr: *arm1
+        exp_samples:
+          - labels: '{job="aether-registrar",revision="101"}'
+            value: 1
+      - eval_time: 9m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      - eval_time: 10m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      - eval_time: 11m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      - eval_time: 13m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      - eval_time: 15m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      - eval_time: 16m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+    alert_rule_test:
+      - eval_time: 30m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+
+  - interval: 1m
+    name: (value gauge) a replica lagging one revision, and a pending write-behind intent, are both quiet
+    input_series:
+      # 0-20m: b lags a revision (different revision, different hash: not compared).
+      # 20m on: same revision, different hash, but b has a write-behind intent pending.
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-a"}'
+        values: "222x40"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "111x19 333x20"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "101x40"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x19 101x20"
+      - series: 'aether_registrar_writebehind_queue_depth{job="aether-registrar",node="registrar-b"}'
+        values: "0x19 1x20"
+    promql_expr_test:
+      - eval_time: 15m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      # the hashes do differ at revision 101 here; only the pending intent keeps it quiet
+      - eval_time: 35m
+        expr: *arm1
+        exp_samples:
+          - labels: '{job="aether-registrar",revision="101"}'
+            value: 2
+      - eval_time: 35m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+    alert_rule_test:
+      - eval_time: 15m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+      - eval_time: 35m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+
+  # MID-ROLL: registrar-a is on the old image (labelled metric only), registrar-b on
+  # the new one (both). Arm 1 sees one replica and cannot compare; the first
+  # promql_expr_test pins that blindness, which is the reason arm 2 is still here.
+  # They agree until 10m, then b serves something else at the same revision.
+  - interval: 1m
+    name: (mid-roll) an old-image replica and a new-image replica that diverge still alert
+    input_series:
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="aaaa"}'
+        values: "1x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="aaaa"}'
+        values: "1x9 _x20"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="bbbb"}'
+        values: "_x10 1x20"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "111x9 222x20"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "100x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x30"
+    promql_expr_test:
+      - eval_time: 20m
+        expr: *arm1
+        exp_samples:
+          - labels: '{job="aether-registrar",revision="100"}'
+            value: 1
+    alert_rule_test:
+      - eval_time: 9m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+      - eval_time: 12m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+      - eval_time: 13m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts:
+          - exp_labels:
+              alertname: AetherRegistrarSnapshotDiverged
+              severity: warning
+              component: aether-registrar
+              job: aether-registrar
+              revision: "100"
+            exp_annotations:
+              summary: "registrar replicas serve 2 different endpoint sets at store revision 100"
+              description: >-
+                Registrar replicas report the same aether_registrar_snapshot_revision
+                (100) with different values of
+                aether_registrar_snapshot_content_hash (or, on an image before
+                aether#1329, different content_hash labels on
+                aether_registrar_snapshot_content), and no write-behind intent is
+                pending. The listing is a pure function of the revision, so at least
+                one replica is not serving what the store holds, and the agents
+                watching it program different endpoints from the rest of the fleet.
+                Compare `aether_registrar_snapshot_content_hash` per replica, then the
+                registrar logs for sync errors and
+                `aether_registrar_sync_errors_total`. Restarting the odd replica
+                makes it list again, but keep its logs first: this is a bug, see
+                docs/runbook.md, "Stored vs in place vs applied".
+
+  # Mid-roll with nothing wrong: the same two images agreeing, through a content
+  # change, must not alert.
+  - interval: 1m
+    name: (mid-roll) an old-image replica and a new-image replica that agree are quiet
+    input_series:
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="aaaa"}'
+        values: "1x9 _x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-a",content_hash="bbbb"}'
+        values: "_x10 1x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="aaaa"}'
+        values: "1x9 _x30"
+      - series: 'aether_registrar_snapshot_content{job="aether-registrar",node="registrar-b",content_hash="bbbb"}'
+        values: "_x10 1x30"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "111x9 222x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-a"}'
+        values: "100x9 101x30"
+      - series: 'aether_registrar_snapshot_revision{job="aether-registrar",node="registrar-b"}'
+        values: "100x9 101x30"
+    promql_expr_test:
+      - eval_time: 10m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+      - eval_time: 13m
+        expr: ALERTS{alertname="AetherRegistrarSnapshotDiverged"}
+        exp_samples: []
+    alert_rule_test:
+      - eval_time: 30m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+
+  # kubernetes backend: the value gauge is exported, no revision is. Different hashes
+  # there are not a finding (health derives from each replica's clock).
+  - interval: 1m
+    name: (value gauge) replicas that report no revision are never compared
+    input_series:
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-a"}'
+        values: "111x30"
+      - series: 'aether_registrar_snapshot_content_hash{job="aether-registrar",node="registrar-b"}'
+        values: "222x30"
+    alert_rule_test:
+      - eval_time: 20m
+        alertname: AetherRegistrarSnapshotDiverged
+        exp_alerts: []
+
+
   # ---------------------------------------------------------------------------
   # AetherContainerRestarted (kube-state-metrics, aether#1242).
   #   agent      aether-system, restarts 0 -> 1 at 10m, OOMKilled / 137 -> alert, reason
diff --git a/clusters/talos-main/prometheus/values.yaml b/clusters/talos-main/prometheus/values.yaml
index 26c00cd..dd18e19 100644
--- a/clusters/talos-main/prometheus/values.yaml
+++ b/clusters/talos-main/prometheus/values.yaml
@@ -987,49 +987,50 @@ serverFiles:
                 `failure_mode_allowed` means requests were let through WITHOUT an
                 authorization decision. Slack only: today the only ext_authz traffic is
                 the test canary.
-      # REGISTRAR SNAPSHOT IDENTITY (aether#1193, aether#1322). Source of truth:
-      # bpalermo/aether docs/observability/registrar-alerts.yml -- keep the two in sync.
+      # REGISTRAR SNAPSHOT IDENTITY (aether#1193, aether#1322, aether#1329). Source of
+      # truth: bpalermo/aether docs/observability/registrar-alerts.yml (the first arm)
+      # and docs/runbook.md, "Stored vs in place vs applied" (this two-arm form).
       - name: aether-registrar
         rules:
-          # THE OBVIOUS EXPRESSION IS WRONG (#1322):
-          #     count(count by (content_hash) (aether_registrar_snapshot_content)) > 1
-          #       and on() (max(aether_registrar_snapshot_revision)
-          #                 == min(aether_registrar_snapshot_revision))
-          #       and on() (max(aether_registrar_writebehind_queue_depth) == 0)
-          # It has two faults.
+          # Two replicas at ONE store revision must serve the same endpoint set.
           #
-          # 1. It false-positives on every content change. The hash is a LABEL, so a
-          #    change ends one series and starts another. The registrar stops
-          #    exporting the old one, but OTLP has no staleness marker, so Prometheus
-          #    keeps answering instant queries with the old series' last sample for
-          #    its 5-minute lookback. For those 5 minutes each replica shows two
-          #    hashes. On an 8 h soak with no divergence this read true in 108 of
-          #    1,920 samples.
-          # 2. It can never fire on a registrar that has not queued a write-behind
-          #    op. aether_registrar_writebehind_queue_depth is recorded when an op is
-          #    queued or flushed, so until the first one the series does not exist,
-          #    `max()` of nothing is empty, and `and on()` with an empty side is empty.
+          # ARM 1 (aether#1329): aether_registrar_snapshot_content_hash carries the hash
+          # as its VALUE (the first 13 hex digits = 52 bits of the content hash, exact
+          # in a float64). One series per replica and no label that changes, so a
+          # content change moves the value and nothing lingers in the lookback.
+          #   count_values without () ("revision", revision)
+          #     each replica's revision as a label; `without ()` keeps every label, so
+          #     this does not depend on the replica label's name (`node` here).
+          #   content_hash * ignoring (revision) group_left (revision) ...
+          #     the replica's hash, labelled with its revision.
+          #   count by (job, revision) (count_values by (job, revision) ("hash", ...)) > 1
+          #     more than one distinct hash at one revision. A lagging replica is at
+          #     another revision and is not compared.
+          # It matches the two metrics on labels, not timestamps. The registrar reads
+          # both from one snapshot state per collection, and they arrive in one OTLP
+          # request; if they ever arrived apart, one evaluation could pair a new
+          # revision with the old hash, which `for:` covers.
           #
-          # What this expression does instead, inside out:
+          # ARM 2 (aether#1322/#1328), TRANSITIONAL: the same check on the deprecated
+          # aether_registrar_snapshot_content{content_hash}. The hash is a LABEL there,
+          # a superseded series stays in the 5m lookback (OTLP has no staleness
+          # marker), so it keeps, per replica, only the series with the newest
+          # timestamp(). It is here because arm 1 cannot see a replica whose image
+          # predates aether#1329: before the registrar is upgraded arm 1 is empty, and
+          # mid-roll it compares only the new replicas. Every image, old or new, exports
+          # the labelled metric, so arm 2 covers all of them. Both arms return
+          # {job, revision}; `or` keeps one alert per divergence.
+          # REMOVE ARM 2 once every registrar replica exports the value gauge --
+          #   count(aether_registrar_snapshot_content_hash) == count(aether_registrar_snapshot_revision)
+          # -- and BEFORE taking the aether release that drops the labelled metric (the
+          # release after the one that added the gauge). Left in place after that it is
+          # merely empty.
           #
-          #   timestamp(content) == max without (content_hash) (timestamp(content))
-          #     keeps, per replica, only the content series whose sample is the
-          #     NEWEST. A superseded hash is still inside the lookback, but its last
-          #     sample is older than the current hash's, so it drops out. A replica
-          #     is "every label except content_hash", so this does not depend on what
-          #     the pipeline calls the replica label (`node` on talos-main).
-          #   revision * ... group_right
-          #     gives that one series per replica the replica's revision as its value.
-          #   count_values by (job, content_hash) ("revision", ...)
-          #     turns the revision into a label: one series per (revision, hash).
-          #   count by (job, revision) (...) > 1
-          #     more than one hash at ONE revision. A replica that lags a revision is
-          #     at a different revision and is not compared.
-          #   unless ... queue_depth > 0
-          #     a pending write-behind intent is overlaid on the listing (version
-          #     `<rev>+<hash>`), so that replica is legitimately ahead of its
-          #     revision. `unless ... > 0` is quiet only when a depth above zero is
-          #     actually reported, so a missing series does not disable the rule.
+          # unless ... queue_depth > 0: a pending write-behind intent is overlaid on the
+          # listing (version `<rev>+<hash>`), so that replica is legitimately ahead of
+          # its revision. The series exists only once something was queued; `unless`
+          # is quiet only when a depth above zero is actually reported, so a missing
+          # series does not disable the rule.
           #
           # for: 3m. An agent RPC applied between two syncs changes a replica's
           # contents before its revision moves (at most the 200 ms sync debounce), and
@@ -1040,22 +1041,33 @@ serverFiles:
           # expression returns nothing there.
           - alert: AetherRegistrarSnapshotDiverged
             expr: |
-              count by (job, revision) (
-                count_values by (job, content_hash) (
-                  "revision",
-                  aether_registrar_snapshot_revision
-                  * ignoring (content_hash) group_right ()
-                  (
-                    aether_registrar_snapshot_content
-                    and
+              (
+                count by (job, revision) (
+                  count_values by (job, revision) (
+                    "hash",
+                    aether_registrar_snapshot_content_hash
+                    * ignoring (revision) group_left (revision)
+                    count_values without () ("revision", aether_registrar_snapshot_revision)
+                  )
+                ) > 1
+                or
+                count by (job, revision) (
+                  count_values by (job, content_hash) (
+                    "revision",
+                    aether_registrar_snapshot_revision
+                    * ignoring (content_hash) group_right ()
                     (
-                      timestamp(aether_registrar_snapshot_content)
-                      == ignoring (content_hash) group_left ()
-                      max without (content_hash) (timestamp(aether_registrar_snapshot_content))
+                      aether_registrar_snapshot_content
+                      and
+                      (
+                        timestamp(aether_registrar_snapshot_content)
+                        == ignoring (content_hash) group_left ()
+                        max without (content_hash) (timestamp(aether_registrar_snapshot_content))
+                      )
                     )
                   )
-                )
-              ) > 1
+                ) > 1
+              )
               unless on (job) (max by (job) (aether_registrar_writebehind_queue_depth) > 0)
             for: 3m
             labels:
@@ -1065,12 +1077,14 @@ serverFiles:
               summary: "registrar replicas serve {{ $value }} different endpoint sets at store revision {{ $labels.revision }}"
               description: >-
                 Registrar replicas report the same aether_registrar_snapshot_revision
-                ({{ $labels.revision }}) with different content_hash labels on
-                aether_registrar_snapshot_content, and no write-behind intent is
+                ({{ $labels.revision }}) with different values of
+                aether_registrar_snapshot_content_hash (or, on an image before
+                aether#1329, different content_hash labels on
+                aether_registrar_snapshot_content), and no write-behind intent is
                 pending. The listing is a pure function of the revision, so at least
                 one replica is not serving what the store holds, and the agents
                 watching it program different endpoints from the rest of the fleet.
-                Compare `aether_registrar_snapshot_content` per replica, then the
+                Compare `aether_registrar_snapshot_content_hash` per replica, then the
                 registrar logs for sync errors and
                 `aether_registrar_sync_errors_total`. Restarting the odd replica
                 makes it list again, but keep its logs first: this is a bug, see

Proof (this repo)

  • bazel test //registrar/internal/server:all //common/snapshotversion:all //registry/... --test_arg=-test.short: 7/7 pass
  • bazel test --config=race //registrar/internal/server:server_test //common/snapshotversion:snapshotversion_test: 2/2 pass
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean
  • make format-check: clean; make gazelle: no change
  • promtool check rules docs/observability/registrar-alerts.yml (3.6.0): 1 rule, SUCCESS. The plain rule also passed a scratch promtool test (agree, adjacent values diverge, both change, lag, pending intent, no revision); that test is not in this repo, which has no promtool in its build.

New unit tests: truncation and rejection cases for ContentHashValue, float64 round trip at the top of the range, the same value from all three version forms, one label-free series whose value follows the contents, equal values on two replicas for equal contents reached by different paths, different values for different contents at one revision, the dirty form, and the kubernetes (hash:) case.

No chart change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…1329)

aether.registrar.snapshot.content carries the hash as a label. A content
change ends one series and starts another, OTLP has no staleness marker for
a series an observable gauge stopped reporting, and Prometheus keeps
returning the superseded hash for its 5-minute lookback. #1328 worked
around that in the divergence rule with a timestamp() filter.

Add aether.registrar.snapshot.content_hash, whose VALUE is the hash: the
first 13 hex digits (52 bits) of the content hash, an integer a float64
holds exactly. One series per replica, no label that changes. The
conversion lives in common/snapshotversion (ContentHashValue) next to the
version parser. The gauge is observed in the same callback, from the same
Snapshot.State(), as the revision gauges, on every backend and in every
version form.

The labelled metric is deprecated and kept for one release so a rule on it
keeps working while replicas of both images run.

docs: AetherRegistrarSnapshotDiverged is now a plain count of distinct
values per (job, revision); the runbook has the by-hand query, the bit
budget, how the two metrics arrive, and the two-arm rule for the upgrade.

Closes #1329

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Copilot AI balanced review requested due to automatic review settings October 7, 2026 17:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues remain in the implementation, regression coverage, or migration guidance.

0 open findings

What changed in this PR

Addresses #1329 by exporting snapshot hashes as gauge values, avoiding stale hash-label series in Prometheus divergence checks.

Changes:

  • Adds an exact 52-bit hash conversion and observes it alongside snapshot revisions.
  • Adds conversion and metric regression tests.
  • Simplifies the divergence rule and documents migration while retaining the old metric for one release.
File Description
registrar/​internal/​server/​metrics.go Exports the new gauge and deprecates the labelled metric.
registrar/​internal/​server/​metrics_test.go Tests gauge updates, replica agreement, and backend variants.
docs/​runbook.md Documents queries and rolling-upgrade steps.
docs/​observability/​registrar-alerts.yml Switches divergence detection to gauge values.
docs/​observability/​README.md Explains the metric and migration.
common/​snapshotversion/​snapshotversion.go Adds the 52-bit hash conversion.
common/​snapshotversion/​snapshotversion_test.go Tests conversion, precision, and version forms.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation, tests, alert expression, and migration guidance are consistent, with no unresolved blocking findings.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 7, 2026 17:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The retained feedback is a minor rollout-documentation correction, with no blocking implementation issues identified.

1 open finding

🧠 Review effort: Balanced

Comment thread docs/runbook.md
Comment on lines +3576 to +3577
`count(aether_registrar_snapshot_content_hash) == count(aether_registrar_snapshot_revision)`
(every replica that reports a revision reports the value gauge).
Copilot AI balanced review requested due to automatic review settings October 7, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

External alert-rule validation and the coordinated cross-repository rollout still require human confirmation.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 7, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The migration coverage check can pass while older replicas remain uncovered, permitting premature removal of transitional detection.

1 open finding

🧠 Review effort: Balanced

@bpalermo
bpalermo merged commit b213215 into main Oct 7, 2026
31 checks passed
@bpalermo
bpalermo deleted the registrar-content-hash-gauge-1329 branch October 7, 2026 18:29
bpalermo added a commit that referenced this pull request Oct 11, 2026
…auge is removed (#1667)

The labelled info gauge aether.registrar.snapshot.content{content_hash}
(Prometheus aether_registrar_snapshot_content) was deprecated in chart 2.4.12
(#1329, #1346) in favour of aether.registrar.snapshot.content_hash, which
carries the hash as its value and is what the shipped rule
AetherRegistrarSnapshotDiverged reads. Deprecated in 2.4.x means removable from
2.5.0 on; the "chart 2.6.0 at the earliest" written beside it by #1658 was one
minor too cautious and is corrected here.

- registrar: the instrument, its content_hash attribute key and the helper
  that observed both gauges are gone; the value gauge and the revision gauges
  are untouched. A test asserts the exported metric set does not contain the
  name, and that no gauge data point carries a content_hash attribute.
- docs: the runbook's transitional `or` arm and its order of work, the
  "Deprecated" sections of the runbook and docs/observability/README.md, and
  the upgrade comment in registrar-alerts.yml are replaced by a short account
  in the past tense. The shipped rule and its promtool tests never read the
  metric and are unchanged.
- chart 2.5.9: a runbook section says what an operator sees (a rule or a
  dashboard still reading the metric returns no data, silently), the query to
  use instead, and closes the row of the "Chart 2.5.7" deprecation table.

The upgrade rolls the registrar Deployment (new image); no template changed.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

registrar: export the snapshot content hash as a gauge VALUE so a superseded hash cannot linger in Prometheus

2 participants