30
30
import software .amazon .cloudwatchlogs .emf .exception .InvalidMetricException ;
31
31
import software .amazon .cloudwatchlogs .emf .exception .InvalidNamespaceException ;
32
32
import software .amazon .cloudwatchlogs .emf .exception .InvalidTimestampException ;
33
+ import software .amazon .cloudwatchlogs .emf .model .AggregationType ;
33
34
import software .amazon .cloudwatchlogs .emf .model .DimensionSet ;
34
35
import software .amazon .cloudwatchlogs .emf .model .MetricsContext ;
35
36
import software .amazon .cloudwatchlogs .emf .model .StorageResolution ;
@@ -45,6 +46,7 @@ public class MetricsLogger {
45
46
private MetricsContext context ;
46
47
private CompletableFuture <Environment > environmentFuture ;
47
48
private EnvironmentProvider environmentProvider ;
49
+ @ Getter @ Setter private volatile AggregationType defaultAggregationType = AggregationType .NONE ;
48
50
/**
49
51
* This lock is used to create an internal sync context for flush() method in multi-threaded
50
52
* situations. Flush() acquires write lock, other methods (accessing mutable shared data with
@@ -191,18 +193,23 @@ public MetricsLogger resetDimensions(boolean useDefault) {
191
193
* @param value is the value of the metric
192
194
* @param unit is the unit of the metric value
193
195
* @param storageResolution is the resolution of the metric
196
+ * @param aggregationType is the aggregation type of the metric
194
197
* @see <a
195
198
* href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics">CloudWatch
196
199
* High Resolution Metrics</a>
197
200
* @return the current logger
198
201
* @throws InvalidMetricException if the metric is invalid
199
202
*/
200
203
public MetricsLogger putMetric (
201
- String key , double value , Unit unit , StorageResolution storageResolution )
204
+ String key ,
205
+ double value ,
206
+ Unit unit ,
207
+ StorageResolution storageResolution ,
208
+ AggregationType aggregationType )
202
209
throws InvalidMetricException {
203
210
rwl .readLock ().lock ();
204
211
try {
205
- this .context .putMetric (key , value , unit , storageResolution );
212
+ this .context .putMetric (key , value , unit , storageResolution , aggregationType );
206
213
return this ;
207
214
} finally {
208
215
rwl .readLock ().unlock ();
@@ -225,7 +232,7 @@ public MetricsLogger putMetric(
225
232
*/
226
233
public MetricsLogger putMetric (String key , double value , StorageResolution storageResolution )
227
234
throws InvalidMetricException {
228
- this .putMetric (key , value , Unit .NONE , storageResolution );
235
+ this .putMetric (key , value , Unit .NONE , storageResolution , defaultAggregationType );
229
236
return this ;
230
237
}
231
238
@@ -242,7 +249,7 @@ public MetricsLogger putMetric(String key, double value, StorageResolution stora
242
249
*/
243
250
public MetricsLogger putMetric (String key , double value , Unit unit )
244
251
throws InvalidMetricException {
245
- this .putMetric (key , value , unit , StorageResolution .STANDARD );
252
+ this .putMetric (key , value , unit , StorageResolution .STANDARD , defaultAggregationType );
246
253
return this ;
247
254
}
248
255
@@ -257,7 +264,90 @@ public MetricsLogger putMetric(String key, double value, Unit unit)
257
264
* @throws InvalidMetricException if the metric is invalid
258
265
*/
259
266
public MetricsLogger putMetric (String key , double value ) throws InvalidMetricException {
260
- this .putMetric (key , value , Unit .NONE , StorageResolution .STANDARD );
267
+ this .putMetric (key , value , Unit .NONE , StorageResolution .STANDARD , defaultAggregationType );
268
+ return this ;
269
+ }
270
+
271
+ /**
272
+ * Put a metric value. This value will be emitted to CloudWatch Metrics asynchronously and does
273
+ * not contribute to your account TPS limits. The value will also be available in your
274
+ * CloudWatch Logs
275
+ *
276
+ * @param key is the name of the metric
277
+ * @param value is the value of the metric
278
+ * @param unit is the unit of the metric value
279
+ * @param storageResolution is the resolution of the metric
280
+ * @see <a
281
+ * href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics">CloudWatch
282
+ * High Resolution Metrics</a>
283
+ * @return the current logger
284
+ * @throws InvalidMetricException if the metric is invalid
285
+ */
286
+ public MetricsLogger putMetric (
287
+ String key , double value , Unit unit , StorageResolution storageResolution )
288
+ throws InvalidMetricException {
289
+ this .putMetric (key , value , Unit .NONE , storageResolution , defaultAggregationType );
290
+ return this ;
291
+ }
292
+
293
+ /**
294
+ * Put a metric value. This value will be emitted to CloudWatch Metrics asynchronously and does
295
+ * not contribute to your account TPS limits. The value will also be available in your
296
+ * CloudWatch Logs
297
+ *
298
+ * @param key is the name of the metric
299
+ * @param value is the value of the metric
300
+ * @param storageResolution is the resolution of the metric
301
+ * @param aggregationType is the aggregation type of the metric
302
+ * @see <a
303
+ * href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics">CloudWatch
304
+ * High Resolution Metrics</a>
305
+ * @return the current logger
306
+ * @throws InvalidMetricException if the metric is invalid
307
+ */
308
+ public MetricsLogger putMetric (
309
+ String key ,
310
+ double value ,
311
+ StorageResolution storageResolution ,
312
+ AggregationType aggregationType )
313
+ throws InvalidMetricException {
314
+ this .putMetric (key , value , Unit .NONE , storageResolution , aggregationType );
315
+ return this ;
316
+ }
317
+
318
+ /**
319
+ * Put a metric value. This value will be emitted to CloudWatch Metrics asynchronously and does
320
+ * not contribute to your account TPS limits. The value will also be available in your
321
+ * CloudWatch Logs
322
+ *
323
+ * @param key is the name of the metric
324
+ * @param value is the value of the metric
325
+ * @param unit is the unit of the metric value
326
+ * @param aggregationType is the aggregation type of the metric
327
+ * @return the current logger
328
+ * @throws InvalidMetricException if the metric is invalid
329
+ */
330
+ public MetricsLogger putMetric (
331
+ String key , double value , Unit unit , AggregationType aggregationType )
332
+ throws InvalidMetricException {
333
+ this .putMetric (key , value , unit , StorageResolution .STANDARD , aggregationType );
334
+ return this ;
335
+ }
336
+
337
+ /**
338
+ * Put a metric value. This value will be emitted to CloudWatch Metrics asynchronously and does
339
+ * not contribute to your account TPS limits. The value will also be available in your
340
+ * CloudWatch Logs
341
+ *
342
+ * @param key the name of the metric
343
+ * @param value the value of the metric
344
+ * @param aggregationType is the aggregation type of the metric
345
+ * @return the current logger
346
+ * @throws InvalidMetricException if the metric is invalid
347
+ */
348
+ public MetricsLogger putMetric (String key , double value , AggregationType aggregationType )
349
+ throws InvalidMetricException {
350
+ this .putMetric (key , value , Unit .NONE , StorageResolution .STANDARD , aggregationType );
261
351
return this ;
262
352
}
263
353
0 commit comments