-
Notifications
You must be signed in to change notification settings - Fork 106
feat(metrics/family): 🍬 contains() checks if metrics exist
#245
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cratelyn
added a commit
to cratelyn/prometheus-client
that referenced
this pull request
Nov 18, 2024
this commit introduces a `len()` method to `Family<S, M, C>`, which returns the number of series within a metric family. see also prometheus#245, which allows callers to check if a family `contains()` a given label set. Signed-off-by: katelyn martin <me+cratelyn@katelyn.world>
Contributor
Author
|
my understanding is that this could be added behind the |
mxinden
reviewed
Jan 19, 2026
Member
mxinden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move forward here once #242 merged.
8068b8a to
ac53ac1
Compare
cratelyn
added a commit
to cratelyn/prometheus-client
that referenced
this pull request
Jan 22, 2026
this commit introduces a `len()` method to `Family<S, M, C>`, which returns the number of series within a metric family. see also prometheus#245, which allows callers to check if a family `contains()` a given label set. ```shell $ cargo clippy --all-features --all-targets --tests Compiling prometheus-client v0.23.0 (/path/to/prometheus-client) warning: struct `Family` has a public `len` method, but no `is_empty` method --> src/metrics/family.rs:309:5 | 309 | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty = note: `#[warn(clippy::len_without_is_empty)]` on by default warning: `prometheus-client` (lib) generated 1 warning warning: `prometheus-client` (lib test) generated 1 warning (1 duplicate) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s ``` Signed-off-by: katelyn martin <git@katelyn.world>
cratelyn
commented
Jan 22, 2026
this commit introduces a small accessor to the `Family<S, M, C>` metric family type. this new `contains()` method allows callers to check whether or not a metric with the provided set of labels exists. if no metric has been created via e.g. `get_or_create()`, this method will return `false`. Signed-off-by: katelyn martin <git@katelyn.world>
ac53ac1 to
1d32d56
Compare
cratelyn
added a commit
to cratelyn/prometheus-client
that referenced
this pull request
Jan 22, 2026
this commit introduces a `len()` method to `Family<S, M, C>`, which returns the number of series within a metric family. see also prometheus#245, which allows callers to check if a family `contains()` a given label set. ```shell $ cargo clippy --all-features --all-targets --tests Compiling prometheus-client v0.23.0 (/path/to/prometheus-client) warning: struct `Family` has a public `len` method, but no `is_empty` method --> src/metrics/family.rs:309:5 | 309 | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty = note: `#[warn(clippy::len_without_is_empty)]` on by default warning: `prometheus-client` (lib) generated 1 warning warning: `prometheus-client` (lib test) generated 1 warning (1 duplicate) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s ``` Signed-off-by: katelyn martin <git@katelyn.world>
cratelyn
commented
Jan 22, 2026
mxinden
approved these changes
Jan 23, 2026
Signed-off-by: Max Inden <mail@max-inden.de>
cratelyn
added a commit
to cratelyn/prometheus-client
that referenced
this pull request
Jan 28, 2026
this commit introduces a `len()` method to `Family<S, M, C>`, which returns the number of series within a metric family. see also prometheus#245, which allows callers to check if a family `contains()` a given label set. ```shell $ cargo clippy --all-features --all-targets --tests Compiling prometheus-client v0.23.0 (/path/to/prometheus-client) warning: struct `Family` has a public `len` method, but no `is_empty` method --> src/metrics/family.rs:309:5 | 309 | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty = note: `#[warn(clippy::len_without_is_empty)]` on by default warning: `prometheus-client` (lib) generated 1 warning warning: `prometheus-client` (lib test) generated 1 warning (1 duplicate) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s ``` Signed-off-by: katelyn martin <git@katelyn.world>
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 29, 2026
feat(metrics/family): `len()` returns the number of metrics this commit introduces a `len()` method to `Family<S, M, C>`, which returns the number of series within a metric family. see also #245, which allows callers to check if a family `contains()` a given label set. ```shell $ cargo clippy --all-features --all-targets --tests Compiling prometheus-client v0.23.0 (/path/to/prometheus-client) warning: struct `Family` has a public `len` method, but no `is_empty` method --> src/metrics/family.rs:309:5 | 309 | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty = note: `#[warn(clippy::len_without_is_empty)]` on by default warning: `prometheus-client` (lib) generated 1 warning warning: `prometheus-client` (lib test) generated 1 warning (1 duplicate) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s ``` Signed-off-by: katelyn martin <git@katelyn.world>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this commit introduces a small accessor to the
Family<S, M, C>metric family type. this newcontains()method allows callers to check whether or not a metric with the provided set of labels exists.if no metric has been created via e.g.
get_or_create(), this method will returnfalse.