Skip to content

fix(prometheus_exporter sink): allow disabling metric expiration via flush_period_secs=0 - #26041

Open
valerypetrov wants to merge 4 commits into
vectordotdev:masterfrom
valerypetrov:fix/prometheus-exporter-disable-expiration
Open

fix(prometheus_exporter sink): allow disabling metric expiration via flush_period_secs=0#26041
valerypetrov wants to merge 4 commits into
vectordotdev:masterfrom
valerypetrov:fix/prometheus-exporter-disable-expiration

Conversation

@valerypetrov

@valerypetrov valerypetrov commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Closes #23519.

The prometheus_exporter sink expires a metric series once it hasn't been updated for flush_period_secs. For metrics with sparse or bursty updates — e.g. high-cardinality counters produced by log_to_metric with tags like pod/status/downstream_service — this causes a series to be expired and later re-added as if it were brand new. To Prometheus, this looks like a gap followed by a counter reset, even when flush_period_secs is configured very high (the reporter tried 1 hour). Any increase()/rate() query spanning that gap under-counts, which is exactly the discrepancy described in the issue versus a Loki-based count_over_time() reference query.

This mirrors a long-standing, maintainer-acknowledged feature request in #10424 ("decouple prometheus_exporter expiration from flush period" / disable expiration), which had a prior attempt in #10427 that went stale and was closed without merging.

  • flush_period_secs: 0 now disables metric expiration entirely instead of being rejected at config-build time. Metrics then persist for the lifetime of the sink.
  • MetricMetadata::has_expired treats a zero expiration window as "never expires".
  • The periodic expiration sweep in PrometheusExporter::run is skipped entirely when expiration is disabled, avoiding an unnecessary full map scan on every event.
  • build() emits a warn! when expiration is disabled, noting the unbounded memory growth risk if metric series cardinality is unbounded.
  • Doc comment on flush_period_secs updated to describe the 0 behavior.

@valerypetrov
valerypetrov requested a review from a team as a code owner August 5, 2026 22:09
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions github-actions Bot added the domain: sinks Anything related to the Vector's sinks label Aug 5, 2026
@valerypetrov
valerypetrov force-pushed the fix/prometheus-exporter-disable-expiration branch from 9633c14 to d3092df Compare August 5, 2026 22:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9633c14297

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sinks/prometheus/exporter.rs
@valerypetrov
valerypetrov requested a review from a team as a code owner August 5, 2026 22:16
@github-actions github-actions Bot added domain: external docs Anything related to Vector's external, public documentation docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. labels Aug 5, 2026
@valerypetrov

Copy link
Copy Markdown
Author

recheck

…flush_period_secs=0

Metrics in the prometheus_exporter sink are expired after flush_period_secs
of no updates. For metrics with sparse or bursty updates (e.g. high
cardinality counters produced by log_to_metric), this causes them to be
expired and later re-added as a "new" series, which appears to Prometheus
as a gap followed by a counter reset, even when flush_period_secs is
configured very high. This under-counts increase()/rate() queries that
span the gap.

Allow flush_period_secs to be set to 0 to disable expiration entirely, so
metrics persist for the lifetime of the sink instead of being evicted.

Fixes: vectordotdev#23519
…eriod_secs

Updates the generated cue reference for flush_period_secs to describe the
new 0-disables-expiration behavior, keeping it in sync with the Rust doc
comment.
@valerypetrov
valerypetrov force-pushed the fix/prometheus-exporter-disable-expiration branch from b35a4d5 to 407454d Compare August 5, 2026 22:21
@valerypetrov

Copy link
Copy Markdown
Author

recheck

@valerypetrov

Copy link
Copy Markdown
Author

@jszwedko , can you please check this one?

@jszwedko

Copy link
Copy Markdown
Contributor

Hi @valerypetrov ! Tagging @vectordotdev/vector since I'm not actively involved in the project anymore.

@pront

pront commented Aug 11, 2026

Copy link
Copy Markdown
Member

Thanks @valerypetrov we will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain: external docs Anything related to Vector's external, public documentation domain: sinks Anything related to the Vector's sinks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prometheus_exporter sink not able to aggregate metrics over time

3 participants