public class MetricFiltering extends java.lang.Object
|Modifier and Type||Method and Description|
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.
public static boolean matches(MetricsFilter filter, MetricKey key)
MetricsFilterwith the matching information of an actual metric
MetricKeywith the information of a metric
public static boolean subPathMatches(java.lang.String haystack, java.lang.String needle)
subPathMatches(haystack, needle)returns true if
needlerepresents a path within
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 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 in
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").
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