@@ -57,13 +57,38 @@ public class HystrixCommandMetrics extends HystrixMetrics {
57
57
* @return {@link HystrixCommandMetrics}
58
58
*/
59
59
public static HystrixCommandMetrics getInstance (HystrixCommandKey key , HystrixCommandGroupKey commandGroup , HystrixCommandProperties properties ) {
60
+ return getInstance (key , commandGroup , null , properties );
61
+ }
62
+
63
+ /**
64
+ * Get or create the {@link HystrixCommandMetrics} instance for a given {@link HystrixCommandKey}.
65
+ * <p>
66
+ * This is thread-safe and ensures only 1 {@link HystrixCommandMetrics} per {@link HystrixCommandKey}.
67
+ *
68
+ * @param key
69
+ * {@link HystrixCommandKey} of {@link HystrixCommand} instance requesting the {@link HystrixCommandMetrics}
70
+ * @param commandGroup
71
+ * Pass-thru to {@link HystrixCommandMetrics} instance on first time when constructed
72
+ * @param properties
73
+ * Pass-thru to {@link HystrixCommandMetrics} instance on first time when constructed
74
+ * @return {@link HystrixCommandMetrics}
75
+ */
76
+ public static HystrixCommandMetrics getInstance (HystrixCommandKey key , HystrixCommandGroupKey commandGroup , HystrixThreadPoolKey threadPoolKey , HystrixCommandProperties properties ) {
60
77
// attempt to retrieve from cache first
61
78
HystrixCommandMetrics commandMetrics = metrics .get (key .name ());
62
79
if (commandMetrics != null ) {
63
80
return commandMetrics ;
64
81
}
65
82
// it doesn't exist so we need to create it
66
- commandMetrics = new HystrixCommandMetrics (key , commandGroup , properties , HystrixPlugins .getInstance ().getEventNotifier ());
83
+
84
+ //now check to see if we need to create a synthetic threadPoolKey
85
+ HystrixThreadPoolKey nonNullThreadPoolKey ;
86
+ if (threadPoolKey == null ) {
87
+ nonNullThreadPoolKey = HystrixThreadPoolKey .Factory .asKey (commandGroup .name ());
88
+ } else {
89
+ nonNullThreadPoolKey = threadPoolKey ;
90
+ }
91
+ commandMetrics = new HystrixCommandMetrics (key , commandGroup , nonNullThreadPoolKey , properties , HystrixPlugins .getInstance ().getEventNotifier ());
67
92
// attempt to store it (race other threads)
68
93
HystrixCommandMetrics existing = metrics .putIfAbsent (key .name (), commandMetrics );
69
94
if (existing == null ) {
@@ -107,13 +132,15 @@ public static Collection<HystrixCommandMetrics> getInstances() {
107
132
private final HystrixRollingPercentile percentileTotal ;
108
133
private final HystrixCommandKey key ;
109
134
private final HystrixCommandGroupKey group ;
135
+ private final HystrixThreadPoolKey threadPoolKey ;
110
136
private final AtomicInteger concurrentExecutionCount = new AtomicInteger ();
111
137
private final HystrixEventNotifier eventNotifier ;
112
138
113
- /* package */ HystrixCommandMetrics (HystrixCommandKey key , HystrixCommandGroupKey commandGroup , HystrixCommandProperties properties , HystrixEventNotifier eventNotifier ) {
139
+ /* package */ HystrixCommandMetrics (HystrixCommandKey key , HystrixCommandGroupKey commandGroup , HystrixThreadPoolKey threadPoolKey , HystrixCommandProperties properties , HystrixEventNotifier eventNotifier ) {
114
140
super (new HystrixRollingNumber (properties .metricsRollingStatisticalWindowInMilliseconds (), properties .metricsRollingStatisticalWindowBuckets ()));
115
141
this .key = key ;
116
142
this .group = commandGroup ;
143
+ this .threadPoolKey = threadPoolKey ;
117
144
this .properties = properties ;
118
145
this .percentileExecution = new HystrixRollingPercentile (properties .metricsRollingPercentileWindowInMilliseconds (), properties .metricsRollingPercentileWindowBuckets (), properties .metricsRollingPercentileBucketSize (), properties .metricsRollingPercentileEnabled ());
119
146
this .percentileTotal = new HystrixRollingPercentile (properties .metricsRollingPercentileWindowInMilliseconds (), properties .metricsRollingPercentileWindowBuckets (), properties .metricsRollingPercentileBucketSize (), properties .metricsRollingPercentileEnabled ());
@@ -131,13 +158,23 @@ public HystrixCommandKey getCommandKey() {
131
158
132
159
/**
133
160
* {@link HystrixCommandGroupKey} of the {@link HystrixCommand} these metrics represent.
134
- *
161
+ *
135
162
* @return HystrixCommandGroupKey
136
163
*/
137
164
public HystrixCommandGroupKey getCommandGroup () {
138
165
return group ;
139
166
}
140
167
168
+ /**
169
+ * {@link HystrixThreadPoolKey} used by {@link HystrixCommand} these metrics represent.
170
+ *
171
+ * @return HystrixThreadPoolKey
172
+ */
173
+ public HystrixThreadPoolKey getThreadPoolKey () {
174
+ return threadPoolKey ;
175
+ }
176
+
177
+
141
178
/**
142
179
* {@link HystrixCommandProperties} of the {@link HystrixCommand} these metrics represent.
143
180
*
0 commit comments