refactor(layers/prometheus): provide builder APIs#5072
refactor(layers/prometheus): provide builder APIs#5072Xuanwo merged 19 commits intoapache:mainfrom koushiro-contrib:prometheus-consistent-apis
Conversation
| /// Ok(()) | ||
| /// # } | ||
| /// ``` | ||
| pub fn register(self, registry: &Registry) -> Self { |
There was a problem hiding this comment.
We don't need this API. PrometheusLayer::new() should be enough.
There was a problem hiding this comment.
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.
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.
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.
So do we need to use similar APIs in PrometheusLayer?
There was a problem hiding this comment.
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.
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.
I feel like we can call with_recorder direcly: https://docs.rs/metrics/latest/src/metrics/recorder/mod.rs.html#126
Xuanwo
left a comment
There was a problem hiding this comment.
Thanks a lot! This API design is really clean and easy to use. There are some nits on the public API.
| 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.
How about returning an error instead of just unwrapping?
There was a problem hiding this comment.
Should we return prometheus::Error or opendal::Error?
There was a problem hiding this comment.
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. |
Xuanwo
left a comment
There was a problem hiding this comment.
Thank you very much. We are very close to merging. I found a few places I missed in the previous round.
Xuanwo
left a comment
There was a problem hiding this comment.
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
PrometheusLayerandPrometheusClientLayerWhat changes are included in this PR?
PrometheusLayer::builderPrometheusLayerBuilderDefaultforPrometheusLayerpath_label_valueintoobservemodAre there any user-facing changes?
API breaking change