use of org.apache.hadoop.metrics2.MetricsFilter in project hadoop by apache.
the class MetricsConfig method getFilter.
MetricsFilter getFilter(String prefix) {
// don't create filter instances without out options
MetricsConfig conf = subset(prefix);
if (conf.isEmpty())
return null;
MetricsFilter filter = getPlugin(prefix);
if (filter != null)
return filter;
// glob filter is assumed if pattern is specified but class is not.
filter = new GlobFilter();
filter.init(conf);
return filter;
}
use of org.apache.hadoop.metrics2.MetricsFilter in project hadoop by apache.
the class TestPatternFilter method shouldAcceptImpl.
private static void shouldAcceptImpl(final boolean expectAcceptList, SubsetConfiguration conf, List<MetricsTag> tags, boolean[] expectedAcceptedSpec) {
final MetricsFilter globFilter = newGlobFilter(conf);
final MetricsFilter regexFilter = newRegexFilter(conf);
// Test acceptance of the tag list:
assertEquals("accepts " + tags, expectAcceptList, globFilter.accepts(tags));
assertEquals("accepts " + tags, expectAcceptList, regexFilter.accepts(tags));
// Test results on each of the individual tags:
int acceptedCount = 0;
for (int i = 0; i < tags.size(); i++) {
MetricsTag tag = tags.get(i);
boolean actGlob = globFilter.accepts(tag);
boolean actRegex = regexFilter.accepts(tag);
assertEquals("accepts " + tag, expectedAcceptedSpec[i], actGlob);
// Both the filters should give the same result:
assertEquals(actGlob, actRegex);
if (actGlob) {
acceptedCount++;
}
}
if (expectAcceptList) {
// At least one individual tag should be accepted:
assertTrue("No tag of the following accepted: " + tags, acceptedCount > 0);
} else {
// At least one individual tag should be rejected:
assertTrue("No tag of the following rejected: " + tags, acceptedCount < tags.size());
}
}
Aggregations