Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset counter #1005

Merged
merged 4 commits into from Feb 13, 2024
Merged

Reset counter #1005

merged 4 commits into from Feb 13, 2024

Conversation

positron96
Copy link
Contributor

Adds .reset() method to Counter metric.

Closes #995.

Signed-off-by: Paul Melnikov <positron96@gmail.com>
Signed-off-by: Paul Melnikov <positron96@gmail.com>
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Thanks! One small comment, and would you be willing to add a test as well please?

prometheus_client/metrics.py Outdated Show resolved Hide resolved
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Paul Melnikov <positron96@gmail.com>
@positron96
Copy link
Contributor Author

Thanks! One small comment, and would you be willing to add a test as well please

I'll see what I can about the test!

@positron96
Copy link
Contributor Author

@csmarchbanks do we need a test for "created" sample? I'm not entirely sure how to test that, as it's tied to system time

@csmarchbanks
Copy link
Member

Ideally yes, I would say just make sure that the value for _created is larger after the reset than it was originally, we don't need to assert the exact value. A brief sleep before the reset should cause that to happen consistently.

Signed-off-by: Paul Melnikov <positron96@gmail.com>
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Thanks!

@csmarchbanks csmarchbanks merged commit 1f8ceb7 into prometheus:master Feb 13, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to reset a Counter metric
2 participants