Package com.aim2be.platform.outbox
Class OutboxMetricsBinder
java.lang.Object
com.aim2be.platform.outbox.OutboxMetricsBinder
Micrometer binder for the outbox metrics enumerated in
.planning/26-stage-b-outbox-parity.md §OQ-5:
im2be_outbox_pending_total— gauge of PENDING row count (polled fromOutboxRecordRepository.countByStatus(com.aim2be.platform.outbox.OutboxRecord.Status)).im2be_outbox_publish_latency_seconds— timer recorded by the publisher on each successful publish (hot or cold).im2be_outbox_backlog_age_seconds— gauge ofnow() - oldest_pending.created_at; published when at least one PENDING row exists, else reports zero.im2be_outbox_publish_failure_total— counter incremented on every failed hot or cold publish attempt.
Per-topic metrics are tagged (topic=<name>). Per-topic timers
and counters are created lazily and memoised so they appear in
/actuator/prometheus on demand.
No-op mode. When constructed with a null
MeterRegistry (Spring Boot Actuator absent in the consumer
service), all recording methods become no-ops and gauge registration is
skipped. This keeps the auto-configuration usable in non-observed
contexts (e.g. integration tests, minimal services) without forcing
Micrometer as a hard dependency on consumers.
-
Constructor Summary
ConstructorsConstructorDescriptionOutboxMetricsBinder(io.micrometer.core.instrument.MeterRegistry registry, OutboxRecordRepository repository) Constructs the binder. -
Method Summary
Modifier and TypeMethodDescriptionvoidrecordFailure(String topic) Increments theim2be_outbox_publish_failure_total{topic=...}counter.voidrecordPublishLatency(String topic, Duration duration) Records one publish latency observation under theim2be_outbox_publish_latency_seconds{topic=...}timer.
-
Constructor Details
-
OutboxMetricsBinder
public OutboxMetricsBinder(io.micrometer.core.instrument.MeterRegistry registry, OutboxRecordRepository repository) Constructs the binder. Whenregistryis non-null, immediately registers the two gauge metrics (pending_total+backlog_age_seconds); per-topic latency + failure metrics are lazy-registered on first use. Whenregistryisnullthe binder operates in no-op mode (see class Javadoc).- Parameters:
registry- Micrometer registry, ornullto disable metric recording entirelyrepository- JPA repository providing the gauge data sources; nevernull
-
-
Method Details
-
recordPublishLatency
Records one publish latency observation under theim2be_outbox_publish_latency_seconds{topic=...}timer. No-op when noMeterRegistryis wired (see class Javadoc).- Parameters:
topic- the topic the publish targetedduration- wall-clock duration of the publish
-
recordFailure
Increments theim2be_outbox_publish_failure_total{topic=...}counter. No-op when noMeterRegistryis wired (see class Javadoc).- Parameters:
topic- the topic whose publish failed
-