Skip to content

fix(grafana): $chain var empty in replay, profit panel renders $0 (closes #424)#425

Merged
obchain merged 1 commit intomainfrom
fix/grafana-chain-var-empty-replay
May 4, 2026
Merged

fix(grafana): $chain var empty in replay, profit panel renders $0 (closes #424)#425
obchain merged 1 commit intomainfrom
fix/grafana-chain-var-empty-replay

Conversation

@obchain
Copy link
Copy Markdown
Owner

@obchain obchain commented May 4, 2026

Summary

  • Source \$chain template variable from charon_scanner_positions instead of charon_listener_blocks_received_total.
  • Listener counter only emits in listen mode; scanner gauge emits in both listen and replay.
  • Without this fix, the predicted-profit stat panel renders $0 in replay-mode demos even when the underlying metric is correct.

Closes #424.

Why this fix

Validated against a live replay against block 91323624 today:

charon_executor_profit_usd_cents_sum{chain="bnb"} 3952448   # = $39,524.48

But the Grafana panel showed $0. Root cause was the empty \$chain variable making chain=~"" match nothing. Switching the source resolves it. See the linked issue for full diagnosis + reproduction.

Test plan

  • Reviewer agent confirmed charon_scanner_positions is a registered gauge with chain label, set unconditionally on every scanner tick (crates/charon-cli/src/main.rs:1958, 1998, 2026).
  • Confirmed all 13 \$chain consumers in deploy/grafana/charon.json filter against metrics that carry the same chain="bnb" label.
  • Live re-test: panel populates at $39 524.48 with --hold-secs 1800.
  • CI: grafana-lint.yml workflow passes.
  • Post-merge: fresh clone + docker compose -f local-stack.yml up -d + replay-with-hold → panel populates without manual datasource hacks.

Files

  • deploy/grafana/charon.json — 1 hunk, 3 insertions, 3 deletions.

#424)

`charon_listener_blocks_received_total` only emits when the listener
subcommand runs in `listen` mode. In `replay` mode, the metric is
empty so `label_values()` returns nothing, leaving the `$chain`
template variable empty. Every panel that filters `chain=~"$chain"`
then renders $0 / empty, including the predicted-profit stat panel
(line 226) which during today's demo showed $0 even though the
underlying metric `charon_executor_profit_usd_cents_sum{chain="bnb"}`
correctly reported 3952448 (= $39,524.48).

Switch the variable source to `charon_scanner_positions`, a gauge
emitted unconditionally on every scanner tick (set in three branches
of charon-cli/src/main.rs: empty scan set, fetch_positions failure,
and normal path). Replay invokes the same run_block_pipeline that
emits these gauges, so `chain="bnb"` is always present on first
scrape.

Verified against a live replay: profit panel populates at
$39,524.48 once `--hold-secs 1800` keeps the exporter alive for
Prometheus to scrape.
@obchain obchain merged commit efe4a95 into main May 4, 2026
4 checks passed
@obchain obchain deleted the fix/grafana-chain-var-empty-replay branch May 4, 2026 07:28
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.

fix(grafana): $chain template variable empty in replay mode, profit panel renders $0

1 participant