use of com.google.api.services.dataflow.model.IntegerMean in project beam by apache.
the class CounterUpdateAggregatorsTest method testAggregateMean.
@Test
public void testAggregateMean() {
List<CounterUpdate> meanUpdates = new ArrayList<>();
for (int i = 0; i < 10; i++) {
meanUpdates.add(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.MEAN.toString()))).setIntegerMean(new IntegerMean().setSum(longToSplitInt((long) i)).setCount(longToSplitInt(1L))));
}
List<CounterUpdate> aggregated = CounterUpdateAggregators.aggregate(meanUpdates);
assertEquals(1, aggregated.size());
CounterUpdate combined = aggregated.get(0);
assertEquals(45L, splitIntToLong(combined.getIntegerMean().getSum()));
assertEquals(10L, splitIntToLong(combined.getIntegerMean().getCount()));
}
use of com.google.api.services.dataflow.model.IntegerMean in project beam by apache.
the class MeanByteCountMonitoringInfoToCounterUpdateTransformer method transform.
/**
* Generates CounterUpdate to send to DFE based on ElementCount MonitoringInfo.
*
* @param monitoringInfo Monitoring info to transform.
* @return CounterUpdate generated based on provided monitoringInfo
*/
@Override
@Nullable
public CounterUpdate transform(MonitoringInfo monitoringInfo) {
Optional<String> validationResult = validate(monitoringInfo);
if (validationResult.isPresent()) {
LOG.debug(validationResult.get());
return null;
}
DistributionData data = decodeInt64Distribution(monitoringInfo.getPayload());
final String pcollectionId = monitoringInfo.getLabelsMap().get(MonitoringInfoConstants.Labels.PCOLLECTION);
final String pcollectionName = pcollectionIdToNameContext.get(pcollectionId).userName();
String counterName = pcollectionName + "-MeanByteCount";
NameAndKind name = new NameAndKind();
name.setName(counterName).setKind(Kind.MEAN.toString());
return new CounterUpdate().setNameAndKind(name).setCumulative(true).setIntegerMean(new IntegerMean().setSum(longToSplitInt(data.sum())).setCount(longToSplitInt(data.count())));
}
use of com.google.api.services.dataflow.model.IntegerMean in project beam by apache.
the class MeanCounterUpdateAggregatorTest method setUp.
@Before
public void setUp() {
counterUpdates = new ArrayList<>();
aggregator = new MeanCounterUpdateAggregator();
for (int i = 0; i < 10; i++) {
counterUpdates.add(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.MEAN.toString()))).setIntegerMean(new IntegerMean().setSum(longToSplitInt((long) i)).setCount(longToSplitInt(1L))));
}
}
Aggregations