Skip to content

Commit e09e49b

Browse files
committed
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.
1 parent 3cb2158 commit e09e49b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,18 @@ public static void reset() {
102102

103103
/* package */ HystrixMetricsPublisherCommand getPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) {
104104
// attempt to retrieve from cache first
105-
HystrixMetricsPublisherCommand publisher = commandPublishers.get(commandKey.name());
105+
String cacheKey = commandOwner.name() + commandKey.name();
106+
HystrixMetricsPublisherCommand publisher = commandPublishers.get(cacheKey);
106107
if (publisher != null) {
107108
return publisher;
108109
} else {
109110
synchronized (this) {
110-
HystrixMetricsPublisherCommand existingPublisher = commandPublishers.get(commandKey.name());
111+
HystrixMetricsPublisherCommand existingPublisher = commandPublishers.get(cacheKey);
111112
if (existingPublisher != null) {
112113
return existingPublisher;
113114
} else {
114115
HystrixMetricsPublisherCommand newPublisher = HystrixPlugins.getInstance().getMetricsPublisher().getMetricsPublisherForCommand(commandKey, commandOwner, metrics, circuitBreaker, properties);
115-
commandPublishers.putIfAbsent(commandKey.name(), newPublisher);
116+
commandPublishers.putIfAbsent(cacheKey, newPublisher);
116117
newPublisher.initialize();
117118
return newPublisher;
118119
}

0 commit comments

Comments
 (0)