Skip to content
Merged
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 @@ -217,7 +217,7 @@ public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
return new QueryResults(filter);
}

private class QueryResults implements MetricQueryResults {
private class QueryResults extends MetricQueryResults {
private final MetricsFilter filter;

private QueryResults(MetricsFilter filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static java.util.Arrays.asList;

import com.google.auto.value.AutoValue;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -39,7 +38,6 @@
import org.apache.beam.runners.core.metrics.MetricsMap;
import org.apache.beam.sdk.metrics.DistributionResult;
import org.apache.beam.sdk.metrics.GaugeResult;
import org.apache.beam.sdk.metrics.MetricName;
import org.apache.beam.sdk.metrics.MetricQueryResults;
import org.apache.beam.sdk.metrics.MetricResult;
import org.apache.beam.sdk.metrics.MetricResults;
Expand Down Expand Up @@ -224,38 +222,6 @@ public GaugeResult extract(GaugeData data) {

private final MetricsMap<MetricKey, DirectMetric<GaugeData, GaugeResult>> gauges;

@AutoValue
abstract static class DirectMetricQueryResults implements MetricQueryResults {
public static MetricQueryResults create(
Iterable<MetricResult<Long>> counters,
Iterable<MetricResult<DistributionResult>> distributions,
Iterable<MetricResult<GaugeResult>> gauges) {
return new AutoValue_DirectMetrics_DirectMetricQueryResults(counters, distributions, gauges);
}
}

@AutoValue
abstract static class DirectMetricResult<T> implements MetricResult<T> {
// need to define these here so they appear in the correct order
// and the generated constructor is usable and consistent
@Override
public abstract MetricName getName();

@Override
public abstract String getStep();

@Override
public abstract T getCommitted();

@Override
public abstract T getAttempted();

public static <T> MetricResult<T> create(
MetricName name, String scope, T committed, T attempted) {
return new AutoValue_DirectMetrics_DirectMetricResult<>(name, scope, committed, attempted);
}
}

DirectMetrics(ExecutorService executorService) {
this.counters = new MetricsMap<>(unusedKey -> new DirectMetric<>(COUNTER, executorService));
this.distributions =
Expand All @@ -280,7 +246,7 @@ public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
maybeExtractResult(filter, gaugeResults, gauge);
}

return DirectMetricQueryResults.create(
return MetricQueryResults.create(
counterResults.build(), distributionResults.build(), gaugeResults.build());
}

Expand All @@ -290,7 +256,7 @@ private <ResultT> void maybeExtractResult(
Map.Entry<MetricKey, ? extends DirectMetric<?, ResultT>> entry) {
if (MetricFiltering.matches(filter, entry.getKey())) {
resultsBuilder.add(
DirectMetricResult.create(
MetricResult.create(
entry.getKey().metricName(),
entry.getKey().stepName(),
entry.getValue().extractCommitted(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static java.util.Arrays.asList;

import com.google.auto.value.AutoValue;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -39,7 +38,6 @@
import org.apache.beam.runners.core.metrics.MetricsMap;
import org.apache.beam.sdk.metrics.DistributionResult;
import org.apache.beam.sdk.metrics.GaugeResult;
import org.apache.beam.sdk.metrics.MetricName;
import org.apache.beam.sdk.metrics.MetricQueryResults;
import org.apache.beam.sdk.metrics.MetricResult;
import org.apache.beam.sdk.metrics.MetricResults;
Expand Down Expand Up @@ -235,38 +233,6 @@ public GaugeResult extract(GaugeData data) {
private MetricsMap<MetricKey, DirectMetric<GaugeData, GaugeResult>> gauges =
new MetricsMap<>(unusedKey -> new DirectMetric<>(GAUGE));

@AutoValue
abstract static class DirectMetricQueryResults implements MetricQueryResults {
public static MetricQueryResults create(
Iterable<MetricResult<Long>> counters,
Iterable<MetricResult<DistributionResult>> distributions,
Iterable<MetricResult<GaugeResult>> gauges) {
return new AutoValue_DirectMetrics_DirectMetricQueryResults(counters, distributions, gauges);
}
}

@AutoValue
abstract static class DirectMetricResult<T> implements MetricResult<T> {
// need to define these here so they appear in the correct order
// and the generated constructor is usable and consistent
@Override
public abstract MetricName getName();

@Override
public abstract String getStep();

@Override
public abstract T getCommitted();

@Override
public abstract T getAttempted();

public static <T> MetricResult<T> create(
MetricName name, String scope, T committed, T attempted) {
return new AutoValue_DirectMetrics_DirectMetricResult<>(name, scope, committed, attempted);
}
}

@Override
public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
ImmutableList.Builder<MetricResult<Long>> counterResults = ImmutableList.builder();
Expand All @@ -284,7 +250,7 @@ public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
maybeExtractResult(filter, gaugeResults, gauge);
}

return DirectMetricQueryResults.create(
return MetricQueryResults.create(
counterResults.build(), distributionResults.build(), gaugeResults.build());
}

Expand All @@ -294,7 +260,7 @@ private <ResultT> void maybeExtractResult(
Map.Entry<MetricKey, ? extends DirectMetric<?, ResultT>> entry) {
if (MetricFiltering.matches(filter, entry.getKey())) {
resultsBuilder.add(
DirectMetricResult.create(
MetricResult.create(
entry.getKey().metricName(),
entry.getKey().stepName(),
entry.getValue().extractCommitted(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.joda.time.Instant;

/** Test class to be used as a input to {@link MetricsSink} implementations tests. */
class CustomMetricQueryResults implements MetricQueryResults {
class CustomMetricQueryResults extends MetricQueryResults {

private final boolean isCommittedSupported;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
jobMetrics = getJobMetrics();
} catch (IOException e) {
LOG.warn("Unable to query job metrics.\n");
return DataflowMetricQueryResults.create(counters, distributions, gauges);
return MetricQueryResults.create(counters, distributions, gauges);
}
metricUpdates = firstNonNull(jobMetrics.getMetrics(), Collections.<MetricUpdate>emptyList());
return populateMetricQueryResults(metricUpdates, filter);
Expand Down Expand Up @@ -322,24 +322,13 @@ public MetricQueryResults build() {
extractor.addMetricResult(
metricKey, committedByName.get(metricKey), tentativeByName.get(metricKey));
}
return DataflowMetricQueryResults.create(
return MetricQueryResults.create(
extractor.getCounterResults(),
extractor.getDistributionResults(),
extractor.getGaugeResults());
}
}

@AutoValue
abstract static class DataflowMetricQueryResults implements MetricQueryResults {
public static MetricQueryResults create(
Iterable<MetricResult<Long>> counters,
Iterable<MetricResult<DistributionResult>> distributions,
Iterable<MetricResult<GaugeResult>> gauges) {
return new AutoValue_DataflowMetrics_DataflowMetricQueryResults(
counters, distributions, gauges);
}
}

@AutoValue
abstract static class DataflowMetricResult<T> implements MetricResult<T> {
// need to define these here so they appear in the correct order
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.beam.sdk.metrics;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.google.auto.value.AutoValue;
import org.apache.beam.sdk.annotations.Experimental;
import org.apache.beam.sdk.annotations.Experimental.Kind;

/** The results of a single current metric. */
@Experimental(Kind.METRICS)
@JsonFilter("committedMetrics")
@AutoValue
public abstract class DefaultMetricResult<T> implements MetricResult<T> {
@Override
public abstract MetricName getName();

@Override
public abstract String getStep();

@Override
public abstract T getCommitted();

@Override
public abstract T getAttempted();

public static <T> DefaultMetricResult<T> create(
MetricName name, String step, T committed, T attempted) {
return new AutoValue_DefaultMetricResult<>(name, step, committed, attempted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@
*/
package org.apache.beam.sdk.metrics;

import com.google.auto.value.AutoValue;
import org.apache.beam.sdk.annotations.Experimental;
import org.apache.beam.sdk.annotations.Experimental.Kind;

/**
* The results of a query for metrics. Allows accessing all of the metrics that matched the filter.
*/
@AutoValue
@Experimental(Kind.METRICS)
public interface MetricQueryResults {
/** Return the metric results for the counters that matched the filter. */
Iterable<MetricResult<Long>> getCounters();
public abstract class MetricQueryResults {
/** Return the metric results for the getCounters that matched the filter. */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed this getCounters comment typo (and similar below); I put a fix here in #7641 for now: 6a21a6b

public abstract Iterable<MetricResult<Long>> getCounters();

/** Return the metric results for the distributions that matched the filter. */
Iterable<MetricResult<DistributionResult>> getDistributions();
/** Return the metric results for the getDistributions that matched the filter. */
public abstract Iterable<MetricResult<DistributionResult>> getDistributions();

/** Return the metric results for the gauges that matched the filter. */
Iterable<MetricResult<GaugeResult>> getGauges();
/** Return the metric results for the getGauges that matched the filter. */
public abstract Iterable<MetricResult<GaugeResult>> getGauges();

public static MetricQueryResults create(
Iterable<MetricResult<Long>> counters,
Iterable<MetricResult<DistributionResult>> distributions,
Iterable<MetricResult<GaugeResult>> gauges) {
return new AutoValue_MetricQueryResults(counters, distributions, gauges);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public interface MetricResult<T> {
/** Return the name of the metric. */
MetricName getName();

/** Return the step context to which this metric result applies. */
String getStep();

Expand All @@ -43,4 +44,8 @@ public interface MetricResult<T> {

/** Return the value of this metric across all attempts of executing all parts of the pipeline. */
T getAttempted();

static <T> DefaultMetricResult<T> create(MetricName name, String step, T committed, T attempted) {
return new AutoValue_DefaultMetricResult<>(name, step, committed, attempted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class MetricResults {
* .addNameFilter("my-counter")
* .addStepFilter("myStepName1").addStepFilter("myStepName2")
* .build());
* Iterable<MetricResult<Long>> counters = metricResults.counters();
* Iterable<MetricResult<Long>> counters = metricResults.getCounters();
* // counters should contain the value of my-counter reported from each of the ParDo
* // applications.
* }</pre>
Expand Down