Skip to content

Commit fd73cb8

Browse files
authored
fix: Fix duplicate metrics on different roots (#18014)
Signed-off-by: Xuanwo <[email protected]>
1 parent 1dfd2da commit fd73cb8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/common/storage/src/metrics_layer.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,32 @@ impl observe::MetricsIntercept for MetricsRecorder {
235235
}
236236
}
237237

238-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
238+
/// observe::MetricLabels contains root but we don't want it.
239+
#[derive(Clone, Debug)]
239240
struct OperationLabels(observe::MetricLabels);
240241

242+
impl PartialEq for OperationLabels {
243+
fn eq(&self, other: &Self) -> bool {
244+
self.0.scheme == other.0.scheme
245+
&& self.0.namespace == other.0.namespace
246+
&& self.0.operation == other.0.operation
247+
&& self.0.error == other.0.error
248+
&& self.0.status_code == other.0.status_code
249+
}
250+
}
251+
252+
impl Eq for OperationLabels {}
253+
254+
impl std::hash::Hash for OperationLabels {
255+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
256+
self.0.scheme.hash(state);
257+
self.0.namespace.hash(state);
258+
self.0.operation.hash(state);
259+
self.0.error.hash(state);
260+
self.0.status_code.hash(state);
261+
}
262+
}
263+
241264
impl EncodeLabelSet for OperationLabels {
242265
fn encode(&self, mut encoder: LabelSetEncoder) -> Result<(), fmt::Error> {
243266
(observe::LABEL_SCHEME, self.0.scheme.into_static()).encode(encoder.encode_label())?;

0 commit comments

Comments
 (0)