feat: Make PrometheusClientLayer Clonable#3352
Conversation
Xuanwo
left a comment
There was a problem hiding this comment.
I don't like the idea of implementing Layer for a reference. Do we have better choices? For example, changing the PromClientLayer's API to avoid such thing happens.
|
Seems We need to make The API will be: #[derive(Default, Clone)]
struct PrometheusClientMetrics {..}
impl PrometheusClientMetrics {
pub fn register(&self, registry: &mut Registry);
}
struct PrometheusClientLayer {..}
impl PrometheusClientLayer {
pub fn new(metrics: PrometheusClientMetrics) -> Self;
}In this way, users only need to store |
IMHO this api is also error prone as the PrometheusClientMetrics struct is passed by moving instead of a reference. We have no way to pass a PrometheusClientMetrics singleton from adhoc any other suggestion about the API design? or just use interior mutability? |
|
|
if do not want using reference on the Layer side, I think we need an however this may introduce an extra |
no. not all metrics are |
But all metrics in opendal will be |
no, Family is used for the metrics with labels. if your labels exploded, you'd like to replace some families with simple metrics to make the metrics crapper happy. |
I didn't get this. Are you talking about changing |
|
oh I got it wrong, the simple metrics like Counter, Gauge are also wrapped within an |
|
so we can consider just make |
LGTM. |
|
updated the PR, after when only one line of code is changed, PTAL @Xuanwo |
Xuanwo
left a comment
There was a problem hiding this comment.
Mostly LGTM, please make rustfmt happy.
we met an issue in databendlabs/databend#13373 , as sometimes we'd call
build_operator()on some queries, this causes duplicated metrics get registered into the registry, which finally produced millions of metrics.the solution is to make the PrometheusClientLayer a singleton, but currently the PrometheusClientLayer have to be moved. we need allow it passing a reference before making the singleton in the
layer()call.