in metrics-core/src/main/java/software/amazon/swage/metrics/record/cloudwatch/MetricDataAggregator.java [110:133]
public List<MetricDatum> flush() {
if (statisticsMap.size() == 0) {
return Collections.emptyList();
}
// Capture all the current metrics, as represented by the set of keys
// at this time in the statisticsMap.
// Note that this iterates over the key set of the underlying map, and
// removes keys from the map at the same time. It is possible keys may
// be added during this iteration, or data for keys modified between
// a key being chosen for iteration and being removed from the map.
// This is ok. Any new keys will be picked up on subsequent flushes.
//TODO: use two maps and swap between, to ensure 'perfect' segmentation?
List<MetricDatum> metricData = new ArrayList<>();
for (DatumKey key : statisticsMap.keySet()) {
StatisticSet value = statisticsMap.remove(key);
//TODO: better to have no timestamp at all?
MetricDatum metricDatum = key.getDatum().withTimestamp(Date.from(Instant.now()))
.withStatisticValues(value);
metricData.add(metricDatum);
}
return metricData;
}