Conversation
🤖 GitHub commentsJust comment with:
|
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
This is a follow-up to #41002, the backlog issue opened to analyse timer/histogram handling in the statsd module. Could a maintainer please add:
On the backport scope: this is a bug fix, but I've described the effect under "Disruptive User Impact" above. On the conclusion in #39987 that this is expected behaviour: the |
|
|
||
| **`ttl`** | ||
| : It defines how long a metric will be reported after it was last recorded. Irrespective of the given ttl, metrics will be reported at least once. A ttl of zero means metrics will never expire. | ||
| : It defines how long a metric will be reported after it was last recorded. Irrespective of the given ttl, metrics will be reported at least once. A ttl of zero means metrics will never expire. It controls how long a metric is kept, not what it aggregates: every flush reports what was recorded since the previous one, and a timer or histogram that received no measurements is not reported for that flush. |
There was a problem hiding this comment.
Because our docs are cumulative for all 9.x version, we need to declare the earliest version in which the new behavior applies.
| : It defines how long a metric will be reported after it was last recorded. Irrespective of the given ttl, metrics will be reported at least once. A ttl of zero means metrics will never expire. It controls how long a metric is kept, not what it aggregates: every flush reports what was recorded since the previous one, and a timer or histogram that received no measurements is not reported for that flush. | |
| : It defines how long a metric will be reported after it was last recorded. Irrespective of the given ttl, metrics will be reported at least once. A ttl of zero means metrics will never expire. | |
| {applies_to}`stack: ga 9.6+` It controls how long a metric is kept, not what it aggregates: every flush reports what was recorded since the previous one, and a timer or histogram that received no measurements is not reported for that flush. |
So if this PR is backported to all active 9.x branches, then the tag would need to be:
{applies_to}`stack: ga 9.4+`
There was a problem hiding this comment.
Thanks for the clarification! I left the ga 9.6+ version you suggested because there still is a small but "Disruptive User Impact". If you think ga 9.4+ is more suitable, let me know. Also, fragment defines this PR as a "bug-fix", I can switch it to "breaking-change" if you'd prefer.
There was a problem hiding this comment.
Thanks, that will do for now. I'll leave it to the developer team to decide about the backport and release note labels.
The statsd server registry resets counters and sets after every flush, but timers (`ms`) and histograms (`h`) were never reset. Their `count` therefore grew monotonically and `min`, `max`, `mean`, `stddev` and the percentiles aggregated every measurement ever recorded, for as long as the metric kept being updated. The values only went back down once the metric went stale and was evicted by `ttl`, which makes the reported series impossible to interpret: a consumer cannot tell whether a document updates the previous one or starts a new window. Clear the histogram sample after each flush and track the timer count separately from the meter, which is monotonic and cannot be reset. The moving average rates (`1m_rate`, `5m_rate`, `15m_rate`, `mean_rate`) are deliberately left alone, they are defined over fixed time windows and are not tied to the flush interval. A timer or histogram that received no measurements during an interval is no longer reported for that interval, so that clearing the sample does not emit zeroed out `min`/`max`/`mean` values. The metric stays in the registry and is reported again as soon as new measurements arrive, or is dropped once it exceeds its `ttl`. Closes elastic#39987 Closes elastic#41002 Assisted-By: Claude Code
39692ce to
7badca5
Compare
|
This pull request doesn't have a |
Proposed commit message
[Metricbeat][statsd] Reset timer and histogram metrics on every flush
registry.getMetricresets counters and sets after every flush, but timers (ms) and histograms (h) were never reset. Theircountgrew monotonically andmin,max,mean,stddevand the percentiles aggregated every measurement ever recorded, dropping only once the metric went stale and was evicted byttl. The resulting series is uninterpretable: a consumer cannot tell a new window from an update from a stale re-report.metrics.Histogram:Clear()after snapshotting, which resets the count and theExpDecaySamplereservoir.*samplingTimer: the count came from the meter, which is monotonic and has noClear(), so the per-interval count is now tracked in the timer and reset with the sample. Sample rate extrapolation (@0.1) is preserved. The moving average rates (1m_rate,5m_rate,15m_rate,mean_rate) are deliberately left alone: they are defined over fixed time windows, not the flush interval.min/max/mean. It stays in the registry and is reported again as soon as new measurements arrive, or is dropped atttl.ttlcontrols how long a metric is reported after it was last recorded, not what a single document aggregates, and every other metric type in the module already aggregates one flush interval.Checklist
I have made corresponding change to the default configuration files(no configuration change)-race)./changelog/fragmentsDisruptive User Impact
msandhvalues change, so dashboards built on the old behaviour need adjusting:countnow describes a single flush interval. Charts that useddifferencesto undo the monotonic count should usesum/avgovercountinstead; that workaround was already unreliable, giving a negative step whenever a metric expired and no value at all for an isolated data point.ttlexpires. Anything counting documents sees fewer of them; anything averagingmin/meanstops being dragged down by stale repeats.Counters, gauges and sets are unchanged.
How to test this PR locally
TestTimerReset,TestTimerSampledResetandTestHistogramResetfail onmainwith the symptom from #39987.End to end: build metricbeat from this branch and from
main, run the configuration from #39987 (period: 10s, defaultttl), sendprocessing_item:3000|hevery 3s twenty times, then stay idle for 40s.statsd.processing_item.countper emitted document:main4, 7, 10are the values quoted in #39987, and documents 7 and 8 are stale repeats emitted after the traffic stopped. On this branch each document covers one period, the counts sum to 20 — exactly the packets sent, so the reset drops no measurements — and nothing is emitted during the idle window. (maintotals 19 because its first packet raced the UDP socket bind at startup; a harness artifact.)Related issues