use of org.apache.beam.sdk.metrics.MetricQueryResults in project beam by apache.
the class DataflowMetricsTest method testMultipleCounterUpdates.
@Test
public void testMultipleCounterUpdates() throws IOException {
JobMetrics jobMetrics = new JobMetrics();
DataflowClient dataflowClient = mock(DataflowClient.class);
when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);
DataflowPipelineJob job = mock(DataflowPipelineJob.class);
when(job.getState()).thenReturn(State.RUNNING);
job.jobId = JOB_ID;
// The parser relies on the fact that one tentative and one committed metric update exist in
// the job metrics results.
jobMetrics.setMetrics(ImmutableList.of(makeCounterMetricUpdate("counterName", "counterNamespace", "s2", 1233L, false), makeCounterMetricUpdate("counterName", "counterNamespace", "s2", 1234L, true), makeCounterMetricUpdate("otherCounter", "otherNamespace", "s3", 12L, false), makeCounterMetricUpdate("otherCounter", "otherNamespace", "s3", 12L, true), makeCounterMetricUpdate("counterName", "otherNamespace", "s4", 1200L, false), makeCounterMetricUpdate("counterName", "otherNamespace", "s4", 1233L, true)));
DataflowMetrics dataflowMetrics = new DataflowMetrics(job, dataflowClient);
MetricQueryResults result = dataflowMetrics.queryMetrics(null);
assertThat(result.counters(), containsInAnyOrder(attemptedMetricsResult("counterNamespace", "counterName", "s2", 1234L), attemptedMetricsResult("otherNamespace", "otherCounter", "s3", 12L), attemptedMetricsResult("otherNamespace", "counterName", "s4", 1233L)));
assertThat(result.counters(), containsInAnyOrder(committedMetricsResult("counterNamespace", "counterName", "s2", 1233L), committedMetricsResult("otherNamespace", "otherCounter", "s3", 12L), committedMetricsResult("otherNamespace", "counterName", "s4", 1200L)));
}
use of org.apache.beam.sdk.metrics.MetricQueryResults in project beam by apache.
the class DataflowMetricsTest method testIgnoreDistributionButGetCounterUpdates.
@Test
public void testIgnoreDistributionButGetCounterUpdates() throws IOException {
JobMetrics jobMetrics = new JobMetrics();
DataflowClient dataflowClient = mock(DataflowClient.class);
when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);
DataflowPipelineJob job = mock(DataflowPipelineJob.class);
when(job.getState()).thenReturn(State.RUNNING);
job.jobId = JOB_ID;
// The parser relies on the fact that one tentative and one committed metric update exist in
// the job metrics results.
jobMetrics.setMetrics(ImmutableList.of(makeCounterMetricUpdate("counterName", "counterNamespace", "s2", 1233L, false), makeCounterMetricUpdate("counterName", "counterNamespace", "s2", 1234L, true), makeCounterMetricUpdate("otherCounter[MIN]", "otherNamespace", "s3", 0L, false), makeCounterMetricUpdate("otherCounter[MIN]", "otherNamespace", "s3", 0L, true)));
DataflowMetrics dataflowMetrics = new DataflowMetrics(job, dataflowClient);
MetricQueryResults result = dataflowMetrics.queryMetrics(null);
assertThat(result.counters(), containsInAnyOrder(attemptedMetricsResult("counterNamespace", "counterName", "s2", 1234L)));
assertThat(result.counters(), containsInAnyOrder(committedMetricsResult("counterNamespace", "counterName", "s2", 1233L)));
}
use of org.apache.beam.sdk.metrics.MetricQueryResults in project beam by apache.
the class DataflowMetricsTest method testEmptyMetricUpdates.
@Test
public void testEmptyMetricUpdates() throws IOException {
Job modelJob = new Job();
modelJob.setCurrentState(State.RUNNING.toString());
DataflowPipelineJob job = mock(DataflowPipelineJob.class);
when(job.getState()).thenReturn(State.RUNNING);
job.jobId = JOB_ID;
JobMetrics jobMetrics = new JobMetrics();
jobMetrics.setMetrics(null);
DataflowClient dataflowClient = mock(DataflowClient.class);
when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);
DataflowMetrics dataflowMetrics = new DataflowMetrics(job, dataflowClient);
MetricQueryResults result = dataflowMetrics.queryMetrics();
assertThat(ImmutableList.copyOf(result.counters()), is(empty()));
assertThat(ImmutableList.copyOf(result.distributions()), is(empty()));
}
use of org.apache.beam.sdk.metrics.MetricQueryResults in project beam by apache.
the class DataflowMetricsTest method testSingleCounterUpdates.
@Test
public void testSingleCounterUpdates() throws IOException {
JobMetrics jobMetrics = new JobMetrics();
DataflowPipelineJob job = mock(DataflowPipelineJob.class);
when(job.getState()).thenReturn(State.RUNNING);
job.jobId = JOB_ID;
MetricUpdate update = new MetricUpdate();
long stepValue = 1234L;
update.setScalar(new BigDecimal(stepValue));
// The parser relies on the fact that one tentative and one committed metric update exist in
// the job metrics results.
MetricUpdate mu1 = makeCounterMetricUpdate("counterName", "counterNamespace", "s2", 1234L, false);
MetricUpdate mu1Tentative = makeCounterMetricUpdate("counterName", "counterNamespace", "s2", 1233L, true);
jobMetrics.setMetrics(ImmutableList.of(mu1, mu1Tentative));
DataflowClient dataflowClient = mock(DataflowClient.class);
when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);
DataflowMetrics dataflowMetrics = new DataflowMetrics(job, dataflowClient);
MetricQueryResults result = dataflowMetrics.queryMetrics(null);
assertThat(result.counters(), containsInAnyOrder(attemptedMetricsResult("counterNamespace", "counterName", "s2", 1233L)));
assertThat(result.counters(), containsInAnyOrder(committedMetricsResult("counterNamespace", "counterName", "s2", 1234L)));
}
use of org.apache.beam.sdk.metrics.MetricQueryResults in project beam by apache.
the class MetricsContainerStepMapTest method testDistributionCommittedUnsupportedInAttemptedAccumulatedMetricResults.
@Test
public void testDistributionCommittedUnsupportedInAttemptedAccumulatedMetricResults() {
MetricsContainerStepMap attemptedMetrics = new MetricsContainerStepMap();
attemptedMetrics.update(STEP1, metricsContainer);
MetricResults metricResults = asAttemptedOnlyMetricResults(attemptedMetrics);
MetricQueryResults step1res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP1).build());
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("This runner does not currently support committed metrics results.");
assertDistribution(DISTRIBUTION_NAME, step1res, STEP1, DistributionResult.ZERO, true);
}
Aggregations