@@ -43,6 +43,8 @@ public class MetricsContext {
43
43
private MetricDirective metricDirective ;
44
44
private final Map <String , StorageResolution > metricNameAndResolutionMap =
45
45
new ConcurrentHashMap <>();
46
+ private final Map <String , AggregationType > metricNameAndAggregationMap =
47
+ new ConcurrentHashMap <>();
46
48
47
49
public MetricsContext () {
48
50
this (new RootNode ());
@@ -112,6 +114,40 @@ public boolean hasDefaultDimensions() {
112
114
return !getDefaultDimensions ().getDimensionKeys ().isEmpty ();
113
115
}
114
116
117
+ /**
118
+ * Add a metric measurement to the context. Multiple calls using the same key will be stored as
119
+ * an array of scalar values.
120
+ *
121
+ * <pre>{@code
122
+ * metricContext.putMetric("Latency", 100, Unit.MILLISECONDS, StorageResolution.HIGH, AggregationType.NONE)
123
+ * }</pre>
124
+ *
125
+ * @param key Name of the metric
126
+ * @param value Value of the metric
127
+ * @param unit The unit of the metric
128
+ * @param storageResolution The resolution of the metric
129
+ * @throws InvalidMetricException if the metric is invalid
130
+ */
131
+ public void putMetric (
132
+ String key ,
133
+ double value ,
134
+ Unit unit ,
135
+ StorageResolution storageResolution ,
136
+ AggregationType aggregationType )
137
+ throws InvalidMetricException {
138
+ Validator .validateMetric (
139
+ key ,
140
+ value ,
141
+ unit ,
142
+ storageResolution ,
143
+ aggregationType ,
144
+ metricNameAndResolutionMap ,
145
+ metricNameAndAggregationMap );
146
+ metricDirective .putMetric (key , value , unit , storageResolution , aggregationType );
147
+ metricNameAndResolutionMap .put (key , storageResolution );
148
+ metricNameAndAggregationMap .put (key , aggregationType );
149
+ }
150
+
115
151
/**
116
152
* Add a metric measurement to the context. Multiple calls using the same key will be stored as
117
153
* an array of scalar values.
@@ -128,10 +164,9 @@ public boolean hasDefaultDimensions() {
128
164
*/
129
165
public void putMetric (String key , double value , Unit unit , StorageResolution storageResolution )
130
166
throws InvalidMetricException {
131
- Validator .validateMetric (key , value , unit , storageResolution , metricNameAndResolutionMap );
132
- metricDirective .putMetric (key , value , unit , storageResolution );
133
- metricNameAndResolutionMap .put (key , storageResolution );
167
+ putMetric (key , value , unit , storageResolution , AggregationType .NONE );
134
168
}
169
+
135
170
/**
136
171
* Add a metric measurement to the context with a storage resolution but without a unit.
137
172
* Multiple calls using the same key will be stored as an array of scalar values.
@@ -147,7 +182,7 @@ public void putMetric(String key, double value, Unit unit, StorageResolution sto
147
182
*/
148
183
public void putMetric (String key , double value , StorageResolution storageResolution )
149
184
throws InvalidMetricException {
150
- putMetric (key , value , Unit .NONE , storageResolution );
185
+ putMetric (key , value , Unit .NONE , storageResolution , AggregationType . NONE );
151
186
}
152
187
153
188
/**
@@ -164,7 +199,67 @@ public void putMetric(String key, double value, StorageResolution storageResolut
164
199
* @throws InvalidMetricException if the metric is invalid
165
200
*/
166
201
public void putMetric (String key , double value , Unit unit ) throws InvalidMetricException {
167
- putMetric (key , value , unit , StorageResolution .STANDARD );
202
+ putMetric (key , value , unit , StorageResolution .STANDARD , AggregationType .NONE );
203
+ }
204
+
205
+ /**
206
+ * Add a metric measurement to the context without a unit Multiple calls using the same key will
207
+ * be stored as an array of scalar values.
208
+ *
209
+ * <pre>{@code
210
+ * metricContext.putMetric("Count", 10, AggregationType.NONE)
211
+ * }</pre>
212
+ *
213
+ * @param key Name of the metric
214
+ * @param value Value of the metric
215
+ * @param aggregationType The aggregation type of the metric
216
+ * @throws InvalidMetricException if the metric is invalid
217
+ */
218
+ public void putMetric (String key , double value , AggregationType aggregationType )
219
+ throws InvalidMetricException {
220
+ putMetric (key , value , Unit .NONE , StorageResolution .STANDARD , aggregationType );
221
+ }
222
+
223
+ /**
224
+ * Add a metric measurement to the context with a storage resolution but without a unit.
225
+ * Multiple calls using the same key will be stored as an array of scalar values.
226
+ *
227
+ * <pre>{@code
228
+ * metricContext.putMetric("Latency", 100, StorageResolution.HIGH, AggregationType.NONE)
229
+ * }</pre>
230
+ *
231
+ * @param key Name of the metric
232
+ * @param value Value of the metric
233
+ * @param storageResolution The resolution of the metric
234
+ * @param aggregationType The aggregation type of the metric
235
+ * @throws InvalidMetricException if the metric is invalid
236
+ */
237
+ public void putMetric (
238
+ String key ,
239
+ double value ,
240
+ StorageResolution storageResolution ,
241
+ AggregationType aggregationType )
242
+ throws InvalidMetricException {
243
+ putMetric (key , value , Unit .NONE , storageResolution , aggregationType );
244
+ }
245
+
246
+ /**
247
+ * Add a metric measurement to the context without a storage resolution. Multiple calls using
248
+ * the same key will be stored as an array of scalar values.
249
+ *
250
+ * <pre>{@code
251
+ * metricContext.putMetric("Latency", 100, Unit.MILLISECONDS, AggregationType.NONE)
252
+ * }</pre>
253
+ *
254
+ * @param key Name of the metric
255
+ * @param value Value of the metric
256
+ * @param unit The unit of the metric
257
+ * @param aggregationType The aggregation type of the metric
258
+ * @throws InvalidMetricException if the metric is invalid
259
+ */
260
+ public void putMetric (String key , double value , Unit unit , AggregationType aggregationType )
261
+ throws InvalidMetricException {
262
+ putMetric (key , value , unit , StorageResolution .STANDARD , aggregationType );
168
263
}
169
264
170
265
/**
@@ -180,7 +275,7 @@ public void putMetric(String key, double value, Unit unit) throws InvalidMetricE
180
275
* @throws InvalidMetricException if the metric is invalid
181
276
*/
182
277
public void putMetric (String key , double value ) throws InvalidMetricException {
183
- putMetric (key , value , Unit .NONE , StorageResolution .STANDARD );
278
+ putMetric (key , value , Unit .NONE , StorageResolution .STANDARD , AggregationType . NONE );
184
279
}
185
280
186
281
/**
0 commit comments