Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-1672] Accumulable MetricsContainers. #2649

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean apply(@Nullable WindowedValue<V> input) {
.isBefore(timerInternals.currentInputWatermarkTime());
if (expired) {
// The element is too late for this window.
droppedDueToLateness.inc();
droppedDueToLateness.update(1L);
WindowTracing.debug(
"GroupAlsoByWindow: Dropping element at {} for key: {}; "
+ "window: {} since it is too far behind inputWatermark: {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
*/
package org.apache.beam.runners.flink;

import static org.apache.beam.sdk.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.apache.beam.runners.flink.metrics.FlinkMetricResults;
import org.apache.beam.runners.flink.metrics.FlinkMetricContainer;
import org.apache.beam.sdk.PipelineResult;
import org.apache.beam.sdk.metrics.MetricResults;
import org.apache.beam.sdk.metrics.MetricsContainerStepMap;
import org.joda.time.Duration;

/**
Expand Down Expand Up @@ -72,6 +75,7 @@ public State waitUntilFinish(Duration duration) {

@Override
public MetricResults metrics() {
return new FlinkMetricResults(accumulators);
return asAttemptedOnlyMetricResults(
(MetricsContainerStepMap) accumulators.get(FlinkMetricContainer.ACCUMULATOR_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@
*/
public class DoFnRunnerWithMetricsUpdate<InputT, OutputT> implements DoFnRunner<InputT, OutputT> {

private final String stepName;
private final FlinkMetricContainer container;
private final DoFnRunner<InputT, OutputT> delegate;

public DoFnRunnerWithMetricsUpdate(
String stepName,
DoFnRunner<InputT, OutputT> delegate,
RuntimeContext runtimeContext) {
this.stepName = stepName;
this.delegate = delegate;
container = new FlinkMetricContainer(stepName, runtimeContext);
container = new FlinkMetricContainer(runtimeContext);
}

@Override
public void startBundle() {
try (Closeable ignored =
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer())) {
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer(stepName))) {
delegate.startBundle();
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -58,7 +60,7 @@ public void startBundle() {
@Override
public void processElement(final WindowedValue<InputT> elem) {
try (Closeable ignored =
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer())) {
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer(stepName))) {
delegate.processElement(elem);
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -69,7 +71,7 @@ public void processElement(final WindowedValue<InputT> elem) {
public void onTimer(final String timerId, final BoundedWindow window, final Instant timestamp,
final TimeDomain timeDomain) {
try (Closeable ignored =
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer())) {
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer(stepName))) {
delegate.onTimer(timerId, window, timestamp, timeDomain);
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -79,7 +81,7 @@ public void onTimer(final String timerId, final BoundedWindow window, final Inst
@Override
public void finishBundle() {
try (Closeable ignored =
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer())) {
MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer(stepName))) {
delegate.finishBundle();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Loading