You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by bc...@apache.org on 2017/07/14 21:56:35 UTC
[1/2] beam git commit: [BEAM-2491] Move package
org.apache.beam.runners.core.metrics to
org.apache.beam.runners.core.construction.metrics
Repository: beam
Updated Branches:
refs/heads/master 621f20f02 -> f77d0351c
[BEAM-2491] Move package org.apache.beam.runners.core.metrics to org.apache.beam.runners.core.construction.metrics
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/78fcbd7e
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/78fcbd7e
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/78fcbd7e
Branch: refs/heads/master
Commit: 78fcbd7e76ff3c1438c785fc928ec73fb1cc00f9
Parents: 621f20f
Author: Etienne Chauchot <ec...@gmail.com>
Authored: Wed Jun 21 13:36:26 2017 +0200
Committer: Ben Chambers <bc...@bchambers-macbookpro2.roam.corp.google.com>
Committed: Fri Jul 14 14:55:22 2017 -0700
----------------------------------------------------------------------
.../construction/metrics/MetricFiltering.java | 102 +++++++++++++
.../core/construction/metrics/MetricKey.java | 43 ++++++
.../core/construction/metrics/package-info.java | 22 +++
.../runners/core/metrics/MetricFiltering.java | 102 -------------
.../beam/runners/core/metrics/MetricKey.java | 43 ------
.../beam/runners/core/metrics/package-info.java | 22 ---
.../metrics/MetricFilteringTest.java | 148 +++++++++++++++++++
.../core/metrics/MetricFilteringTest.java | 148 -------------------
.../runners/core/metrics/MetricUpdates.java | 1 +
.../core/metrics/MetricsContainerImpl.java | 1 +
.../core/metrics/MetricsContainerStepMap.java | 2 +
.../beam/runners/direct/DirectMetrics.java | 4 +-
.../beam/runners/direct/DirectMetricsTest.java | 2 +-
.../beam/runners/dataflow/DataflowMetrics.java | 4 +-
14 files changed, 324 insertions(+), 320 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricFiltering.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricFiltering.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricFiltering.java
new file mode 100644
index 0000000..99d8f0f
--- /dev/null
+++ b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricFiltering.java
@@ -0,0 +1,102 @@
+/*
+ * 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.runners.core.construction.metrics;
+
+import com.google.common.base.Objects;
+import java.util.Set;
+import org.apache.beam.sdk.metrics.MetricName;
+import org.apache.beam.sdk.metrics.MetricNameFilter;
+import org.apache.beam.sdk.metrics.MetricsFilter;
+
+/**
+ * Implements matching for metrics filters. Specifically, matching for metric name,
+ * namespace, and step name.
+ */
+public class MetricFiltering {
+
+ private MetricFiltering() { }
+
+ /** Matching logic is implemented here rather than in MetricsFilter because we would like
+ * MetricsFilter to act as a "dumb" value-object, with the possibility of replacing it with
+ * a Proto/JSON/etc. schema object.
+ * @param filter {@link MetricsFilter} with the matching information of an actual metric
+ * @param key {@link MetricKey} with the information of a metric
+ * @return whether the filter matches the key or not
+ */
+ public static boolean matches(MetricsFilter filter, MetricKey key) {
+ return filter == null
+ || (matchesName(key.metricName(), filter.names())
+ && matchesScope(key.stepName(), filter.steps()));
+ }
+
+ /**
+ * {@code subPathMatches(haystack, needle)} returns true if {@code needle}
+ * represents a path within {@code haystack}. For example, "foo/bar" is in "a/foo/bar/b",
+ * but not "a/fool/bar/b" or "a/foo/bart/b".
+ */
+ public static boolean subPathMatches(String haystack, String needle) {
+ int location = haystack.indexOf(needle);
+ int end = location + needle.length();
+ if (location == -1) {
+ return false; // needle not found
+ } else if (location != 0 && haystack.charAt(location - 1) != '/') {
+ return false; // the first entry in needle wasn't exactly matched
+ } else if (end != haystack.length() && haystack.charAt(end) != '/') {
+ return false; // the last entry in needle wasn't exactly matched
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * {@code matchesScope(actualScope, scopes)} returns true if the scope of a metric is matched
+ * by any of the filters in {@code scopes}. A metric scope is a path of type "A/B/D". A
+ * path is matched by a filter if the filter is equal to the path (e.g. "A/B/D", or
+ * if it represents a subpath within it (e.g. "A/B" or "B/D", but not "A/D"). */
+ public static boolean matchesScope(String actualScope, Set<String> scopes) {
+ if (scopes.isEmpty() || scopes.contains(actualScope)) {
+ return true;
+ }
+
+ // If there is no perfect match, a stage name-level match is tried.
+ // This is done by a substring search over the levels of the scope.
+ // e.g. a scope "A/B/C/D" is matched by "A/B", but not by "A/C".
+ for (String scope : scopes) {
+ if (subPathMatches(actualScope, scope)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private static boolean matchesName(MetricName metricName, Set<MetricNameFilter> nameFilters) {
+ if (nameFilters.isEmpty()) {
+ return true;
+ }
+ for (MetricNameFilter nameFilter : nameFilters) {
+ if ((nameFilter.getName() == null || nameFilter.getName().equals(metricName.name()))
+ && Objects.equal(metricName.namespace(), nameFilter.getNamespace())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricKey.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricKey.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricKey.java
new file mode 100644
index 0000000..f4521a3
--- /dev/null
+++ b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/MetricKey.java
@@ -0,0 +1,43 @@
+/*
+ * 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.runners.core.construction.metrics;
+
+import com.google.auto.value.AutoValue;
+import java.io.Serializable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.annotations.Experimental.Kind;
+import org.apache.beam.sdk.metrics.MetricName;
+
+/**
+ * Metrics are keyed by the step name they are associated with and the name of the metric.
+ */
+@Experimental(Kind.METRICS)
+@AutoValue
+public abstract class MetricKey implements Serializable {
+
+ /** The step name that is associated with this metric. */
+ public abstract String stepName();
+
+ /** The name of the metric. */
+ public abstract MetricName metricName();
+
+ public static MetricKey create(String stepName, MetricName metricName) {
+ return new AutoValue_MetricKey(stepName, metricName);
+ }
+}
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/package-info.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/package-info.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/package-info.java
new file mode 100644
index 0000000..ceffd73
--- /dev/null
+++ b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/metrics/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Utilities for runners to implement metrics.
+ */
+package org.apache.beam.runners.core.construction.metrics;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricFiltering.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricFiltering.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricFiltering.java
deleted file mode 100644
index d469d20..0000000
--- a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricFiltering.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.runners.core.metrics;
-
-import com.google.common.base.Objects;
-import java.util.Set;
-import org.apache.beam.sdk.metrics.MetricName;
-import org.apache.beam.sdk.metrics.MetricNameFilter;
-import org.apache.beam.sdk.metrics.MetricsFilter;
-
-/**
- * Implements matching for metrics filters. Specifically, matching for metric name,
- * namespace, and step name.
- */
-public class MetricFiltering {
-
- private MetricFiltering() { }
-
- /** Matching logic is implemented here rather than in MetricsFilter because we would like
- * MetricsFilter to act as a "dumb" value-object, with the possibility of replacing it with
- * a Proto/JSON/etc. schema object.
- * @param filter {@link MetricsFilter} with the matching information of an actual metric
- * @param key {@link MetricKey} with the information of a metric
- * @return whether the filter matches the key or not
- */
- public static boolean matches(MetricsFilter filter, MetricKey key) {
- return filter == null
- || (matchesName(key.metricName(), filter.names())
- && matchesScope(key.stepName(), filter.steps()));
- }
-
- /**
- * {@code subPathMatches(haystack, needle)} returns true if {@code needle}
- * represents a path within {@code haystack}. For example, "foo/bar" is in "a/foo/bar/b",
- * but not "a/fool/bar/b" or "a/foo/bart/b".
- */
- public static boolean subPathMatches(String haystack, String needle) {
- int location = haystack.indexOf(needle);
- int end = location + needle.length();
- if (location == -1) {
- return false; // needle not found
- } else if (location != 0 && haystack.charAt(location - 1) != '/') {
- return false; // the first entry in needle wasn't exactly matched
- } else if (end != haystack.length() && haystack.charAt(end) != '/') {
- return false; // the last entry in needle wasn't exactly matched
- } else {
- return true;
- }
- }
-
- /**
- * {@code matchesScope(actualScope, scopes)} returns true if the scope of a metric is matched
- * by any of the filters in {@code scopes}. A metric scope is a path of type "A/B/D". A
- * path is matched by a filter if the filter is equal to the path (e.g. "A/B/D", or
- * if it represents a subpath within it (e.g. "A/B" or "B/D", but not "A/D"). */
- public static boolean matchesScope(String actualScope, Set<String> scopes) {
- if (scopes.isEmpty() || scopes.contains(actualScope)) {
- return true;
- }
-
- // If there is no perfect match, a stage name-level match is tried.
- // This is done by a substring search over the levels of the scope.
- // e.g. a scope "A/B/C/D" is matched by "A/B", but not by "A/C".
- for (String scope : scopes) {
- if (subPathMatches(actualScope, scope)) {
- return true;
- }
- }
-
- return false;
- }
-
- private static boolean matchesName(MetricName metricName, Set<MetricNameFilter> nameFilters) {
- if (nameFilters.isEmpty()) {
- return true;
- }
- for (MetricNameFilter nameFilter : nameFilters) {
- if ((nameFilter.getName() == null || nameFilter.getName().equals(metricName.name()))
- && Objects.equal(metricName.namespace(), nameFilter.getNamespace())) {
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricKey.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricKey.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricKey.java
deleted file mode 100644
index 58d4055..0000000
--- a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/MetricKey.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.runners.core.metrics;
-
-import com.google.auto.value.AutoValue;
-import java.io.Serializable;
-import org.apache.beam.sdk.annotations.Experimental;
-import org.apache.beam.sdk.annotations.Experimental.Kind;
-import org.apache.beam.sdk.metrics.MetricName;
-
-/**
- * Metrics are keyed by the step name they are associated with and the name of the metric.
- */
-@Experimental(Kind.METRICS)
-@AutoValue
-public abstract class MetricKey implements Serializable {
-
- /** The step name that is associated with this metric. */
- public abstract String stepName();
-
- /** The name of the metric. */
- public abstract MetricName metricName();
-
- public static MetricKey create(String stepName, MetricName metricName) {
- return new AutoValue_MetricKey(stepName, metricName);
- }
-}
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/package-info.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/package-info.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/package-info.java
deleted file mode 100644
index 263a705..0000000
--- a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/metrics/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * Utilities for runners to implement metrics.
- */
-package org.apache.beam.runners.core.metrics;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/metrics/MetricFilteringTest.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/metrics/MetricFilteringTest.java b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/metrics/MetricFilteringTest.java
new file mode 100644
index 0000000..5814551
--- /dev/null
+++ b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/metrics/MetricFilteringTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.runners.core.construction.metrics;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.beam.sdk.metrics.MetricName;
+import org.apache.beam.sdk.metrics.MetricNameFilter;
+import org.apache.beam.sdk.metrics.MetricsFilter;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Tests for {@link MetricFiltering}.
+ */
+@RunWith(JUnit4.class)
+public class MetricFilteringTest {
+ private static final MetricName NAME1 = MetricName.named("ns1", "name1");
+
+
+ private boolean matchesSubPath(String actualScope, String subPath) {
+ return MetricFiltering.subPathMatches(actualScope, subPath);
+ }
+
+ @Test
+ public void testMatchCompositeStepNameFilters() {
+ // MetricsFilter with a Class-namespace + name filter + step filter.
+ // Successful match.
+ assertTrue(MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
+ .addStep("myStep").build(),
+ MetricKey.create(
+ "myBigStep/myStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
+
+ // Unsuccessful match.
+ assertFalse(MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
+ .addStep("myOtherStep").build(),
+ MetricKey.create(
+ "myOtherStepNoMatch/myStep",
+ MetricName.named(MetricFilteringTest.class, "myMetricName"))));
+ }
+
+ @Test
+ public void testMatchStepNameFilters() {
+ // MetricsFilter with a Class-namespace + name filter + step filter.
+ // Successful match.
+ assertTrue(MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
+ .addStep("myStep").build(),
+ MetricKey.create("myStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
+
+ // Unsuccessful match.
+ assertFalse(MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
+ .addStep("myOtherStep").build(),
+ MetricKey.create("myStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
+ }
+
+ @Test
+ public void testMatchClassNamespaceFilters() {
+ // MetricsFilter with a Class-namespace + name filter. Without step filter.
+ // Successful match.
+ assertTrue(MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named(MetricFilteringTest.class, "myMetricName")).build(),
+ MetricKey.create("anyStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
+
+ // Unsuccessful match.
+ assertFalse(MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named(MetricFilteringTest.class, "myMetricName")).build(),
+ MetricKey.create("anyStep", MetricName.named(MetricFiltering.class, "myMetricName"))));
+ }
+
+ @Test
+ public void testMatchStringNamespaceFilters() {
+ // MetricsFilter with a String-namespace + name filter. Without step filter.
+ // Successful match.
+ assertTrue(
+ MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named("myNamespace", "myMetricName")).build(),
+ MetricKey.create("anyStep", MetricName.named("myNamespace", "myMetricName"))));
+
+ // Unsuccessful match.
+ assertFalse(
+ MetricFiltering.matches(
+ MetricsFilter.builder().addNameFilter(
+ MetricNameFilter.named("myOtherNamespace", "myMetricName")).build(),
+ MetricKey.create("anyStep", MetricName.named("myNamespace", "myMetricname"))));
+ }
+
+ @Test
+ public void testMatchesSubPath() {
+ assertTrue("Match of the first element",
+ matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Top1"));
+ assertTrue("Match of the first elements",
+ matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1"));
+ assertTrue("Match of the last elements",
+ matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Inner1/Bottom1"));
+ assertFalse("Substring match but no subpath match",
+ matchesSubPath("Top1/Outer1/Inner1/Bottom1", "op1/Outer1/Inner1"));
+ assertFalse("Substring match from start - but no subpath match",
+ matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Top"));
+ }
+
+ private boolean matchesScopeWithSingleFilter(String actualScope, String filter) {
+ Set<String> scopeFilter = new HashSet<String>();
+ scopeFilter.add(filter);
+ return MetricFiltering.matchesScope(actualScope, scopeFilter);
+ }
+
+ @Test
+ public void testMatchesScope() {
+ assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1"));
+ assertTrue(matchesScopeWithSingleFilter(
+ "Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1/Bottom1"));
+ assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1"));
+ assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1"));
+ assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Inner1"));
+ assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inn"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/metrics/MetricFilteringTest.java
----------------------------------------------------------------------
diff --git a/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/metrics/MetricFilteringTest.java b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/metrics/MetricFilteringTest.java
deleted file mode 100644
index 8953f21..0000000
--- a/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/metrics/MetricFilteringTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.runners.core.metrics;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.beam.sdk.metrics.MetricName;
-import org.apache.beam.sdk.metrics.MetricNameFilter;
-import org.apache.beam.sdk.metrics.MetricsFilter;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Tests for {@link MetricFiltering}.
- */
-@RunWith(JUnit4.class)
-public class MetricFilteringTest {
- private static final MetricName NAME1 = MetricName.named("ns1", "name1");
-
-
- private boolean matchesSubPath(String actualScope, String subPath) {
- return MetricFiltering.subPathMatches(actualScope, subPath);
- }
-
- @Test
- public void testMatchCompositeStepNameFilters() {
- // MetricsFilter with a Class-namespace + name filter + step filter.
- // Successful match.
- assertTrue(MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
- .addStep("myStep").build(),
- MetricKey.create(
- "myBigStep/myStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
-
- // Unsuccessful match.
- assertFalse(MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
- .addStep("myOtherStep").build(),
- MetricKey.create(
- "myOtherStepNoMatch/myStep",
- MetricName.named(MetricFilteringTest.class, "myMetricName"))));
- }
-
- @Test
- public void testMatchStepNameFilters() {
- // MetricsFilter with a Class-namespace + name filter + step filter.
- // Successful match.
- assertTrue(MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
- .addStep("myStep").build(),
- MetricKey.create("myStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
-
- // Unsuccessful match.
- assertFalse(MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named(MetricFilteringTest.class, "myMetricName"))
- .addStep("myOtherStep").build(),
- MetricKey.create("myStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
- }
-
- @Test
- public void testMatchClassNamespaceFilters() {
- // MetricsFilter with a Class-namespace + name filter. Without step filter.
- // Successful match.
- assertTrue(MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named(MetricFilteringTest.class, "myMetricName")).build(),
- MetricKey.create("anyStep", MetricName.named(MetricFilteringTest.class, "myMetricName"))));
-
- // Unsuccessful match.
- assertFalse(MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named(MetricFilteringTest.class, "myMetricName")).build(),
- MetricKey.create("anyStep", MetricName.named(MetricFiltering.class, "myMetricName"))));
- }
-
- @Test
- public void testMatchStringNamespaceFilters() {
- // MetricsFilter with a String-namespace + name filter. Without step filter.
- // Successful match.
- assertTrue(
- MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named("myNamespace", "myMetricName")).build(),
- MetricKey.create("anyStep", MetricName.named("myNamespace", "myMetricName"))));
-
- // Unsuccessful match.
- assertFalse(
- MetricFiltering.matches(
- MetricsFilter.builder().addNameFilter(
- MetricNameFilter.named("myOtherNamespace", "myMetricName")).build(),
- MetricKey.create("anyStep", MetricName.named("myNamespace", "myMetricname"))));
- }
-
- @Test
- public void testMatchesSubPath() {
- assertTrue("Match of the first element",
- matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Top1"));
- assertTrue("Match of the first elements",
- matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1"));
- assertTrue("Match of the last elements",
- matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Inner1/Bottom1"));
- assertFalse("Substring match but no subpath match",
- matchesSubPath("Top1/Outer1/Inner1/Bottom1", "op1/Outer1/Inner1"));
- assertFalse("Substring match from start - but no subpath match",
- matchesSubPath("Top1/Outer1/Inner1/Bottom1", "Top"));
- }
-
- private boolean matchesScopeWithSingleFilter(String actualScope, String filter) {
- Set<String> scopeFilter = new HashSet<String>();
- scopeFilter.add(filter);
- return MetricFiltering.matchesScope(actualScope, scopeFilter);
- }
-
- @Test
- public void testMatchesScope() {
- assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1"));
- assertTrue(matchesScopeWithSingleFilter(
- "Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1/Bottom1"));
- assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1"));
- assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1"));
- assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Inner1"));
- assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inn"));
- }
-}
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUpdates.java
----------------------------------------------------------------------
diff --git a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUpdates.java b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUpdates.java
index eae3305..ae91f71 100644
--- a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUpdates.java
+++ b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUpdates.java
@@ -22,6 +22,7 @@ import com.google.auto.value.AutoValue;
import com.google.common.collect.Iterables;
import java.io.Serializable;
import java.util.Collections;
+import org.apache.beam.runners.core.construction.metrics.MetricKey;
import org.apache.beam.sdk.annotations.Experimental;
import org.apache.beam.sdk.annotations.Experimental.Kind;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java
----------------------------------------------------------------------
diff --git a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java
index 99d7454..4b331e0 100644
--- a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java
+++ b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java
@@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList;
import java.io.Serializable;
import java.util.Map;
+import org.apache.beam.runners.core.construction.metrics.MetricKey;
import org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate;
import org.apache.beam.sdk.annotations.Experimental;
import org.apache.beam.sdk.annotations.Experimental.Kind;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerStepMap.java
----------------------------------------------------------------------
diff --git a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerStepMap.java b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerStepMap.java
index 68238e4..14b8ccb 100644
--- a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerStepMap.java
+++ b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerStepMap.java
@@ -25,6 +25,8 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.beam.runners.core.construction.metrics.MetricFiltering;
+import org.apache.beam.runners.core.construction.metrics.MetricKey;
import org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate;
import org.apache.beam.sdk.metrics.DistributionResult;
import org.apache.beam.sdk.metrics.GaugeResult;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/direct-java/src/main/java/org/apache/beam/runners/direct/DirectMetrics.java
----------------------------------------------------------------------
diff --git a/runners/direct-java/src/main/java/org/apache/beam/runners/direct/DirectMetrics.java b/runners/direct-java/src/main/java/org/apache/beam/runners/direct/DirectMetrics.java
index 8169332..48b0113 100644
--- a/runners/direct-java/src/main/java/org/apache/beam/runners/direct/DirectMetrics.java
+++ b/runners/direct-java/src/main/java/org/apache/beam/runners/direct/DirectMetrics.java
@@ -32,10 +32,10 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.concurrent.GuardedBy;
+import org.apache.beam.runners.core.construction.metrics.MetricFiltering;
+import org.apache.beam.runners.core.construction.metrics.MetricKey;
import org.apache.beam.runners.core.metrics.DistributionData;
import org.apache.beam.runners.core.metrics.GaugeData;
-import org.apache.beam.runners.core.metrics.MetricFiltering;
-import org.apache.beam.runners.core.metrics.MetricKey;
import org.apache.beam.runners.core.metrics.MetricUpdates;
import org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate;
import org.apache.beam.runners.core.metrics.MetricsMap;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectMetricsTest.java
----------------------------------------------------------------------
diff --git a/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectMetricsTest.java b/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectMetricsTest.java
index 8cdf323..4ce5342 100644
--- a/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectMetricsTest.java
+++ b/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectMetricsTest.java
@@ -26,9 +26,9 @@ import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import com.google.common.collect.ImmutableList;
+import org.apache.beam.runners.core.construction.metrics.MetricKey;
import org.apache.beam.runners.core.metrics.DistributionData;
import org.apache.beam.runners.core.metrics.GaugeData;
-import org.apache.beam.runners.core.metrics.MetricKey;
import org.apache.beam.runners.core.metrics.MetricUpdates;
import org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate;
import org.apache.beam.sdk.metrics.DistributionResult;
http://git-wip-us.apache.org/repos/asf/beam/blob/78fcbd7e/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 f038e3f..31b6cda 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
@@ -28,8 +28,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import org.apache.beam.runners.core.metrics.MetricFiltering;
-import org.apache.beam.runners.core.metrics.MetricKey;
+import org.apache.beam.runners.core.construction.metrics.MetricFiltering;
+import org.apache.beam.runners.core.construction.metrics.MetricKey;
import org.apache.beam.sdk.metrics.DistributionResult;
import org.apache.beam.sdk.metrics.GaugeResult;
import org.apache.beam.sdk.metrics.MetricName;
[2/2] beam git commit: This closes #3422
Posted by bc...@apache.org.
This closes #3422
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/f77d0351
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/f77d0351
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/f77d0351
Branch: refs/heads/master
Commit: f77d0351c2e8add9dd3f208c7203fab50313fb50
Parents: 621f20f 78fcbd7
Author: Ben Chambers <bc...@bchambers-macbookpro2.roam.corp.google.com>
Authored: Fri Jul 14 11:32:40 2017 -0700
Committer: Ben Chambers <bc...@bchambers-macbookpro2.roam.corp.google.com>
Committed: Fri Jul 14 14:55:23 2017 -0700
----------------------------------------------------------------------
.../construction/metrics/MetricFiltering.java | 102 +++++++++++++
.../core/construction/metrics/MetricKey.java | 43 ++++++
.../core/construction/metrics/package-info.java | 22 +++
.../runners/core/metrics/MetricFiltering.java | 102 -------------
.../beam/runners/core/metrics/MetricKey.java | 43 ------
.../beam/runners/core/metrics/package-info.java | 22 ---
.../metrics/MetricFilteringTest.java | 148 +++++++++++++++++++
.../core/metrics/MetricFilteringTest.java | 148 -------------------
.../runners/core/metrics/MetricUpdates.java | 1 +
.../core/metrics/MetricsContainerImpl.java | 1 +
.../core/metrics/MetricsContainerStepMap.java | 2 +
.../beam/runners/direct/DirectMetrics.java | 4 +-
.../beam/runners/direct/DirectMetricsTest.java | 2 +-
.../beam/runners/dataflow/DataflowMetrics.java | 4 +-
14 files changed, 324 insertions(+), 320 deletions(-)
----------------------------------------------------------------------