/** * Aggregate an incoming metric to the base aggregated metric with the given * operation state in a stateless fashion. The assumption here is * baseAggregatedMetric and latestMetric should be single value data if not * null. * * @param incomingMetric Incoming timeline metric to aggregate * @param baseAggregatedMetric Base timeline metric * @return Result metric after aggregation */ public static TimelineMetric aggregateTo(TimelineMetric incomingMetric, TimelineMetric baseAggregatedMetric) { return aggregateTo(incomingMetric, baseAggregatedMetric, null); }
TimelineMetric aggregatedMetric = TimelineMetric.aggregateTo(m1, null); assertEquals(10000L, aggregatedMetric.getSingleDataValue()); aggregatedMetric = TimelineMetric.aggregateTo(m2, aggregatedMetric); assertEquals(30000L, aggregatedMetric.getSingleDataValue()); TimelineMetric m2New = getSingleValueMetric("MEGA_BYTES_MILLIS", TimelineMetricOperation.SUM, ts, 10000L); aggregatedMetric = TimelineMetric.aggregateTo(m2New, aggregatedMetric, state); assertEquals(20000L, aggregatedMetric.getSingleDataValue()); TimelineMetric aggregatedMax = TimelineMetric.aggregateTo(m3, null); assertEquals(150L, aggregatedMax.getSingleDataValue()); aggregatedMax = TimelineMetric.aggregateTo(m4, aggregatedMax); assertEquals(170L, aggregatedMax.getSingleDataValue()); TimelineMetricOperation.AVG, ts, 150L); try { TimelineMetric.aggregateTo(m5, null); fail("Taking average among metrics is not supported! "); } catch (UnsupportedOperationException e) {