From 150ca559ad379c68d795f24952d67571e8203ebb Mon Sep 17 00:00:00 2001 From: Hugh Sutton-Gee Date: Fri, 20 Dec 2024 13:20:10 -0800 Subject: [PATCH] Update metric creation to happen only once per store --- .../java/com/linkedin/venice/router/MetaDataHandler.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/venice-router/src/main/java/com/linkedin/venice/router/MetaDataHandler.java b/services/venice-router/src/main/java/com/linkedin/venice/router/MetaDataHandler.java index 975c4f25de..576ab385f6 100644 --- a/services/venice-router/src/main/java/com/linkedin/venice/router/MetaDataHandler.java +++ b/services/venice-router/src/main/java/com/linkedin/venice/router/MetaDataHandler.java @@ -484,9 +484,12 @@ private void handleD2ServiceLookup(ChannelHandlerContext ctx, VenicePathParserHe } // Only create metrics for valid stores - String d2DiscoveryMetricName = "venice.router.d2_discovery." + storeName; - Sensor d2DiscoverySensor = metricsRepository.sensor(d2DiscoveryMetricName); - d2DiscoverySensor.add(d2DiscoveryMetricName + ".request.count", new Count()); + Sensor d2DiscoverySensor = metricsRepository.sensor("venice.router.d2_discovery." + storeName); + String d2DiscoveryRequestCountMetric = "venice.router.d2_discovery." + storeName + ".request.count"; + // Check if metric already exists before adding + if (!metricsRepository.metrics().containsKey(d2DiscoveryRequestCountMetric)) { + d2DiscoverySensor.add(d2DiscoveryRequestCountMetric, new Count()); + } d2DiscoverySensor.record(); String clusterName = config.get().getCluster();