Skip to content

Commit

Permalink
cache publishers for commands by both command group key + command key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ali-jawad committed Jan 14, 2019
1 parent 809104c commit e7ff313
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e7ff313

Please sign in to comment.