Search in sources :

Example 11 with MetricQueryResults

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)));
}
Also used : MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) JobMetrics(com.google.api.services.dataflow.model.JobMetrics) Test(org.junit.Test)

Example 12 with MetricQueryResults

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)));
}
Also used : MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) JobMetrics(com.google.api.services.dataflow.model.JobMetrics) Test(org.junit.Test)

Example 13 with MetricQueryResults

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()));
}
Also used : MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Job(com.google.api.services.dataflow.model.Job) JobMetrics(com.google.api.services.dataflow.model.JobMetrics) Test(org.junit.Test)

Example 14 with MetricQueryResults

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)));
}
Also used : MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) MetricUpdate(com.google.api.services.dataflow.model.MetricUpdate) JobMetrics(com.google.api.services.dataflow.model.JobMetrics) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 15 with MetricQueryResults

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);
}
Also used : MetricsContainerStepMap.asMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Test(org.junit.Test)

Aggregations

MetricQueryResults (org.apache.beam.sdk.metrics.MetricQueryResults)18 Test (org.junit.Test)16 MetricsContainerStepMap.asAttemptedOnlyMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults)7 MetricResults (org.apache.beam.sdk.metrics.MetricResults)7 MetricsContainerStepMap.asMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults)5 JobMetrics (com.google.api.services.dataflow.model.JobMetrics)4 MetricUpdate (org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate)3 PipelineResult (org.apache.beam.sdk.PipelineResult)3 GaugeResult (org.apache.beam.sdk.metrics.GaugeResult)2 MetricName (org.apache.beam.sdk.metrics.MetricName)2 Job (com.google.api.services.dataflow.model.Job)1 MetricUpdate (com.google.api.services.dataflow.model.MetricUpdate)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 StreamingTest (org.apache.beam.runners.spark.StreamingTest)1 DistributionResult (org.apache.beam.sdk.metrics.DistributionResult)1 MetricResult (org.apache.beam.sdk.metrics.MetricResult)1 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)1 Category (org.junit.experimental.categories.Category)1