Repository: beam Updated Branches: refs/heads/master d54ace4f3 -> 4ab74bf74
[BEAM-2017] Fix NPE in DataflowRunner when there are no metrics Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/4c28c99c Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/4c28c99c Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/4c28c99c Branch: refs/heads/master Commit: 4c28c99cac26c1ec42b9bc9d20a03e53c43b1a7c Parents: d54ace4 Author: Dan Halperin <dhalp...@google.com> Authored: Wed Apr 19 12:13:59 2017 -0700 Committer: Dan Halperin <dhalp...@google.com> Committed: Wed Apr 19 14:19:49 2017 -0700 ---------------------------------------------------------------------- .../org/apache/beam/runners/dataflow/DataflowMetrics.java | 7 ++++++- .../org/apache/beam/runners/dataflow/DataflowMetricsTest.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/4c28c99c/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowMetrics.java ---------------------------------------------------------------------- diff --git a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowMetrics.java b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowMetrics.java index 9d28ef6..d4d29dd 100644 --- a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowMetrics.java +++ b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowMetrics.java @@ -17,11 +17,14 @@ */ package org.apache.beam.runners.dataflow; +import static com.google.common.base.MoreObjects.firstNonNull; + import com.google.api.services.dataflow.model.JobMetrics; import com.google.auto.value.AutoValue; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -169,7 +172,9 @@ class DataflowMetrics extends MetricResults { LOG.warn("Unable to query job metrics.\n"); return DataflowMetricQueryResults.create(counters, distributions, gauges); } - metricUpdates = jobMetrics.getMetrics(); + metricUpdates = firstNonNull( + jobMetrics.getMetrics(), + Collections.<com.google.api.services.dataflow.model.MetricUpdate>emptyList()); return populateMetricQueryResults(metricUpdates, filter); } http://git-wip-us.apache.org/repos/asf/beam/blob/4c28c99c/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowMetricsTest.java ---------------------------------------------------------------------- diff --git a/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowMetricsTest.java b/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowMetricsTest.java index 1017978..ddb719c 100644 --- a/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowMetricsTest.java +++ b/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowMetricsTest.java @@ -98,7 +98,7 @@ public class DataflowMetricsTest { job.jobId = JOB_ID; JobMetrics jobMetrics = new JobMetrics(); - jobMetrics.setMetrics(ImmutableList.<MetricUpdate>of()); + jobMetrics.setMetrics(null /* this is how the APIs represent empty metrics */); DataflowClient dataflowClient = mock(DataflowClient.class); when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);