Search in sources :

Example 1 with IntegerMean

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()));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) IntegerMean(com.google.api.services.dataflow.model.IntegerMean) ArrayList(java.util.ArrayList) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 2 with IntegerMean

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())));
}
Also used : DistributionData(org.apache.beam.runners.core.metrics.DistributionData) IntegerMean(com.google.api.services.dataflow.model.IntegerMean) NameAndKind(com.google.api.services.dataflow.model.NameAndKind) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 3 with IntegerMean

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))));
    }
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) IntegerMean(com.google.api.services.dataflow.model.IntegerMean) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Before(org.junit.Before)

Aggregations

CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)3 IntegerMean (com.google.api.services.dataflow.model.IntegerMean)3 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)2 CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)2 NameAndKind (com.google.api.services.dataflow.model.NameAndKind)1 ArrayList (java.util.ArrayList)1 DistributionData (org.apache.beam.runners.core.metrics.DistributionData)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Before (org.junit.Before)1 Test (org.junit.Test)1