Skip to content

Detect stale latest closed_at in no_missing_ledgers - #256

Open
amishas157 wants to merge 7 commits into
masterfrom
extend-tests
Open

Detect stale latest closed_at in no_missing_ledgers#256
amishas157 wants to merge 7 commits into
masterfrom
extend-tests

Conversation

@amishas157

@amishas157 amishas157 commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The existing no_missing_ledgers singular test only finds gaps between existing rows, so a table that stops receiving data silently passes.
  • Adds a stale_latest CTE that fails when max(closed_at) is null (no rows in the 7-day lookback) or < batch_end_date (latest data hasn't caught up).
  • Unifies results into a failures CTE with a failure_reason column ('gap' or 'stale_latest') so the test output makes the cause obvious. Severity stays error for both.

Test plan

  • Trigger the airflow singular-test task on a batch where upstream data is current — expect 0 rows.
  • Manually run with a batch_end_date set ahead of max(closed_at) in one of the listed tables — expect a stale_latest row for that table.
  • Confirm existing gap-detection path still flags engineered sequence gaps (failure_reason = 'gap').
  • Confirm table_group_name / table_name var scoping still narrows both checks.

hunterpack and others added 4 commits May 13, 2026 11:31
* contract token updates

* changes for asset code

* update codes

* updates based on pr comments

* Lag batch_end_date by 1 hour in eho_by_ops singular test (#254)

* updates based on pr comments

* Fix stale comment about contract_id fallback

* fix joins in account balances contract model

* add test

---------

Co-authored-by: chowbao <simon.chow@stellar.org>
* accept batch start/end date and update test tag

* add: no_negative_circulating_supply singular test tagged validate_history_tables

Ports the circulating-supply check from datafold-monitors
(anomaly-detection/no_negative_circulating_supply.yaml.j2) into a
dbt singular test. References stg_token_transfers_raw, sums mint vs
burn events per contract, and fails when any non-allowlisted contract
has negative cumulative supply.

Tagged validate_history_tables so the new airflow gate selects it via
`dbt test --select tag:validate_history_tables`.

* add: singular tests for state, EHO, and token_transfer validation gates

Three new singular tests, each tagged with the matching airflow gate:

- state_tables_missing_ledger_sequence (validate_state_tables): detects
  missed export batches by flagging unexpectedly large gaps (>240
  ledgers, ~2x the 10-min export cadence) between consecutive distinct
  ledger_sequence values across 11 state staging tables.

- eho_row_count (validate_eho_tables): asserts strict count equality
  between enriched_history_operations and stg_history_operations within
  the batch window. Fast complement to eho_by_ops which finds the
  individual missing op_ids.

- token_transfers_no_negative_circulating_supply
  (validate_token_transfer_tables): mirrors the existing
  no_negative_circulating_supply test but reads from the token_transfers
  mart, catching any enrichment-introduced drift between raw events and
  the mart.

* refactor: parameterize ledger_sequence_increment singular test

Accept optional table_group_name and table_name vars so the check can target
all tables, a named group, or a single table. Retag as validate_no_missing_ledgers.

* add: populate table groups for ledger_sequence_increment test

Fill history_tables, state_tables, snapshot_tables, current_tables, and
fee_stats_tables so the parameterized test can be targeted by group.

* remove: state_tables_missing_ledger_sequence singular test

Superseded by the parameterized ledger_sequence_increment test, which can be
targeted at the state_tables group.

* remove stg_history_contract_events

* remove stg_history_effects model

* Move test to new file

* fix braces

* no pricing check with ledger sequence

* add test for no missing days in snapshot

* add new test

* snapshot run at day level

* Apply suggestion from @amishas157

* remove extranneous tests
The gap check only finds missing ledgers between existing rows, so a
table that stops receiving data silently passes. Add a stale_latest
check that fails when max(closed_at) is null or below batch_end_date,
and tag failures by reason in the test output.
@amishas157
amishas157 requested a review from a team as a code owner May 14, 2026 21:02
{% endif %}
)

, stale_latest as (

@amishas157 amishas157 May 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test ensures that data until batch_end_date(with 5 minutes lag threshold) is available in the table.
The downstream task checks for upstream tables.

Base automatically changed from release-v20260515 to master May 15, 2026 20:12
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.

4 participants