Skip to content

Commit 1118507

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 1118507

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,22 @@ public static void reset() {
9797

9898
/* package */ HystrixMetricsPublisherFactory() {}
9999

100-
// String is CommandKey.name() (we can't use CommandKey directly as we can't guarantee it implements hashcode/equals correctly)
101100
private final ConcurrentHashMap<String, HystrixMetricsPublisherCommand> commandPublishers = new ConcurrentHashMap<String, HystrixMetricsPublisherCommand>();
102101

103102
/* package */ HystrixMetricsPublisherCommand getPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) {
104103
// attempt to retrieve from cache first
105-
HystrixMetricsPublisherCommand publisher = commandPublishers.get(commandKey.name());
104+
String cacheKey = commandOwner.name() + commandKey.name();
105+
HystrixMetricsPublisherCommand publisher = commandPublishers.get(cacheKey);
106106
if (publisher != null) {
107107
return publisher;
108108
} else {
109109
synchronized (this) {
110-
HystrixMetricsPublisherCommand existingPublisher = commandPublishers.get(commandKey.name());
110+
HystrixMetricsPublisherCommand existingPublisher = commandPublishers.get(cacheKey);
111111
if (existingPublisher != null) {
112112
return existingPublisher;
113113
} else {
114114
HystrixMetricsPublisherCommand newPublisher = HystrixPlugins.getInstance().getMetricsPublisher().getMetricsPublisherForCommand(commandKey, commandOwner, metrics, circuitBreaker, properties);
115-
commandPublishers.putIfAbsent(commandKey.name(), newPublisher);
115+
commandPublishers.putIfAbsent(cacheKey, newPublisher);
116116
newPublisher.initialize();
117117
return newPublisher;
118118
}

0 commit comments

Comments
 (0)