Feat: Add backend observability for contract event schema drifts#32
Open
estyemma wants to merge 2 commits into
Open
Feat: Add backend observability for contract event schema drifts#32estyemma wants to merge 2 commits into
estyemma wants to merge 2 commits into
Conversation
Contributor
|
@estyemma |
Author
@MaryammAli pls check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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