From e09e49bf22323b7cb29667db3cc363c59111787b Mon Sep 17 00:00:00 2001 From: Ali Alsatrawi Date: Mon, 14 Jan 2019 11:45:23 +0100 Subject: [PATCH] cache publishers for commands by both command group key + command key so that they are unique. This fixes a bug whereby if two Hystrix commands have the same command key, although different group keys, only one of them will be reported. --- .../strategy/metrics/HystrixMetricsPublisherFactory.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java index 98c7813eb..b90b65f56 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java @@ -102,17 +102,18 @@ public static void reset() { /* package */ HystrixMetricsPublisherCommand getPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) { // attempt to retrieve from cache first - HystrixMetricsPublisherCommand publisher = commandPublishers.get(commandKey.name()); + String cacheKey = commandOwner.name() + commandKey.name(); + HystrixMetricsPublisherCommand publisher = commandPublishers.get(cacheKey); if (publisher != null) { return publisher; } else { synchronized (this) { - HystrixMetricsPublisherCommand existingPublisher = commandPublishers.get(commandKey.name()); + HystrixMetricsPublisherCommand existingPublisher = commandPublishers.get(cacheKey); if (existingPublisher != null) { return existingPublisher; } else { HystrixMetricsPublisherCommand newPublisher = HystrixPlugins.getInstance().getMetricsPublisher().getMetricsPublisherForCommand(commandKey, commandOwner, metrics, circuitBreaker, properties); - commandPublishers.putIfAbsent(commandKey.name(), newPublisher); + commandPublishers.putIfAbsent(cacheKey, newPublisher); newPublisher.initialize(); return newPublisher; }