Package org.apache.beam.sdk.metrics
Class MetricFiltering
- java.lang.Object
-
- org.apache.beam.sdk.metrics.MetricFiltering
-
public class MetricFiltering extends java.lang.Object
Implements matching for metrics filters. Specifically, matching for metric name, namespace, and step name.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
matches(MetricsFilter filter, MetricKey key)
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.static boolean
matchesScope(java.lang.String actualScope, java.util.Set<java.lang.String> scopes)
matchesScope(actualScope, scopes)
returns true if the scope of a metric is matched by any of the filters inscopes
.static boolean
subPathMatches(java.lang.String haystack, java.lang.String needle)
subPathMatches(haystack, needle)
returns true ifneedle
represents a path withinhaystack
.
-
-
-
Method Detail
-
matches
public static boolean matches(MetricsFilter filter, MetricKey key)
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.- Parameters:
filter
-MetricsFilter
with the matching information of an actual metrickey
-MetricKey
with the information of a metric- Returns:
- whether the filter matches the key or not
-
subPathMatches
public static boolean subPathMatches(java.lang.String haystack, java.lang.String needle)
subPathMatches(haystack, needle)
returns true ifneedle
represents a path withinhaystack
. For example, "foo/bar" is in "a/foo/bar/b", but not "a/fool/bar/b" or "a/foo/bart/b".
-
matchesScope
public static boolean matchesScope(java.lang.String actualScope, java.util.Set<java.lang.String> scopes)
matchesScope(actualScope, scopes)
returns true if the scope of a metric is matched by any of the filters inscopes
. 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").Per https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/Set.html "sets contain ... at most one null element" / "Some set implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements". Since sets cannot in general contain null it is not safe to check for membership of null, so the caller must determine what to do with a null
actualScope
.
-
-