Search in sources :

Example 6 with CounterStructuredNameAndMetadata

use of com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata in project beam by apache.

the class DistributionCounterUpdateAggregatorTest method setUp.

@Before
public void setUp() {
    counterUpdates = new ArrayList<>();
    aggregator = new DistributionCounterUpdateAggregator();
    for (int i = 0; i < 10; i++) {
        counterUpdates.add(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.MEAN.toString()))).setDistribution(new DistributionUpdate().setSum(longToSplitInt((long) i)).setMax(longToSplitInt((long) i)).setMin(longToSplitInt((long) i)).setCount(longToSplitInt((long) 1))));
    }
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) DistributionUpdate(com.google.api.services.dataflow.model.DistributionUpdate) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Before(org.junit.Before)

Example 7 with CounterStructuredNameAndMetadata

use of com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata 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 8 with CounterStructuredNameAndMetadata

use of com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata in project beam by apache.

the class WorkItemStatusClientTest method populateCounterUpdatesWithMsecCounter.

@Test
public void populateCounterUpdatesWithMsecCounter() throws Exception {
    final CounterUpdate expectedMsec = new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin("SYSTEM").setName("start-msecs").setOriginalStepName("step")).setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()))).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(42));
    BatchModeExecutionContext context = mock(BatchModeExecutionContext.class);
    when(context.extractMetricUpdates(anyBoolean())).thenReturn(ImmutableList.of());
    when(context.extractMsecCounters(anyBoolean())).thenReturn(ImmutableList.of(expectedMsec));
    WorkItemStatus status = new WorkItemStatus();
    when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
    statusClient.setWorker(worker, context);
    statusClient.populateCounterUpdates(status);
    assertThat(status.getCounterUpdates(), containsInAnyOrder(expectedMsec));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 9 with CounterStructuredNameAndMetadata

use of com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata in project beam by apache.

the class WorkItemStatusClientTest method populateCounterUpdatesWithMetricsAndCounters.

/**
 * Validates that Beam Metrics and "internal" Counters are merged in the update.
 */
@Test
public void populateCounterUpdatesWithMetricsAndCounters() throws Exception {
    final CounterUpdate expectedCounter = new CounterUpdate().setNameAndKind(new NameAndKind().setName("some-counter").setKind(Kind.SUM.toString())).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(42));
    CounterSet counterSet = new CounterSet();
    counterSet.intSum(CounterName.named("some-counter")).addValue(42);
    final CounterUpdate expectedMetric = new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin("USER").setOriginNamespace("namespace").setName("some-counter").setOriginalStepName("step")).setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()))).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(42));
    MetricsContainerImpl metricsContainer = new MetricsContainerImpl("step");
    BatchModeExecutionContext context = mock(BatchModeExecutionContext.class);
    when(context.extractMetricUpdates(anyBoolean())).thenReturn(ImmutableList.of(expectedMetric));
    when(context.extractMsecCounters(anyBoolean())).thenReturn(Collections.emptyList());
    CounterCell counter = metricsContainer.getCounter(MetricName.named("namespace", "some-counter"));
    counter.inc(1);
    counter.inc(41);
    counter.inc(1);
    counter.inc(-1);
    WorkItemStatus status = new WorkItemStatus();
    when(worker.getOutputCounters()).thenReturn(counterSet);
    when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
    statusClient.setWorker(worker, context);
    statusClient.populateCounterUpdates(status);
    assertThat(status.getCounterUpdates(), containsInAnyOrder(expectedCounter, expectedMetric));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) CounterCell(org.apache.beam.runners.core.metrics.CounterCell) WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) CounterSet(org.apache.beam.runners.dataflow.worker.counters.CounterSet) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) NameAndKind(com.google.api.services.dataflow.model.NameAndKind) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 10 with CounterStructuredNameAndMetadata

use of com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata in project beam by apache.

the class DataflowCounterUpdateExtractor method getStructuredName.

private CounterStructuredNameAndMetadata getStructuredName(CounterName name, String kind) {
    CounterMetadata metadata = new CounterMetadata();
    metadata.setKind(kind);
    CounterStructuredName structuredName = new CounterStructuredName();
    structuredName.setName(name.name());
    if (name.usesContextOriginalName()) {
        structuredName.setOriginalStepName(name.contextOriginalName());
    } else if (name.usesContextSystemName()) {
        structuredName.setComponentStepName(name.contextSystemName());
    }
    if (name.originalRequestingStepName() != null) {
        structuredName.setOriginalRequestingStepName(name.originalRequestingStepName());
    }
    if (name.inputIndex() != null && name.inputIndex() > 0) {
        structuredName.setInputIndex(name.inputIndex());
    }
    CounterStructuredNameAndMetadata nameAndMetadata = new CounterStructuredNameAndMetadata();
    nameAndMetadata.setMetadata(metadata);
    nameAndMetadata.setName(structuredName);
    return nameAndMetadata;
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)

Aggregations

CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)20 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)18 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)18 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)13 Test (org.junit.Test)10 DistributionUpdate (com.google.api.services.dataflow.model.DistributionUpdate)6 ArrayList (java.util.ArrayList)4 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 Before (org.junit.Before)3 IntegerMean (com.google.api.services.dataflow.model.IntegerMean)2 WorkItemStatus (com.google.api.services.dataflow.model.WorkItemStatus)2 Distribution (org.apache.beam.sdk.metrics.Distribution)2 NameAndKind (com.google.api.services.dataflow.model.NameAndKind)1 Source (com.google.api.services.dataflow.model.Source)1 SplitInt64 (com.google.api.services.dataflow.model.SplitInt64)1 Closeable (java.io.Closeable)1 CounterCell (org.apache.beam.runners.core.metrics.CounterCell)1 DistributionData (org.apache.beam.runners.core.metrics.DistributionData)1 MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)1