Skip to content

Proposal: built-in TTL #1983

@jpinsonneau

Description

@jpinsonneau

Hello team,

Several projects in the Prometheus ecosystem need to expire stale metric series from *Vec metrics (high-cardinality, ephemeral label sets / think per-pod, per-connection, etc.).

Today the only option is to maintain an external cache that shadows metricMap to track last-access times and periodically call Delete(). This duplicates memory (label sets stored twice), duplicates hashing and leads to a lot of reimplemented boilerplate across projects.

Projects that have independently built this:

I know #1397 was closed with "use Delete/Reset", but the number of projects reimplementing the same pattern suggests this would be valuable as a first-class feature. The core idea is simple: an atomic lastAccessed timestamp per child (+8 bytes, updated on GetMetricWith), and a way to clean up expired entries — either via an explicit method, during Collect(), or both.

Happy to discuss the design further and contribute a PR if there's interest. Would something like this be welcome ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions