Search in sources :

Example 1 with MetricKey

use of org.apache.beam.sdk.metrics.MetricKey in project flink by apache.

the class FlinkMetricContainerTest method testGetFlinkMetricIdentifierString.

@Test
public void testGetFlinkMetricIdentifierString() {
    MetricKey key = MetricKey.create("step", MetricName.named(DEFAULT_NAMESPACE, "name"));
    assertThat(FlinkMetricContainer.getFlinkMetricIdentifierString(key), is("key.value.name"));
}
Also used : MetricKey(org.apache.beam.sdk.metrics.MetricKey) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 2 with MetricKey

use of org.apache.beam.sdk.metrics.MetricKey in project beam by apache.

the class SparkBeamMetric method renderName.

@VisibleForTesting
String renderName(MetricResult<?> metricResult) {
    MetricKey key = metricResult.getKey();
    MetricName name = key.metricName();
    String step = key.stepName();
    ArrayList<String> pieces = new ArrayList<>();
    if (step != null) {
        step = step.replaceAll(ILLEGAL_CHARACTERS, "_");
        if (step.endsWith("_")) {
            step = step.substring(0, step.length() - 1);
        }
        pieces.add(step);
    }
    pieces.addAll(ImmutableList.of(name.getNamespace(), name.getName()).stream().map(str -> str.replaceAll(ILLEGAL_CHARACTERS, "_")).collect(toList()));
    return String.join(".", pieces);
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MetricKey(org.apache.beam.sdk.metrics.MetricKey) ArrayList(java.util.ArrayList) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 3 with MetricKey

use of org.apache.beam.sdk.metrics.MetricKey in project beam by apache.

the class SparkBeamMetric method renderName.

@VisibleForTesting
static String renderName(MetricResult<?> metricResult) {
    MetricKey key = metricResult.getKey();
    MetricName name = key.metricName();
    String step = key.stepName();
    ArrayList<String> pieces = new ArrayList<>();
    if (step != null) {
        step = step.replaceAll(ILLEGAL_CHARACTERS, "_");
        if (step.endsWith("_")) {
            step = step.substring(0, step.length() - 1);
        }
        pieces.add(step);
    }
    pieces.addAll(ImmutableList.of(name.getNamespace(), name.getName()).stream().map(str -> str.replaceAll(ILLEGAL_CHARACTERS, "_")).collect(toList()));
    return String.join(".", pieces);
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MetricKey(org.apache.beam.sdk.metrics.MetricKey) ArrayList(java.util.ArrayList) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 4 with MetricKey

use of org.apache.beam.sdk.metrics.MetricKey in project beam by apache.

the class CustomMetricQueryResults method makeResults.

private <T> List<MetricResult<T>> makeResults(String step, String name, T committed, T attempted) {
    MetricName metricName = MetricName.named(NAMESPACE, name);
    MetricKey key = MetricKey.create(step, metricName);
    return Collections.singletonList(isCommittedSupported ? MetricResult.create(key, committed, attempted) : MetricResult.attempted(key, attempted));
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MetricKey(org.apache.beam.sdk.metrics.MetricKey)

Example 5 with MetricKey

use of org.apache.beam.sdk.metrics.MetricKey in project beam by apache.

the class MetricsContainerStepMap method mergeAttemptedResults.

@SuppressWarnings("ConstantConditions")
private static <T> void mergeAttemptedResults(Map<MetricKey, MetricResult<T>> metricResultMap, Iterable<MetricUpdate<T>> updates, BiFunction<T, T, T> combine) {
    for (MetricUpdate<T> metricUpdate : updates) {
        MetricKey key = metricUpdate.getKey();
        metricResultMap.compute(key, (k, current) -> {
            if (current == null) {
                return MetricResult.attempted(key, metricUpdate.getUpdate());
            } else {
                return current.addAttempted(metricUpdate.getUpdate(), combine);
            }
        });
    }
}
Also used : MetricKey(org.apache.beam.sdk.metrics.MetricKey)

Aggregations

MetricKey (org.apache.beam.sdk.metrics.MetricKey)12 Test (org.junit.Test)4 MetricName (org.apache.beam.sdk.metrics.MetricName)3 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)3 ArrayList (java.util.ArrayList)2 VisibleForTesting (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)2 DistributionData (org.apache.beam.runners.core.metrics.DistributionData)1 GaugeData (org.apache.beam.runners.core.metrics.GaugeData)1 MetricUpdates (org.apache.beam.runners.core.metrics.MetricUpdates)1 FlinkMetricContainer.getFlinkMetricNameString (org.apache.beam.runners.flink.metrics.FlinkMetricContainer.getFlinkMetricNameString)1 DistributionResult (org.apache.beam.sdk.metrics.DistributionResult)1 GaugeResult (org.apache.beam.sdk.metrics.GaugeResult)1 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 OperatorMetricGroup (org.apache.flink.metrics.groups.OperatorMetricGroup)1 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)1 NoOpMetricRegistry (org.apache.flink.runtime.metrics.NoOpMetricRegistry)1 GenericMetricGroup (org.apache.flink.runtime.metrics.groups.GenericMetricGroup)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1