Skip to content

Implement deletion of Gauge metrics based on partially specified labels #1118

Closed

Description

@TheGameProfi

In many cases, the labels of a Gauge are fixed and known, but sometimes it’s hard to keep track of all labels, for example with an HTTP request collector per endpoint.

It would be very useful to have a method to delete metrics by matching a subset of labels. For example, deleting all metrics with status_code="200" regardless of other labels.

I ran into this issue myself when scraping disk data from multiple instances. On reset I wanted to remove only a specific instance's metrics, but ended up removing all.

The Go client (client_golang) has a DeletePartiallyMatching method.
prometheus/client_golang#834

Activity

  1. changed the title [-]Enable deletion of Gauge metrics based on partially specified labels[/-] [+]Implement deletion of Gauge metrics based on partially specified labels[/+] on Jul 11, 2025
  2. hazel-shen commented on Aug 12, 2025

    @hazel-shen
    Contributor

    Hi, I’m interested in implementing partial label removal (remove_matching) for Gauge (and other metric types if applicable).
    I’ve done a local prototype that allows deleting all time series that match a subset of labels.
    Example:

    g.remove_matching({"tenant": "acme"})
    This would remove all series where tenant="acme", regardless of endpoint.

    I’ll prepare a PR including:

    • Thread-safe implementation for single-process mode
    • Warning + no-op for multiprocess mode (same as current remove function)
    • Unit tests covering exact match, partial match, and no match
    • Documentation updates in the "Labels / Removing series" section

    Please let me know if this approach works for you before I proceed.

  3. TheGameProfi commented on Aug 12, 2025

    @TheGameProfi
    Author

    Hey @hazel-shen , that really sounds like exactly what I was looking for.
    I had thought about looking into how it could be implemented myself, but I just don’t have the time or focus for it right now.
    So I really appreciate you taking the initiative to create a PR for this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions