Repository navigation
Conversation
…for tracked tag values Add `ttl_secs` and `ttl_generations` to the global config, per-metric overrides, and the corresponding schemas. When set, tag values not observed within `ttl_secs` are expired so fresh values can take their slot under `value_limit` — useful when the downstream backend (e.g. Datadog custom metrics) counts uniqueness over a rolling window. `mode: exact` uses a `HashMap<value, last_seen>` with lazy sweep; `mode: probabilistic` uses a generational rolling bloom filter so a non-deletable bloom can still expire values (eviction granularity = `ttl_secs / ttl_generations`). Both refresh on sighting and evict lazily on access. The `DropEvent` pre-check uses a new `contains_no_refresh` variant so rejected events don't extend leases. New `tag_cardinality_ttl_expirations_total` internal counter exposes eviction volume. Backwards compatible: unset / `0` ⇒ pre-PR behavior.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7aa7efbef3
ℹ️ 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".
…ache_ttl # Conflicts: # src/transforms/tag_cardinality_limit/mod.rs # src/transforms/tag_cardinality_limit/tag_value_set.rs
There was a problem hiding this comment.
💡 Codex Review
vector/src/transforms/tag_cardinality_limit/tag_value_set.rs
Lines 59 to 63 in dde8896
BloomFilterStorage::insert currently skips writes when contains is already true, which is safe for a single monotonic bloom but breaks the new rolling TTL path. In RollingBloomStorage::contains, a hit in an older shard is refreshed into the newest shard via this method; if the newest shard returns a false positive for that value, the refresh is skipped, and after the older shard rotates out the value can disappear despite being recently observed. Near value_limit, that turns into legitimate recurring tag values being treated as new and dropped (or causing DropEvent rejections). Refresh writes in the active shard need to be unconditional, with count tracking handled separately.
ℹ️ 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".
…lementation Five fixes flagged by Codex on PR vectordotdev#25485: P1 - `RollingBloomStorage::len()` returned the max across shards, which under-counts the window-union cardinality. Distinct cold values spread across shards kept every individual shard below `value_limit` while the union exceeded it, silently admitting values past the cap. Now sums shard counts as a strict upper bound; the only failure mode is over-rejection (observable via `tag_value_limit_exceeded_total`). P1 - `BloomFilterStorage::insert` skipped setting bits when `contains` already returned true. For the rolling-bloom refresh path, that meant a recently-sighted value could ride on another value's false-positive bits rather than holding its own — its lifetime then depended on when those unrelated bits aged out instead of its own activity. The insert now sets bits unconditionally; count tracking remains conditional. P2 - `slice` was floored to 1s, silently stretching the configured TTL window to `ttl_generations` seconds whenever `ttl_secs < ttl_generations`. The effective number of generations is now capped to `ttl_secs` so `slice * generations == ttl` is preserved exactly. Same cap applied to `TtlExactStorage::new` for consistency. P2 - `Instant + Duration` could panic on pathological `ttl_secs` close to `u64::MAX`. Now uses checked arithmetic with saturation, so an oversized config keeps the transform alive instead of crashing it. P2 - TTL eviction left empty `(metric, tag-key)` buckets in place, which permanently consumed slots under `max_tracked_keys`. A lazy `reclaim_empty_buckets` runs only on the cap-hit path; freed slots are now reused. Steady-state allocations are unaffected. Refs: vectordotdev#25485
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b95265e91c
ℹ️ 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".
…check, and Instant saturation - Trim Codex / "previously …" framing and consolidate the changelog so all pre-merge refinements ship under the single feature entry. - `tag_limit_exceeded` now reclaims empty TTL buckets before the `value_limit: 0` capacity check, matching `record_tag_value` and preventing `drop_event` events from silently admitting a value when the cap is full but contains reclaimable empty buckets. - `saturating_add` falls back to `instant + ~136 years` (with bisection) on `Instant + Duration` overflow so `next_rotate` is never pinned to `now`, avoiding `generations`-per-call rotation churn under pathological `ttl_secs`. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 528561d02f
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57e3ce86fb
ℹ️ 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".
…fresh, and zero-limit reclaim
Resolve conflict in internal_metrics.cue: keep tag_cardinality_ttl_expirations_total from the TTL PR and drop a stale stdin_reads_failed_total entry that was not on upstream master. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 44d9f079e4
ℹ️ 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".
Resolve tag_value_set.rs conflict: keep TTL storage backends and wire in upstream ExactFingerprint mode (FingerprintStorage + match arms). Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78490bc7d2
ℹ️ 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".
The exact TTL backend retained over the whole bucket on every read, so `contains`/`contains_no_refresh` cost O(cached values) per accepted tag. Workloads with a large `value_limit` and mostly already-accepted values paid that scan on the hot path of every event. Reads now inspect only the timestamp of the value they were asked about and drop that single entry when its lease has lapsed. The full retain is reserved for the periodic sweep and for `len`, which gates `value_limit` and the `max_tracked_keys` bucket reclaim and so must never count lapsed entries. This preserves the existing guarantee that an expired value is never refreshed back into the window. Both eviction paths now report to `tag_cardinality_ttl_expirations_total`; previously only the periodic sweep did, so evictions driven by an access between sweeps went uncounted. Co-authored-by: Cursor <cursoragent@cursor.com>
… slots `tag_cardinality_ttl_expirations_total` was documented as a count of distinct values expired, but in probabilistic mode it reports the slots reclaimed from the retired rolling-bloom shard. Refresh-on-sighting copies hot values into newer shards, so a value counted there may still be retained in the window. Rather than drop the rotation signal, describe the counter in the unit it actually measures. Slots are also the unit `len` sums to enforce `value_limit`, so the counter stays consistent with the cap it feeds. Exact mode is unchanged and remains one slot per distinct value. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@ArunPiduguDD any updates? |
Keep the TTL backends and mutable membership checks, and include master's ExactFingerprint storage in the same constructor. Narrow the TTL helpers to pub(super)/pub(crate) so they satisfy unreachable_pub. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de42499b11
ℹ️ 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".
…roximate The expiration counter sums bloom-shard slot counts. Refresh-on-sighting can count a value that is still retained, and a false-positive insert does not increment the shard count, so the probabilistic figure is an approximation rather than an upper bound. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa0e7d17b5
ℹ️ 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".
… redundant bloom writes reclaim_empty_buckets scanned every bucket on each max_tracked_keys cap miss even when no TTL is configured, where only intentional value_limit: 0 buckets can be empty and those are never reclaimed. Skip the scan unless the global config or a per-metric override enables a TTL, which restores the O(1) cap-miss path for non-TTL users. BloomFilterStorage::insert wrote bits even when contains() already reported the value present. That write is a no-op because contains() is true only when every bit is already set, so return early instead. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab1e5289e4
ℹ️ 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".
any_ttl_enabled treated a positive ttl_secs on a per_metric_limits entry as a real TTL even when that entry is mode: excluded. Excluded metrics allocate no buckets and ignore their other fields, so the flag turned the full max_tracked_keys reclaim scan back on when nothing could expire. Only tracked overrides now count. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b3430d18e
ℹ️ 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".
…r second Gating reclaim on a config-wide TTL flag still let a single TTL override make every max_tracked_keys cap miss visit all buckets, including the non-expiring ones. Rate-limit the whole pass to once per second instead (the flag stays as a cheap early return), which bounds the cost for any mix of TTL and non-TTL buckets. The old split between len() and len_reclaiming() goes away since every pass now fully purges. Also stop validating TTL fields on mode: excluded overrides. They ignore every other field and allocate no storage, so a stale ttl_secs with ttl_generations: 0 must not fail startup. OverrideInner::ttl_active is now the single predicate for both validation and the reclaim flag. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b81eb42147
ℹ️ 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".
A cache miss checks every rolling-bloom shard, and each check hashes the tag value, so a long ttl_secs with ttl_generations at the u8 maximum is 256 probes per tag. Reject probabilistic configs whose effective generation count, after the one-second slice clamp, is above 16. Exact mode does not probe shards and stays uncapped, and a short ttl_secs that clamps the count back to 16 or below still builds. Validation uses the same slice helper the storage backends use. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Once an exact-TTL bucket is full, every rejected new value forces a complete scan, making overflow handling proportional to value_limit. The existing one-second guard protects empty-bucket reclamation but does not cover these rejection paths.
🤖 Bits Code Review · Commit 6a49c95
…ce per second A full exact-TTL bucket of still-valid values forced a complete HashMap scan on every rejected new value, from both try_accept_tag and the DropEvent pre-check, so overflow cost grew with value_limit per event. Gate purge_expired on its own timestamp so it runs at most once per second. Independent of last_sweep, since the periodic sweep is not due during overflow. A value whose lease lapses just after a purge keeps its slot until the next one, at most one second later. Also switch five call sites that still used the emit! macro to emit(), since the master merge replaced the macro in this crate and the branch did not compile. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
More details
The PR adds optional TTL for exact and probabilistic tag-cardinality caches, refreshing accepted values and reclaiming stale slots. The new commit fixes repeated full-cache scans during rejection by limiting capacity purges to once per second per bucket; no findings remain open.
🤖 Bits Code Review · Commit 4b1d9ce
|
@ArunPiduguDD any update? |
|
Let me know when there was anything to update. |
Summary
Adds optional sliding-window TTL to the
tag_cardinality_limittransform via two new settings (ttl_secs,ttl_generations) on the global config, everyper_metric_limitsentry, and the corresponding schemas (Inner/OverrideInner).When set, tag values not accepted within
ttl_secsare expired so fresh values can take their slot undervalue_limit.The cardinality cache is currently monotonic: every distinct value ever seen for a tag holds a slot under
value_limituntil the next Vector restart — and a restart is the only thing that resets the cache today. That's fine for stable identifiers, but it breaks down for high-churn tag values with a natural lifetime:pod_name,abused_account_id, ephemeral request IDs, short-lived job IDs, etc. These are valid for hours to days at most (a pod rolled out yesterday, an account that was banned last week, a request that completed minutes ago), then never appear again — yet they keep holding slots until Vector is restarted. Once enough dead slots accumulate, the cache hitsvalue_limitand starts rejecting legitimate new values that would fit comfortably under the cap, simply because old ones never aged out.Setting
ttl_secsturns the cache into a sliding window: any tag value not accepted within that many seconds is dropped, freeing the slot for a fresh value, without requiring a Vector restart.Two storage backends, picked at construction time from
(Mode, ttl_secs):mode: exact+ TTL →HashMap<value, last_accepted>with lazy sweep on access. Per-value precision; ~50% more memory than today's HashSet (one Instant per value). Ordinarylen()stays O(1); a full purge runs only when a bucket is atvalue_limitor when reclaiming empty keys (at most once per second).mode: probabilistic+ TTL → generational / rolling bloom filter (VecDeque<BloomFilter>of the effective generation count plus one open write shard). An explicitttl_generations: 1is the only one-shard tumbling window. A clamp from a higher request (e.g.ttl_secs: 1with the default of 4) still keeps the extra shard. Eviction granularity isttl_secs / effective generations. Memory cost is(effective generations + 1) × cache_size_per_keyper(metric, tag-key)pair; dividecache_size_per_keyby that factor to keep total memory flat. TTL bounds unique values over time; it does not shrink bloom RSS unless you also shrinkcache_size_per_key.Other design points worth flagging for review:
containshit on the accept path extends the value's lease, so continuously-accepted values stay in the cache across rotation boundaries.value_limit: re-seeding a retained value into the newest shard increases the summed slot count. That transition emitsvalue_limit_reached_total; later novel values are rejected.insert/contains/len. No background task, no extra locking — drops cleanly into the existingTaskTransformmodel.DropEventcorrectness: the pre-check uses a newcontains_no_refreshvariant so an event rejected by a later tag does not silently extend the leases of earlier-checked tags. The cache reflects accepted values, not just seen values.ttl_secsis a full override (unset on a per-metric entry means "no TTL for this metric", not "inherit from global"), matching how per-metricvalue_limitshadows the global one.tag_cardinality_ttl_expirations_totalreports the volume of evictions.Backwards compatibility: when
ttl_secsis unset (default) or0, both backends are bit-for-bit identical to pre-PR behavior —HashSetforexact, singleBloomFilterforprobabilistic. All existing configs continue to deserialize unchanged (regression-tested inttl_existing_yaml_unchanged).Why generational/rolling Bloom + per-value
HashMap, not Cuckoo or LRUaxiomhq/rust-cuckoofilter) supports deletion but has no TTL or LRU primitive — we'd still need an external timestamp store to know when to delete each value, which defeats the space win. False-not-found on full buckets is also a worse failure mode than bloom's false-positive for cardinality limiting (bloom's "ah, we've seen this, pass it through" is safe; cuckoo's "no we haven't" can drop legitimate values).HashMap<value, Instant>(which is what we use forexactmode anyway) and lost the bloom's memory advantage.value_limit) cares about the rolling window of activity, not "how many distinct values fit in N slots".HashMap<value, Instant>for both modesmode: exact. But formode: probabilistic— chosen specifically by users who can't affordHashSet-sized memory at high cardinalities — replacing the bloom with a hashmap would silently undo their memory savings.probabilistic)Ntime-sliced bloom filters and rotating the oldest one out everyttl_secs / N. Refresh-on-sighting is one line (insert into newest shard). Rotation is O(1). Approximation error is bounded and configurable viattl_generations.HashMap<value, Instant>(chosen forexact)mode: exactusers explicitly opted into. Lazyretainsweep on access is cheap (amortized over real traffic) and avoids a background task. Modest memory increase vs. today's HashSet (one Instant per value).Vector configuration
Operational impact and tuning recommendations
Side effects of enabling TTL
mode: exactmode: probabilistic(metric, tag-key)pairHashSetbaseline (oneInstantper value)(effective generations + 1) × cache_size_per_key(5× at default 4; 1× only for an explicitttl_generations: 1. A clamp such asttl_secs: 1+ default 4 keeps 2 shards / 2×)Instant::now()+ aHashMap::get_mutInstant::now()+ bloom OR-scan + possible idempotent insert into newest shardHashMap::retainover the bucket (lazy, at most once perttl_secs / generations)VecDeque::pop_front+push_back)ttl_secs / ttl_generationsDropEventpre-check usescontains_no_refresh, so rejected events don't extend leasesDropEvent: the TTL window is the active set of accepted values, not raw event volume.Memory estimation (concrete numbers)
Assume the default
cache_size_per_key = 5 × 1024 = 5,120 bytesand a workload of 100 metrics × 5 tracked tag keys = 500 pairs.mode: probabilistic, no TTL (today)mode: probabilistic,ttl_secs: 3600, ttl_generations: 4mode: probabilistic,ttl_secs: 3600, ttl_generations: 4,cache_size_per_key: 1024(1/5 of default)mode: probabilistic,ttl_secs: 3600, ttl_generations: 1(tumbling window)mode: exact, 500 distinct values × 32 B avg + 16 BInstantper valueHashSet-only baselineFor probabilistic mode the rule of thumb is
cache_size_per_key / (ttl_generations + 1)keeps total memory flat. If memory is the constraint, scalecache_size_per_keydown by the same factor you scalettl_generationsup.Recommendations
1. Don't enable TTL globally — scope it to the metrics that need it
Most deployments have a small subset of metrics whose tags actually churn (
pod_name,account_id,request_id, short-lived job IDs). The vast majority of tags (service,environment,region,host) are stable and will be re-sighted on every event anyway, so TTL on them does literally nothing except cost memory.Use
per_metric_limitsto scope TTL to the noisy metrics:2. Pick
ttl_generationsbased on memory budget vs. eviction precisionttl_generations: 1→ tumbling window. One shard (same RSS as no TTL), but everyttl_secsthe cache is dumped wholesale. A clamped one-generation config (ttl_secsshorter than the requested generation count) still keeps two shards so the TTL is not cut short.ttl_generations: 4(default) → sliding window with ±25% eviction granularity. Reasonable middle ground.ttl_generations: 8→ ±12.5% eviction granularity, 9× memory (8+1 shards). Only worth it if you're matching a strict downstream window and you have memory to spare.For
mode: exact,ttl_generationscontrols only the sweep cadence (and the sweep is cheap), not the precision — bumping it up just makes the sweep run more often. Default is fine for exact mode in almost all cases.3. Monitor
tag_cardinality_ttl_expirations_totalAfter enabling TTL, watch this counter for the first few hours:
tag_value_limit_exceeded_totalis climbing →ttl_secsis too short orvalue_limitis too low. Don't just bump TTL down further; check the lifecycle of the underlying entity.How did you test this PR?
cargo test -p vector \ --no-default-features \ --features sources-internal_metrics,transforms-tag_cardinality_limit,test-utils \ tag_cardinality_limitStorage-level unit tests in
src/transforms/tag_cardinality_limit/tag_value_set.rs::tests— these driveInstants directly (and use small real-time sleeps where the public method internally callsInstant::now()), which is the only way to exercise timing-sensitive behavior deterministically:Storage-level Instant-driven tests in tag_value_set.rs and config/integration coverage in tests.rs (84 total for this transform filter).
Transform-level integration tests in
src/transforms/tag_cardinality_limit/tests.rs.Change Type
Is this a breaking change?
All new fields default to "off"; existing YAML/TOML configs parse unchanged and produce bit-for-bit identical behavior. Verified by ttl_existing_yaml_unchanged, and ttl_zero_disables_ttl.
Does this PR include user facing changes?
no-changeloglabel to this PR.References
Notes
@vectordotdev/vectorto reach out to us regarding this PR.pre-pushhook, please see this template.make fmtmake check-clippy(if there are failures it's possible some of them can be fixed withmake clippy-fix)make testgit merge origin masterandgit push.Cargo.lock), pleaserun
make build-licensesto regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.