Search in sources :

Example 11 with CounterUpdate

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

the class SimpleParDoFnTest method testOutputsPerElementCounterDisabledViaExperiment.

// TODO: Remove once Distributions has shipped.
@Test
public void testOutputsPerElementCounterDisabledViaExperiment() throws Exception {
    DataflowPipelineDebugOptions debugOptions = options.as(DataflowPipelineDebugOptions.class);
    List<String> experiments = debugOptions.getExperiments();
    experiments.remove(SimpleParDoFn.OUTPUTS_PER_ELEMENT_EXPERIMENT);
    debugOptions.setExperiments(experiments);
    List<CounterUpdate> counterUpdates = executeParDoFnCounterTest(0);
    CounterName expectedName = CounterName.named("per-element-output-count").withOriginalName(stepContext.getNameContext());
    assertThat(counterUpdates, not(contains(hasStructuredName(expectedName, "DISTRIBUTION"))));
}
Also used : CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) DataflowPipelineDebugOptions(org.apache.beam.runners.dataflow.options.DataflowPipelineDebugOptions) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 12 with CounterUpdate

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

the class SimpleParDoFnTest method testOutputsPerElementCounter.

@Test
public void testOutputsPerElementCounter() throws Exception {
    int[] inputData = new int[] { 1, 2, 3, 4, 5 };
    CounterDistribution expectedDistribution = CounterDistribution.builder().minMax(1, 5).count(5).sum(1 + 2 + 3 + 4 + 5).sumOfSquares(1 + 4 + 9 + 16 + 25).buckets(1, Lists.newArrayList(1L, 3L, 1L)).build();
    List<CounterUpdate> counterUpdates = executeParDoFnCounterTest(inputData);
    CounterName expectedName = CounterName.named("per-element-output-count").withOriginalName(stepContext.getNameContext());
    assertThat(counterUpdates, contains(allOf(hasStructuredName(expectedName, "DISTRIBUTION"), hasDistribution(expectedDistribution))));
}
Also used : CounterDistribution(org.apache.beam.runners.dataflow.worker.counters.CounterFactory.CounterDistribution) CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 13 with CounterUpdate

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

the class IsmSideInputReaderTest method testIterableSideInputReadCounter.

@Test
public void testIterableSideInputReadCounter() throws Exception {
    // These are the expected msec and byte counters:
    CounterUpdate expectedSideInputMsecUpdate = new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.SUM.toString())).setName(new CounterStructuredName().setOrigin("SYSTEM").setName("read-sideinput-msecs").setOriginalStepName("originalName").setExecutionStepName("stageName").setOriginalRequestingStepName("originalName2").setInputIndex(1))).setCumulative(true).setInteger(new SplitInt64().setHighBits(0).setLowBits(0L));
    CounterName expectedCounterName = CounterName.named("read-sideinput-byte-count").withOriginalName(operationContext.nameContext()).withOrigin("SYSTEM").withOriginalRequestingStepName("originalName2").withInputIndex(1);
    // Test startup:
    Coder<WindowedValue<Long>> valueCoder = WindowedValue.getFullCoder(VarLongCoder.of(), GLOBAL_WINDOW_CODER);
    IsmRecordCoder<WindowedValue<Long>> ismCoder = IsmRecordCoder.of(1, 0, ImmutableList.of(GLOBAL_WINDOW_CODER, BigEndianLongCoder.of()), valueCoder);
    // Create a new state, which represents a step that receives the side input.
    DataflowExecutionState state2 = executionContext.getExecutionStateRegistry().getState(NameContext.create("stageName", "originalName2", "systemName2", "userName2"), "process", null, NoopProfileScope.NOOP);
    final List<KV<Long, WindowedValue<Long>>> firstElements = Arrays.asList(KV.of(0L, valueInGlobalWindow(0L)));
    final List<KV<Long, WindowedValue<Long>>> secondElements = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        secondElements.add(KV.of(i, valueInGlobalWindow(i * 10)));
    }
    final PCollectionView<Iterable<Long>> view = Pipeline.create().apply(Create.empty(VarLongCoder.of())).apply(View.asIterable());
    Source sourceA = initInputFile(fromKvsForList(firstElements), ismCoder);
    Source sourceB = initInputFile(fromKvsForList(secondElements), ismCoder);
    try (Closeable state2Closeable = executionContext.getExecutionStateTracker().enterState(state2)) {
        final IsmSideInputReader reader = serialSideInputReader(view.getTagInternal().getId(), sourceA, sourceB);
        // Store a strong reference to the returned value so that the logical reference
        // cache is not cleared for this test.
        Iterable<Long> value = reader.get(view, GlobalWindow.INSTANCE);
        verifyIterable(toValueList(concat(firstElements, secondElements)), value);
        // Assert that the same value reference was returned showing that it was cached.
        assertSame(reader.get(view, GlobalWindow.INSTANCE), value);
        Iterable<CounterUpdate> counterUpdates = executionContext.getExecutionStateRegistry().extractUpdates(true);
        assertThat(counterUpdates, hasItem(expectedSideInputMsecUpdate));
        Counter<?, ?> expectedCounter = counterFactory.getExistingCounter(expectedCounterName);
        assertNotNull(expectedCounter);
    }
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) SplitInt64(com.google.api.services.dataflow.model.SplitInt64) KV(org.apache.beam.sdk.values.KV) Source(com.google.api.services.dataflow.model.Source) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) DataflowExecutionState(org.apache.beam.runners.dataflow.worker.DataflowOperationContext.DataflowExecutionState) CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) WindowedValue(org.apache.beam.sdk.util.WindowedValue) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) Test(org.junit.Test)

Example 14 with CounterUpdate

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

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

the class DistributionCounterUpdateAggregatorTest method testAggregate.

@Test
public void testAggregate() {
    CounterUpdate combined = aggregator.aggregate(counterUpdates);
    assertEquals(45L, splitIntToLong(combined.getDistribution().getSum()));
    assertEquals(10L, splitIntToLong(combined.getDistribution().getCount()));
    assertEquals(9L, splitIntToLong(combined.getDistribution().getMax()));
    assertEquals(0L, splitIntToLong(combined.getDistribution().getMin()));
}
Also used : CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Aggregations

CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)51 Test (org.junit.Test)33 CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)18 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)16 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)12 HashMap (java.util.HashMap)10 WorkItemStatus (com.google.api.services.dataflow.model.WorkItemStatus)9 ArrayList (java.util.ArrayList)9 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)7 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)7 DistributionUpdate (com.google.api.services.dataflow.model.DistributionUpdate)6 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 NameAndKind (com.google.api.services.dataflow.model.NameAndKind)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 DataflowCounterUpdateExtractor.splitIntToLong (org.apache.beam.runners.dataflow.worker.counters.DataflowCounterUpdateExtractor.splitIntToLong)5 WorkItemCommitRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.WorkItemCommitRequest)4 IntegerMean (com.google.api.services.dataflow.model.IntegerMean)3 List (java.util.List)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3