Skip to content

Commit d544f76

Browse files
authored
feat(interchain-indexer): Stats zero-count chain visibility setting (#1662)
* Added `StatsSettings`. Introducing `include_zero_chains`. * Added ENV validation step into the implementation-plan workflow * Update memory bank * Code review issues * Fix issues
1 parent 9d40969 commit d544f76

20 files changed

Lines changed: 1856 additions & 729 deletions

File tree

interchain-indexer/.memory-bank/research/config-loading-and-validation.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ Settings (deny_unknown_fields)
7171
├─ jaeger: JaegerSettings
7272
├─ database: DatabaseSettings
7373
├─ api: ApiSettings (deny_unknown_fields)
74-
├─ stats_backfill_on_start: bool
75-
└─ stats_chains_recalculation_period_secs: u64
74+
└─ stats: StatsSettings (deny_unknown_fields)
75+
├─ backfill_on_start: bool
76+
├─ chains_recalculation_period_secs: u64
77+
└─ include_zero_chains: bool
7678
```
7779

7880
### JSON Config Structs

interchain-indexer/.memory-bank/research/stats-projection.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ increments `crosschain_messages.stats_processed` for the counted rows.
108108

109109
There is also a startup backfill path for historical rows:
110110

111-
- when `stats_backfill_on_start = true`, server startup triggers a stats
112-
backfill pass
111+
- when `stats.backfill_on_start = true` (env:
112+
`INTERCHAIN_INDEXER__STATS__BACKFILL_ON_START=true`), server startup triggers
113+
a stats backfill pass
113114
- the backfill scans canonical rows with `stats_processed = 0`
114115
- it applies the same projection logic in batches until no eligible rows remain
115116

interchain-indexer/.memory-bank/research/stats-subsystem.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ For detailed message-projection semantics, see `stats-projection.md`.
213213

214214
### 3. Startup backfill reuses the same projection rules
215215

216-
When `stats_backfill_on_start = true`, startup calls
216+
When `stats.backfill_on_start = true` (env:
217+
`INTERCHAIN_INDEXER__STATS__BACKFILL_ON_START=true`), startup calls
217218
`backfill_stats_until_idle_with_token_enrichment()`.
218219

219220
That method repeatedly runs `backfill_stats_projection_round(...)` until no
@@ -402,6 +403,23 @@ Then:
402403
- left join from `chains` ensures known chains without a stats row can still be
403404
returned as `0`
404405

406+
Zero-chain visibility is service-wide and configurable:
407+
408+
- `stats.include_zero_chains` (env:
409+
`INTERCHAIN_INDEXER__STATS__INCLUDE_ZERO_CHAINS`), default `true`
410+
- when `true`: `/stats/chains` and message-path endpoints include known chains
411+
from `chains` even when the aggregated stats row is missing or zero
412+
- `/stats/chains` keeps its `chains LEFT JOIN stats_chains` shape
413+
- message-path endpoints drive the query from `chains` (excluding the
414+
selected chain) and left-join `stats_messages` / aggregated
415+
`stats_messages_days`
416+
- explicit `counterparty_chain_ids` still suppresses synthesized zero rows
417+
- when `false`: both families return only rows with positive aggregated stats
418+
- `/stats/chains` filters
419+
`COALESCE(sc.unique_transfer_users_count, 0) > 0 OR COALESCE(sc.unique_message_users_count, 0) > 0)`
420+
inside the ranked SQL, preserving keyset pagination
421+
- message-path endpoints keep their current stats-table-driven behavior
422+
405423
## Refresh and Recalculation Model
406424

407425
### Live request-time queries
@@ -456,16 +474,18 @@ Behavior:
456474

457475
Main knob:
458476

459-
- `INTERCHAIN_INDEXER__STATS_CHAINS_RECALCULATION_PERIOD_SECS`
477+
- `INTERCHAIN_INDEXER__STATS__CHAINS_RECALCULATION_PERIOD_SECS`
478+
(`stats.chains_recalculation_period_secs`)
460479
- default: `3600`
461480
- `0` disables periodic refresh
462481

463482
## Backfill Semantics
464483

465484
### What startup backfill does
466485

467-
`INTERCHAIN_INDEXER__STATS_BACKFILL_ON_START=true` triggers a startup catch-up
468-
pass that projects historical canonical rows whose stats were not yet built.
486+
`INTERCHAIN_INDEXER__STATS__BACKFILL_ON_START=true`
487+
(`stats.backfill_on_start = true`) triggers a startup catch-up pass that
488+
projects historical canonical rows whose stats were not yet built.
469489

470490
It is useful when:
471491

interchain-indexer/.memory-bank/workflows/implementation-plan.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Produce `implementation-plan-X.md` (X - source solution number) describing:
8888
- affected layers and their responsibilities
8989
- end-to-end data flow and control flow changes
9090
- persistence, API, config, and runtime implications
91+
- README / generated env documentation implications when ENV or config keys change
9192
- invariants that must remain true
9293
- main risks, edge cases, and failure handling expectations
9394
- validation strategy
@@ -109,6 +110,7 @@ Requirements:
109110
Prepare the implementation breakdown:
110111

111112
- exact files, modules, schemas, tests, and configs likely to change
113+
- `README.md` and generated env documentation impact when ENV or config surface changes
112114
- required migrations, backfills, or rollout ordering
113115
- dependencies between subtasks
114116
- validation commands and artifacts to update
@@ -139,6 +141,15 @@ Include:
139141
- known risks and watch-outs
140142
- any remaining blockers or questions
141143

144+
If the approved design adds, removes, renames, or changes ENVs or config keys, the coding handoff
145+
must explicitly require the implementation agent to:
146+
147+
- run `just check-envs`
148+
- if `just check-envs` fails, run `just generate-envs`
149+
- review any generated changes, especially in `README.md`
150+
- add or refine `README.md` descriptions for new or changed env fields when the generated output is
151+
missing or insufficiently descriptive
152+
142153
### 7. Decide the Outcome Status
143154

144155
End with one of these statuses inside both artifacts when relevant:
@@ -180,6 +191,14 @@ Verification guidance in both artifacts must follow the repo testing rules:
180191
- do not default to raw `cargo test` commands when a repo-native wrapper exists
181192
- only mention bare `cargo test` when no wrapper applies or when the command is specifically needed for a non-default case
182193

194+
When the planned change affects ENVs or config keys, verification guidance in `coding-task-X.md`
195+
must also include:
196+
197+
- `just check-envs`
198+
- `just generate-envs` as the required follow-up when `just check-envs` fails because generated env
199+
docs are out of sync
200+
- a final `README.md` review to ensure new or changed env fields are described clearly when needed
201+
183202
Use this structure:
184203

185204
### `implementation-plan-X.md`
@@ -279,3 +298,12 @@ Use this structure:
279298

280299
[ready for coding | blocked on clarification | blocked on additional codebase research | blocked on product or architectural decision]
281300
```
301+
302+
When ENV or config surface changes are in scope, extend the generated `coding-task-X.md` with:
303+
304+
- `README.md` in `Files And Components`
305+
- an ordered work item to run `just check-envs`, fall back to `just generate-envs` on failure, and
306+
review the resulting `README.md` diff
307+
- a verification entry for `just check-envs`
308+
- an acceptance criterion that the main `README.md` env documentation is updated for any new or
309+
changed fields when needed

0 commit comments

Comments
 (0)