Durable Emitter - TTL budget metric#2239
Open
tarcisiozf wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors DurableEmitter queue-expiry pressure observability by replacing the “near expiry count” signal with a more direct “TTL budget” signal (time remaining before the oldest pending event reaches EventTTL). This flows through the observer interface, store implementations, and metric instruments.
Changes:
- Replaced
NearTTLCount/NearExpiryLead-based observation withTTLBudget(EventTTL - OldestPendingAge) inDurableQueueStatsandObserveDurableQueue. - Updated Postgres + in-memory observer implementations and the emitter metrics loop to use the new observer signature.
- Renamed/retyped the gauge from
durable_emitter.queue.near_ttl(int) todurable_emitter.queue.ttl_budget_seconds(float).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/durableemitter/store.go | Computes TTLBudget from the oldest pending event instead of querying a near-expiry count. |
| pkg/durableemitter/observable_store.go | Updates DurableQueueStats and DurableQueueObserver interface to use TTLBudget and removes nearExpiryLead. |
| pkg/durableemitter/durable_emitter.go | Removes near-expiry lead plumbing and updates metrics loop to call the new observer signature. |
| pkg/durableemitter/durable_emitter_test.go | Updates test in-memory store observer to compute TTLBudget. |
| pkg/durableemitter/durable_emitter_metrics.go | Introduces the durable_emitter.queue.ttl_budget_seconds gauge and records it from observed stats. |
Comments suppressed due to low confidence (1)
pkg/durableemitter/durable_emitter.go:788
- When PollInterval is unset/zero, metricsLoop currently defaults to polling every 500ms, but DurableEmitterMetricsConfig.PollInterval is documented as "Zero = 10s". This mismatch is likely to surprise callers and can significantly increase DB load due to ObserveDurableQueue being called 2x/sec by default. Consider aligning the implementation with the documented 10s default (or update the doc if 500ms is intended).
mc := d.cfg.Metrics
poll := mc.PollInterval
if poll <= 0 {
poll = 500 * time.Millisecond
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+231
to
235
| if m.queueTTLBudgetSec, err = meter.Float64Gauge( | ||
| "durable_emitter.queue.ttl_budget_seconds", | ||
| metric.WithUnit("s"), | ||
| metric.WithDescription("Seconds of TTL headroom for the oldest pending event (EventTTL - oldest age); low/negative → DLQ/expiry pressure. Alert engine decides what 'near' means"), | ||
| ); err != nil { |
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.
This pull request refactors how the durable emitter tracks and reports queue expiry pressure metrics. Instead of counting the number of events near expiry, it now measures the "TTL budget"—the remaining time before the oldest pending event expires. This simplifies the code and provides a more direct signal for alerting on dead-letter queue (DLQ) pressure.
Metrics and Observability Improvements:
NearTTLCountmetric (number of events near expiry) with a newTTLBudgetmetric, which tracks the remaining TTL headroom for the oldest pending event. This is now reported asqueue.ttl_budget_seconds.DurableQueueStatsstruct and theObserveDurableQueueinterface to remove thenearExpiryLeadparameter and field, and instead use the newTTLBudgetfield.PgDurableEventStore,MemDurableEventStore, and metric wrappers) to remove all logic related to "near expiry" windows and focus only on TTL budget calculation.