Skip to content

Commit 6077a6c

Browse files
committed
Added Aggregation Methods to the README
1 parent 6ef1216 commit 6077a6c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,42 @@ Thread-safety for the second use case is achieved by using a ReentrantReadWriteL
409409
With all the internal synchronization measures, however, there're still certain multi-threading use cases that are not covered by this library, which might require external synchronizations or other protection measures.
410410
This is due to the fact that the execution order of APIs are not determined in async contexts. For example, if user needs to associate a given set of properties with a metric in each thread, the results are not guaranteed since the execution order of `putProperty()` is not determined across threads. In such cases, we recommend using a different MetricsLogger instance for different threads, so that no resources are shared and no thread-safety problem would ever happen. Note that this can often be simplified by using a ThreadLocal variable.
411411

412+
## Aggregation
413+
414+
### Built in Aggregation
415+
416+
There are 3 types of aggregation implemented in this library: List, Statistic Sets, and Histograms.
417+
418+
- List reports all values added to a metrics as a list of values.
419+
- Statistic Sets only reports the maximum, minimum, sum, and count of values added to a metric.
420+
- Histograms use the Sparse Exponential Histogram Algorithm (SEH) to place each value added to a metric into a bin which keeps track of how many values have been added it. A histogram will report the bin values, the count of values in each bin, and a statistic set about the provided values. Note: SEH only accepts values greater than 0
421+
422+
There are several ways to set the aggregation type of a metric:
423+
1. Use the `AggregationType` parameter when calling `putMetric` on `MetricsLogger`
424+
```
425+
MetricsLogger logger = new MetricsLogger();
426+
logger.putMetric("metric", 1, AggregationType.Histogram);
427+
```
428+
2. By default, `MetricsLogger` will set all metrics that are added using `putMetric` without specificying an aggregation type to use List aggregation. This default behaviour can be changed to any of the other aggregation types by using a setter (it is recommended that this be done before any metrics are added to the logger because trying to change the aggregation type of an exist log with throw an error):
429+
```
430+
MetricsLogger logger = new MetricsLogger();
431+
logger.setDefaultAggregationType(AggregationType.StatisticSet);
432+
```
433+
434+
### Custom Histograms
435+
436+
Custom histograms can also be created if the sparse exponential histogram algorithm is not the best for the given data. To do this use the `HistogramMetric` class.
437+
438+
```
439+
ArrayList<Double> values = Arrays.asList(1, 1234, 7, 100);
440+
ArrayList<Integer> counts = Arrays.asList(1, 2, 7, 10);
441+
442+
HistogramMetric histogram = HistogramMetric(values, counts);
443+
444+
MetricsLogger logger = new MetricsLogger();
445+
logger.setMetric("myHistogram", histogram);
446+
```
447+
412448
## Examples
413449

414450
Check out the [examples](https://github.com/awslabs/aws-embedded-metrics-java/tree/master/examples) directory to get started.

src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDefinition.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.LinkedList;
2121
import java.util.List;
2222
import java.util.Queue;
23-
2423
import lombok.NonNull;
2524
import software.amazon.cloudwatchlogs.emf.Constants;
2625

@@ -69,7 +68,7 @@ private MetricDefinition getFirstMetricBatch(int batchSize) {
6968
}
7069

7170
private MetricDefinition getRemainingMetricBatch(int batchSize) {
72-
if (batchSize >= values.size()) {
71+
if (batchSize > values.size()) {
7372
return null;
7473
}
7574
List<Double> subList = values.subList(batchSize, values.size());

0 commit comments

Comments
 (0)