Skip to content

Add support for the prometheus-client crate #88

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
merged 19 commits into from
May 23, 2023
Merged

Conversation

emschwartz
Copy link
Contributor

Resolves #25

@emschwartz
Copy link
Contributor Author

For some reason, the tests are failing / flaky only when the opentelemetry crate is being used. I'm also having trouble figuring out what that crate is doing internally when you call the functions to increment the counters to identify what the issue might be. It seems like some of the calls to the instrumented functions in the tests aren't being registered.

@emschwartz emschwartz marked this pull request as ready for review May 19, 2023 15:10
@emschwartz
Copy link
Contributor Author

I found out that #94 was the issue causing the tests to fail here. I opened a separate draft PR to work on fixing that issue, as it is separate from what's being added here.

@@ -186,9 +186,21 @@ pub use autometrics_macros::ResultLabels;
#[cfg(feature = "prometheus-exporter")]
pub use self::prometheus_exporter::*;

/// Functionality specific to the libraries used to collect metrics
pub mod integrations {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still not sure I like this name, but I can't think of anything better. metrics_libraries, producers, ...

Copy link
Member

Choose a reason for hiding this comment

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

couldn't we just put the integrations as the top level name, getting rid of integrations? so the resolved path would end up being smth like autometrics::prometheus_client instead of autometrics::integrations::prometheus_client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm that would also be an option. The main downside with that is we may want some other submodules exported from the crate root that are different, and they could get a bit lost. For example #90. We'd have 4-5 modules that are all related to the metrics libraries and 1-2 that aren't.

Copy link
Member

Choose a reason for hiding this comment

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

seems fine imo

@emschwartz emschwartz requested review from gagbo and mellowagain May 19, 2023 15:12
@emschwartz
Copy link
Contributor Author

We should also update the example for custom metrics to show how to do it with this crate. The only thing is that the way we are exporting the registry, you can't modify it to add more custom metrics to that same registry. That might not be a problem though, because this crate seems to discourage the use of global registries anyway. So maybe it's fine?

Copy link
Member

@mellowagain mellowagain left a comment

Choose a reason for hiding this comment

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

we didnt end up doing the compile_error thing for the conflicting features?

@@ -119,6 +122,10 @@ impl Objective {
}

/// The percentage of requests that must meet the given criteria (success rate or latency).
#[cfg_attr(
feature = "prometheus-client",
derive(Clone, Debug, PartialEq, Eq, Hash)
Copy link
Member

Choose a reason for hiding this comment

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

can also be Copy, which would make it easier to use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, true. Do you think we should derive all of those traits all of the time (not just when using prometheus-client)? I'm somewhat hesitant to do that proactively because it technically expands the surface area of the API and (maybe?) increases compile times. But maybe it's fine to just do it for this type of enum

Copy link
Member

Choose a reason for hiding this comment

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

saving Copy makes it way nicer to use. just be sure that u dont plan to add more in the future which may not be Copy, as removing Copy is a breaking change and requires a major version bump (unlike adding it)

@emschwartz
Copy link
Contributor Author

we didnt end up doing the compile_error thing for the conflicting features?

@mellowagain I think that's still undecided. My current thought on this PR is to try to get it in sooner, but fix some of those other things we've talked about in other PRs and wait until a bunch of them are done before publishing another version

@emschwartz emschwartz requested a review from mellowagain May 23, 2023 11:11
Copy link
Member

@mellowagain mellowagain left a comment

Choose a reason for hiding this comment

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

small nits no blocker

@@ -186,9 +186,21 @@ pub use autometrics_macros::ResultLabels;
#[cfg(feature = "prometheus-exporter")]
pub use self::prometheus_exporter::*;

/// Functionality specific to the libraries used to collect metrics
pub mod integrations {
Copy link
Member

Choose a reason for hiding this comment

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

seems fine imo

@@ -119,6 +122,10 @@ impl Objective {
}

/// The percentage of requests that must meet the given criteria (success rate or latency).
#[cfg_attr(
feature = "prometheus-client",
derive(Clone, Debug, PartialEq, Eq, Hash)
Copy link
Member

Choose a reason for hiding this comment

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

saving Copy makes it way nicer to use. just be sure that u dont plan to add more in the future which may not be Copy, as removing Copy is a breaking change and requires a major version bump (unlike adding it)

@emschwartz emschwartz enabled auto-merge (squash) May 23, 2023 12:46
@emschwartz emschwartz merged commit 4d67922 into main May 23, 2023
@emschwartz emschwartz deleted the prometheus-client-2 branch May 23, 2023 12:49
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.

Add support for the prometheus-client crate
2 participants