Skip to content

_lock not found on metric #1140

Closed
Closed

Description

@zack-littke-smith-ai

Hello! I hit an issue with a metric which has no labels invoking clear(). We fail on self._lock no existing. Turns out it was not created because there are no label values here, we actually have no lock on the instance later when we clear it. Why don't we always create this lock?

Activity

  1. added theissue type on Oct 7, 2025
  2. csmarchbanks commented on Oct 7, 2025

    @csmarchbanks
    Member

    Definitely a bug here, we shouldn't fail with such a unhelpful message.

    That said, clearing (or removing as I believe this will also happen if you try to call remove on a metric with no labels) doesn't really make a lot of sense. Both clear and remove deal with labelsets which are also what are protected by the lock, so a metric with no labelset doesn't need the lock.

    As far as this issue goes, what were you trying to accomplish calling clear on this metric? I can imagine providing a more helpful error message (maybe pointing users to reset for counters, or set(0) for gauges?), or just having clear/remove doing nothing when called on metrics without a labelset.

  3. zack-littke-smith-ai commented on Oct 7, 2025

    @zack-littke-smith-ai
    Author

    I have a pretty specific usecase to motivate use of https://github.com/zapier/prom-aggregation-gateway (not very vanilla Prometheus), but I have actually found a different approach that works for me. My initial implementation was to clear metrics immediately after sending them to this gateway, so that I would never double count. It is slightly more compute but it is actually more threadsafe and api-supported to calculate deltas from the last payload and send those, rather than resetting to 0.

    My usecase for using the library in the first place is that I want to collect metrics in many short-lived jobs which cant be easily / reliably scraped.

  4. csmarchbanks commented on Jul 8, 2026

    @csmarchbanks
    Member

    Fixed in #1184

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions