Skip to content

feat(metrics): expose dropped messages count as the droppedMsgs Prometheus counter#317

Open
dmytro-landiak wants to merge 7 commits into
develop/2.4from
feat/dropped-msgs-prometheus-metric
Open

feat(metrics): expose dropped messages count as the droppedMsgs Prometheus counter#317
dmytro-landiak wants to merge 7 commits into
develop/2.4from
feat/dropped-msgs-prometheus-metric

Conversation

@dmytro-landiak
Copy link
Copy Markdown
Contributor

Pull Request description

Resolves #303.

Exposes the cumulative dropped-message count as a Micrometer counter droppedMsgs on the existing /actuator/prometheus endpoint, so operators can alert on message drops directly with Prometheus.

What changed

  • Added a dedicated TbMessageStatsReportClient#reportDroppedMsgs(int count) method.
  • TbMessageStatsReportClientImpl now injects MeterRegistry, registers a single Counter named droppedMsgs (no tags), and increments it on every dropped message. The counter is registered in @PostConstruct init() before the historical-data-report.enabled early-exit, so the metric is always present and scrapeable — even when historical persistence is disabled.
  • Migrated all 14 existing reportStats(DROPPED_MSGS[, n]) call sites (11 files) to reportDroppedMsgs(...). No call site uses the generic reportStats path for dropped messages anymore.

Backward compatibility

  • The existing in-memory AtomicLong → PostgreSQL historical pipeline is unchanged and still gated by historical-data-report.enabled, so existing historical droppedMsgs dashboards / time series are unaffected. No schema change, no new dependency.

Sample scrape (/actuator/prometheus):

# HELP droppedMsgs_total
# TYPE droppedMsgs_total counter
droppedMsgs_total 0.0

Documentation

  • The Prometheus / monitoring documentation should be updated to mention the new droppedMsgs_total counter exposed on /actuator/prometheus.

General checklist

  • You have reviewed the guidelines document.
  • Labels that classify your pull request have been added.
  • The milestone is specified and corresponds to fix version.
  • Description references specific issue ([Feature Request] Expose dropped messages count as a Prometheus metric #303).
  • Description contains human-readable scope of changes.
  • Description contains brief notes about what needs to be added to the documentation.
  • No merge conflicts, commented blocks of code, code formatting issues.
  • Changes are backward compatible or upgrade script is provided.

Front-End feature checklist

N/A — back-end only change (no front-end / UI changes).

  • Screenshots with affected component(s) are added. The best option is to provide 2 screens: before and after changes;
  • If you change the widget or other API, ensure it is backward-compatible or upgrade script is present.

Back-End feature checklist

  • Added corresponding unit and/or integration test(s). Provide written explanation in the PR description if you have failed to add tests. — 3 new unit tests in TbMessageStatsReportClientImplTest (basic increment, batched count, and counter-works-when-historical-reporting-disabled); BasicDownLinkProcessorImplTest verifications updated; full mvn -T 1C clean install is green, including the Spring-context RateLimitsIntegrationTestCase.
  • If new dependency was added: the dependency tree is checked for conflicts. — No new dependency added; Micrometer / micrometer-registry-prometheus were already on the classpath.

…s counter

Registers a Micrometer Counter named droppedMsgs (no tags) inside
TbMessageStatsReportClientImpl and exposes it through the existing
/actuator/prometheus endpoint. The counter is registered before the
historical-data-report.enabled early-exit so it works even when
historical persistence is disabled.

Adds the dedicated reportDroppedMsgs(int count) interface method;
call-site migration follows in subsequent commits.

Refs #303
…DroppedMsgs

Migrates 10 call sites (8 files) from reportStats(DROPPED_MSGS) to the
dedicated reportDroppedMsgs(1) method introduced in the previous commit.
Batched-count call sites (4 remaining) are migrated separately.

Refs #303
Migrates the remaining 4 call sites (4 files) that pass an explicit count
to reportStats(DROPPED_MSGS, n). No call sites now use the generic
reportStats path for DROPPED_MSGS.

Refs #303
Create the droppedMsgs counter via StatsFactory.createDefaultCounter instead of injecting MeterRegistry directly, matching the convention used by all other metrics in the broker.

Add a no-arg reportDroppedMsgs() alongside reportDroppedMsgs(int), mirroring the existing reportStats()/reportStats(key, count) pair, and migrate the single-drop call sites from reportDroppedMsgs(1) to reportDroppedMsgs().

Document on reportStats(...) that DROPPED_MSGS must be reported via reportDroppedMsgs to keep the Prometheus counter in sync. Update unit tests accordingly.
…respects stats.enabled

The droppedMsgs Prometheus counter was created directly through StatsFactory, which is always active, so it stayed exposed even when metrics were turned off via stats.enabled=false (STATS_ENABLED) - inconsistent with every other broker metric.

Move counter creation behind StatsManager#createDroppedMsgsCounter(): StatsManagerImpl registers the real counter, while StatsManagerStub (used when stats are disabled) returns a no-op counter that is never exposed on /actuator/prometheus. The historical PostgreSQL pipeline remains independently gated by historical-data-report.enabled.
…ction

Extract a DroppedMsgStats stats object (interface + Default + Stub) owned by StatsManager, mirroring DeviceProcessorStats/FlowControlStats and the rest of the stats package, instead of returning a bare DefaultCounter.

This removes the throwaway SimpleMeterRegistry no-op hack from StatsManagerStub (it now returns a real no-op StubDroppedMsgStats), lets the report client depend on the interface rather than a raw counter, and gives a clean extension point - including PE - for future dropped-message metrics without changing StatsManager's signature.
@dmytro-landiak dmytro-landiak added the WIP Work in progress label May 27, 2026
@dmytro-landiak dmytro-landiak added this to the 2.4.0 milestone May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant