Search in sources :

Example 1 with CounterName

use of org.apache.beam.runners.dataflow.worker.counters.CounterName in project beam by apache.

the class ShuffleReadCounter method checkState.

@SuppressWarnings("ReferenceEquality")
@SuppressFBWarnings("ES_COMPARING_STRINGS_WITH_EQ")
private void checkState() {
    if (this.experimentEnabled) {
        ExecutionStateTracker.ExecutionState currentState = ExecutionStateTracker.getCurrentExecutionState();
        String currentStateName = null;
        if (currentState instanceof DataflowExecutionState) {
            currentStateName = ((DataflowExecutionState) currentState).getStepName().originalName();
        }
        if (this.currentCounter != null && currentStateName == this.currentCounter.getName().originalRequestingStepName()) {
            // If the step name of the state has not changed do not do another lookup.
            return;
        }
        CounterName name = ShuffleReadCounter.generateCounterName(this.originalShuffleStepName, currentStateName);
        this.currentCounter = this.counterSet.longSum(name);
    } else {
        this.currentCounter = this.legacyPerOperationPerDatasetBytesCounter;
    }
}
Also used : ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) DataflowExecutionState(org.apache.beam.runners.dataflow.worker.DataflowOperationContext.DataflowExecutionState) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with CounterName

use of org.apache.beam.runners.dataflow.worker.counters.CounterName in project beam by apache.

the class ApplianceShuffleCounters method importCounters.

/**
 * Invoked to import a set of counter deltas. All the arrays passed in as parameters are required
 * to have the same length.
 *
 * @param counterNames names of counters to import
 * @param counterKinds kinds of counters to import ("sum", "max", or "min")
 * @param counterDeltas counter deltas to import
 */
public void importCounters(String[] counterNames, String[] counterKinds, long[] counterDeltas) {
    final int length = counterNames.length;
    if (counterKinds.length != length || counterDeltas.length != length) {
        throw new AssertionError("array lengths do not match");
    }
    for (int i = 0; i < length; ++i) {
        final CounterName name = CounterName.named(counterPrefix + counterNames[i]);
        final String kind = counterKinds[i];
        final long delta = counterDeltas[i];
        switch(kind) {
            case "sum":
                counterFactory.longSum(name).addValue(delta);
                break;
            case "max":
                counterFactory.longMax(name).addValue(delta);
                break;
            case "min":
                counterFactory.longMin(name).addValue(delta);
                break;
            default:
                throw new IllegalArgumentException("unsupported counter kind: " + kind);
        }
    }
}
Also used : CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName)

Example 3 with CounterName

use of org.apache.beam.runners.dataflow.worker.counters.CounterName in project beam by apache.

the class DataflowCounterUpdateExtractorTest method testExtractStructuredNameWithIoInfo.

@Test
public void testExtractStructuredNameWithIoInfo() {
    CounterName counterName = CounterName.named(COUNTER_NAME).withOriginalRequestingStepName("stepReq").withInputIndex(1);
    Counter<?, ?> structuredOriginal = counterFactory.intSum(counterName);
    assertThat(structuredOriginal.extractUpdate(true, DataflowCounterUpdateExtractor.INSTANCE), hasStructuredName(counterName, "SUM"));
}
Also used : CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) NameContextsForTests.nameContextForTest(org.apache.beam.runners.dataflow.worker.NameContextsForTests.nameContextForTest) Test(org.junit.Test)

Example 4 with CounterName

use of org.apache.beam.runners.dataflow.worker.counters.CounterName in project beam by apache.

the class DataflowCounterUpdateExtractorTest method testExtractShuffleReadCounter.

@Test
public void testExtractShuffleReadCounter() {
    CounterName counterName = ShuffleReadCounter.generateCounterName("originalShuffleStepName", "originalExecutingStepName");
    Counter<?, ?> counter = counterFactory.longSum(counterName);
    counter.extractUpdate(true, DataflowCounterUpdateExtractor.INSTANCE);
    hasStructuredName(counterName, "SUM");
}
Also used : CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) NameContextsForTests.nameContextForTest(org.apache.beam.runners.dataflow.worker.NameContextsForTests.nameContextForTest) Test(org.junit.Test)

Example 5 with CounterName

use of org.apache.beam.runners.dataflow.worker.counters.CounterName in project beam by apache.

the class MapTaskExecutorTest method testPerElementProcessingTimeCounters.

/**
 * Verify counts for the per-element-output-time counter are correct.
 */
@Test
public void testPerElementProcessingTimeCounters() throws Exception {
    PipelineOptions options = PipelineOptionsFactory.create();
    options.as(DataflowPipelineDebugOptions.class).setExperiments(Lists.newArrayList(DataflowElementExecutionTracker.TIME_PER_ELEMENT_EXPERIMENT));
    ExecutionStateSampler stateSampler = ExecutionStateSampler.newForTest();
    DataflowExecutionStateTracker stateTracker = new DataflowExecutionStateTracker(stateSampler, new TestDataflowExecutionState(NameContext.forStage("test-stage"), "other", null, /* requestingStepName */
    null, /* sideInputIndex */
    null, /* metricsContainer */
    NoopProfileScope.NOOP), counterSet, options, "test-work-item-id");
    NameContext parDoName = nameForStep("s1");
    // Wire a read operation with 3 elements to a ParDoOperation and assert that we count
    // the correct number of elements.
    ReadOperation read = ReadOperation.forTest(new TestReader("a", "b", "c"), new OutputReceiver(), TestOperationContext.create(counterSet, nameForStep("s0"), null, stateTracker));
    ParDoOperation parDo = new ParDoOperation(new NoopParDoFn(), new OutputReceiver[0], TestOperationContext.create(counterSet, parDoName, null, stateTracker));
    parDo.attachInput(read, 0);
    List<Operation> operations = Lists.newArrayList(read, parDo);
    try (MapTaskExecutor executor = new MapTaskExecutor(operations, counterSet, stateTracker)) {
        executor.execute();
    }
    stateSampler.doSampling(100L);
    CounterName counterName = CounterName.named("per-element-processing-time").withOriginalName(parDoName);
    Counter<Long, CounterDistribution> counter = (Counter<Long, CounterDistribution>) counterSet.getExistingCounter(counterName);
    assertThat(counter.getAggregate().getCount(), equalTo(3L));
}
Also used : CounterDistribution(org.apache.beam.runners.dataflow.worker.counters.CounterFactory.CounterDistribution) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) TestReader(org.apache.beam.runners.dataflow.worker.util.common.worker.ExecutorTestUtils.TestReader) TestDataflowExecutionState(org.apache.beam.runners.dataflow.worker.TestOperationContext.TestDataflowExecutionState) Counter(org.apache.beam.runners.dataflow.worker.counters.Counter) CounterName(org.apache.beam.runners.dataflow.worker.counters.CounterName) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) DataflowPipelineDebugOptions(org.apache.beam.runners.dataflow.options.DataflowPipelineDebugOptions) DataflowExecutionStateTracker(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker) ExecutionStateSampler(org.apache.beam.runners.core.metrics.ExecutionStateSampler) Test(org.junit.Test)

Aggregations

CounterName (org.apache.beam.runners.dataflow.worker.counters.CounterName)12 Test (org.junit.Test)9 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)4 NameContextsForTests.nameContextForTest (org.apache.beam.runners.dataflow.worker.NameContextsForTests.nameContextForTest)4 CounterDistribution (org.apache.beam.runners.dataflow.worker.counters.CounterFactory.CounterDistribution)4 DataflowPipelineDebugOptions (org.apache.beam.runners.dataflow.options.DataflowPipelineDebugOptions)3 Counter (org.apache.beam.runners.dataflow.worker.counters.Counter)3 DataflowExecutionStateTracker (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker)2 DataflowExecutionState (org.apache.beam.runners.dataflow.worker.DataflowOperationContext.DataflowExecutionState)2 TestDataflowExecutionState (org.apache.beam.runners.dataflow.worker.TestOperationContext.TestDataflowExecutionState)2 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)2 TestReader (org.apache.beam.runners.dataflow.worker.util.common.worker.ExecutorTestUtils.TestReader)2 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)2 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)1 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)1 CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)1 Source (com.google.api.services.dataflow.model.Source)1 SplitInt64 (com.google.api.services.dataflow.model.SplitInt64)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Closeable (java.io.Closeable)1