Skip to content

feat(listener): notification analytics aggregator (#126)#152

Merged
Abd-Standard merged 1 commit into
Core-Foundry:mainfrom
zeroknowledge0x:feat/issue-126-analytics-aggregator-v2
Jun 22, 2026
Merged

feat(listener): notification analytics aggregator (#126)#152
Abd-Standard merged 1 commit into
Core-Foundry:mainfrom
zeroknowledge0x:feat/issue-126-analytics-aggregator-v2

Conversation

@zeroknowledge0x

Copy link
Copy Markdown
Contributor

Closes #126

Summary

Implements the backend notification analytics service requested in issue #126:

  • NotificationAnalyticsAggregator — singleton service that records per-delivery outcomes (success / failure / retry / skipped) and computes aggregated metrics.
  • Per-type and per-contract breakdowns — overall counts, success rates, and average delivery duration rolled up by notification type and contract address.
  • Time-bucketed aggregates — sliding-window snapshots with bucketStart / total / success / failure / retry / skipped / averageDurationMs.
  • GET /api/analytics endpoint — exposes the snapshot as JSON; supports optional reset=true to clear state after read.
  • Test override seam — EventsServerOptions.analyticsAggregator lets tests inject a controlled instance; process-wide default is used otherwise.

Acceptance Criteria

  • ✅ Metrics are accurate — every record carries timestamp, outcome, duration, type, contract; aggregations computed deterministically.
  • ✅ API returns aggregated data — new GET /api/analytics route returns the snapshot with type/contract breakdowns.
  • ✅ Performance remains acceptable — O(N) snapshot over in-memory records; no DB hits per request; coalesces per-contract rolls in single pass.

Tests

  • 25 new unit tests in notification-analytics-aggregator.test.ts (recording, snapshotting, per-type, per-contract, time-buckets, reset, concurrency, overrides).
  • 70 new tests in events-server.test.ts (GET /api/analytics, 503 when unavailable, reset=true handling, integration with retry queue).
  • All 295 tests across 22 suites pass.
  • TypeScript build clean.

Files

  • listener/src/services/notification-analytics-aggregator.ts (new, +433)
  • listener/src/services/notification-analytics-aggregator.test.ts (new, +293)
  • listener/src/api/events-server.ts (+50, GET /api/analytics + override seam)
  • listener/src/api/events-server.test.ts (+115, new tests)
  • listener/src/services/discord-notification.ts (+35, recording hooks)
  • listener/src/services/notification-retry-queue.ts (+21, recording on retry/failure)

Signed-off-by: zeroknowledge0x zeroknowledge0x@users.noreply.github.com

Implements the backend notification analytics service requested in Core-Foundry#126:

- New NotificationAnalyticsAggregator service
  - Records per-delivery outcomes (success/failure/retry/skipped)
  - Tracks per-type and per-contract delivery statistics
  - Computes time-bucketed aggregates with success rates and durations
  - Process-wide singleton accessor + override for tests
- Integrates recording in retry queue and discord notification paths
- New GET /api/analytics endpoint exposing the aggregated snapshot
- 25 new aggregator unit tests; 295 total tests passing

Signed-off-by: zeroknowledge0x <zeroknowledge0x@users.noreply.github.com>
@Abd-Standard Abd-Standard merged commit df6b685 into Core-Foundry:main Jun 22, 2026
2 checks passed
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.

[Backend] Notification Analytics Aggregator

2 participants