-
Notifications
You must be signed in to change notification settings - Fork 512
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
refactor(layers/prometheus): provide builder APIs #5072
refactor(layers/prometheus): provide builder APIs #5072
Conversation
core/src/layers/prometheus.rs
Outdated
/// Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn register(self, registry: &Registry) -> Self { |
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.
We don't need this API. PrometheusLayer::new()
should be enough.
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.
IMO, PrometheusLayer::new
should just be a helper function that uses the default config and registers the metrics with the default config to the registry.
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.
Personally, I don't believe we should perform register
during new
unless the upstream API forbid it. Creating the layer itself should have no side effects. Everything should occur during the layer.
So PrometheusLayer::new()
should just take a registry
and return Self
. We will perform the registry during Layer::layer
.
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.
So how about PrometheusClientLayer
in #5073
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.
Okay, how about this: Let's use your previous proposed builder's API.
let layer: impl Layer = PrometheusClientLayer::builder()
.operation_bytes_buckets(vec![1.0, 2.0])
.register(registry);
PrometheusClientLayer::builder()
returns a PrometheusClientLayerBuilder
. Users can only use this layer after calling register
. We can provide default()
if the upstream lib has default
registry concept.
What do you think?
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.
So do we need to use similar APIs in PrometheusLayer
?
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.
So do we need to use similar APIs in
PrometheusLayer
?
I believe this design can adapt to all metrics libraries. What do you think?
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.
Yes, if you agree with the design, I'll apply it to PrometheusLayer
and PrometheusClientLayer
.
But I'm not sure if this design will fit well with other metric layers, I'm not very optimistic after using the metrics
library.
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.
I feel like we can call with_recorder
direcly: https://docs.rs/metrics/latest/src/metrics/recorder/mod.rs.html#126
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.
Thanks a lot! This API design is really clean and easy to use. There are some nits on the public API.
core/src/layers/prometheus.rs
Outdated
let labels = OperationLabels::names(false, path_label_level); | ||
let operation_duration_seconds = register_histogram_vec_with_registry!( | ||
/// Register the metrics into the given registry and return a [`PrometheusLayer`]. | ||
pub fn register(self, registry: &Registry) -> PrometheusLayer { |
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.
How about returning an error instead of just unwrapping?
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.
Should we return prometheus::Error
or opendal::Error
?
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.
opendal only returns opendal::Error
, we can wrap it inside.
There are some weird errors in CI
But if I change the icloud code, these errors are gone - let id = match node.items.iter().find(|it| it.name == name) {
- Some(it) => Ok(Some(it.drivewsid.clone())),
- None => Ok(None),
- }?;
- Ok(id)
+ Ok(node
+ .items
+ .iter()
+ .find(|it| it.name == name)
+ .map(|it| it.drivewsid.clone())) |
I think it's a new Clippy lint introduced in the latest Rust version. Would you like to submit a new PR to address it? |
I apologize for not providing a clear review. I suggest adding a In this way, we keep our public types clean and easy to maintain. |
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.
Thank you very much. We are very close to merging. I found a few places I missed in the previous round.
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.
Perfect, thank you for your patience!
Which issue does this PR close?
Related issue: #5069 (comment)
Related PR: #5073
Rationale for this change
Provide similar APIs for
PrometheusLayer
andPrometheusClientLayer
What changes are included in this PR?
PrometheusLayer::builder
PrometheusLayerBuilder
Default
forPrometheusLayer
path_label_value
intoobserve
modAre there any user-facing changes?
API breaking change