Skip to content

Feat: Add backend observability for contract event schema drifts#32

Open
estyemma wants to merge 2 commits into
BlockDash-Studios:mainfrom
estyemma:events
Open

Feat: Add backend observability for contract event schema drifts#32
estyemma wants to merge 2 commits into
BlockDash-Studios:mainfrom
estyemma:events

Conversation

@estyemma

Copy link
Copy Markdown

Closed: #30

What was implemented
New file: contract-event-drift.service.ts
The core drift detector. It maintains:

A rolling 5-minute window (10 × 30s buckets) with per-reason counters: unknown_event_name, schema_version_too_high, incompatible_schema_version, field_mismatch, topic_mismatch, parse_error
Cumulative totals since service start
A ring buffer of 20 recent drift events (field names only, no raw payload values — safe for logging)
detectFieldDrift() compares observed XDR map keys against the schema registry's payloadKeys and returns missing/extra fields
Alert logging at ERROR level when the rolling rejection rate exceeds 10% with ≥20 events in the window
Modified: soroban-event.parser.ts
Every rejection path now calls driftService.recordDrift(...) with structured context:

Unknown event names → unknown_event_name
Topic namespace mismatch for a known event → topic_mismatch
schema_version > MAX_SUPPORTED_SCHEMA_VERSION → schema_version_too_high
Version not in compatibleVersions → incompatible_schema_version
XDR field names extracted (no values) before parsing → field_mismatch if any payloadKeys are missing
Catch block → parse_error
Successful parse → driftService.recordProcessed()
Modified: metrics.service.ts
Five new Prometheus metrics:

contract_event_parser_rejections_total — labeled by reason, contract_id, event_name, schema_version
contract_event_unknown_names_total — labeled by contract_id (separate from parse errors, per acceptance criteria)
contract_event_field_mismatches_total — labeled by contract_id, event_name, schema_version
contract_event_parse_errors_total — labeled by contract_id
contract_event_rejection_rate gauge — rolling rate per contract_id, updated after each rejected event batch
New file: parser-health.dto.ts
Swagger-annotated DTOs for the health endpoint response.

Modified: soroban-indexer.controller.ts
New GET /indexer/parser-health endpoint returning the full ParserHealthSnapshot — window stats, totals, known event names, schema versions, and recent drift events.

Modified: ingestion.module.ts
ContractEventDriftService registered as a provider and exported
SorobanEventParser now uses a factory provider that wires both the onUnknownSchemaVersion callback (feeding Prometheus) and the ContractEventDriftService at bootstrap time
Both StellarIngestionService and SorobanEventIndexerService receive the shared parser and drift service via DI

@MaryammAli

Copy link
Copy Markdown
Contributor

@estyemma
run
npm run build and npm run test to fix errors

@estyemma

Copy link
Copy Markdown
Author

@estyemma run npm run build and npm run test to fix errors

@MaryammAli pls check

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.

Add backend observability for contract event schema drifts

3 participants