From 1118507eb26fa8542d95abcae2c7514881a3bcd6 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 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..e999b1a76 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 @@ -97,22 +97,22 @@ public static void reset() { /* package */ HystrixMetricsPublisherFactory() {} - // String is CommandKey.name() (we can't use CommandKey directly as we can't guarantee it implements hashcode/equals correctly) private final ConcurrentHashMap commandPublishers = new ConcurrentHashMap(); /* 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; }