/** * This will only be invoked if using a fork of the metrics library with support * for filtering on a per-measurement basis - http://github.com/mspiegel/metrics. * Otherwise this method is not invoked. The @Override annotation is omitted so * that compilation is successful using either the metrics library or the fork of the * metrics library. */ public boolean matches(MetricName name, Metric metric, String measurement) { if ((meter != null) && (metric instanceof Meter)) { return allowMeasurement(name, measurement, meter, meterPatterns); } else if ((histogram != null) && (metric instanceof Histogram)) { return allowMeasurement(name, measurement, histogram, histogramPatterns); } else if ((timer != null) && (metric instanceof Timer)) { return allowMeasurement(name, measurement, timer, timerPatterns); } else { return true; } }
public boolean allowMeasurement(MetricName name, String measurement, Measurement type, List<MeasurementPattern> patterns) { if (type.useQualifiedName) { return allowMeasurement(qualifyMetricName(name), measurement, type, patterns); } else { return allowMeasurement(name.getName(), measurement, type, patterns); } }
private boolean allowMeasurement(String name, String measurement, PredicateConfig.Measurement type, List<PredicateConfig.MeasurementPattern> patterns) { if (type.getUseQualifiedName()) { return predicate.allowMeasurement(name, measurement, type, patterns); } else { return predicate.allowMeasurement(unqualifyMetricName(name), measurement, type, patterns); } }
public boolean allowMeasurement(MetricName name, String measurement, PredicateConfig.Measurement type, List<PredicateConfig.MeasurementPattern> patterns) { if (type.getUseQualifiedName()) { return predicate.allowMeasurement(qualifyMetricName(name), measurement, type, patterns); } else { return predicate.allowMeasurement(name.getName(), measurement, type, patterns); } }
@Test public void singleWhiteMeasurement() { MeasurementPattern pattern = new MeasurementPattern("^foo.+", "^bar.+"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern); Measurement type = new Measurement("white", false); assertFalse(PredicateConfig.allowMeasurement("foo", "bar", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foo", "bars", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foos", "bar", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foos", "bars", type, patternList)); }
@Test public void singleBlackMeasurement() { MeasurementPattern pattern = new MeasurementPattern("^foo.+", "^bar.+"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern); Measurement type = new Measurement("black", false); assertTrue(PredicateConfig.allowMeasurement("foo", "bar", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foo", "bars", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foos", "bar", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foos", "bars", type, patternList)); }
@Test public void multiBlackMeasurement() { MeasurementPattern pattern1 = new MeasurementPattern("^foo.+", "^bar.+"); MeasurementPattern pattern2 = new MeasurementPattern(".*foo$", ".*bar$"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern1); patternList.add(pattern2); Measurement type = new Measurement("black", false); assertTrue(PredicateConfig.allowMeasurement("hello", "world", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("hellofooworld", "hellobarworld", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("hellobarworld", "hellofooworld", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("fooworld", "barworld", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("hellofoo", "hellobar", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foohellofoo", "barhellobar", type, patternList)); }
@Test public void multiWhiteMeasurement() { MeasurementPattern pattern1 = new MeasurementPattern("^foo.+", "^bar.+"); MeasurementPattern pattern2 = new MeasurementPattern(".*foo$", ".*bar$"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern1); patternList.add(pattern2); Measurement type = new Measurement("white", false); assertFalse(PredicateConfig.allowMeasurement("hello", "world", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("hellofooworld", "hellobarworld", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("hellobarworld", "hellofooworld", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("fooworld", "barworld", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("hellofoo", "hellobar", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foohellofoo", "barhellobar", type, patternList)); }