Skip to content

fix(metrics): count nostr_events_total on successful DB write, not on ingress#225

Merged
hoytech merged 1 commit intohoytech:masterfrom
archief2910:fix/nostr_events_total-semantics
Apr 28, 2026
Merged

fix(metrics): count nostr_events_total on successful DB write, not on ingress#225
hoytech merged 1 commit intohoytech:masterfrom
archief2910:fix/nostr_events_total-semantics

Conversation

@archief2910
Copy link
Copy Markdown
Contributor

@archief2910 archief2910 commented Apr 23, 2026

Description

nostr_events_total{kind="…"} was incremented in ingesterProcessEvent immediately after parse/verify, before duplicate detection, write-policy plugin, and the writer pipeline. That counted every accepted parse toward kind totals, including events that never became EventWriteStatus::Written (duplicates, plugin rejects, replace/delete outcomes, etc.).

This PR:

  • Removes PROM_INC_EVENT_KIND from src/apps/relay/RelayIngester.cpp.
  • Adds PROM_INC_EVENT_KIND(std::to_string(packed.kind())) in src/apps/relay/RelayWriter.cpp only when newEvent.status == EventWriteStatus::Written, alongside writtenEventsTotal.inc().
  • Updates the Prometheus # HELP nostr_events_total text in src/PrometheusMetrics.h to state that the counter reflects events persisted to the DB, not raw client ingress.

Files: src/apps/relay/RelayIngester.cpp, src/apps/relay/RelayWriter.cpp, src/PrometheusMetrics.h

Motivation and context

Operators using Prometheus to reason about stored traffic and kind mix should not inflate totals with duplicates and write-path rejects. Counting at Written matches that intent.

Types of changes

  • Non-functional change
  • Bug fix
  • Breaking change
  • Breaking change

Checklist

  • HELP text updated
  • Build passes locally

@hoytech
Copy link
Copy Markdown
Owner

hoytech commented Apr 28, 2026

Technically a breaking change, but I doubt anyone is relying on this behaviour. And I agree it's more useful/accurate this way.

@hoytech hoytech merged commit 9f77ac8 into hoytech:master Apr 28, 2026
1 check 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.

2 participants