@Test public void testMetricNamePrefixMatch() { Set<String> names = new HashSet<String>(); names.add("shared.carts.my_cart"); MetricNameSetFilter filter = new MetricNameSetFilter(names); MetricName mn = MetricName.build("shared.carts.my_cart.m1"); Assert.assertTrue(filter.matches(mn, null)); Set<String> names2 = new HashSet<String>(); names2.add("shared.carts.my_cart.m15"); MetricNameSetFilter filter2 = new MetricNameSetFilter(names2); MetricName mn2 = MetricName.build("shared.carts.my_cart.m1"); Assert.assertFalse(filter2.matches(mn2, null)); }
@Override public boolean matches(MetricName name, Metric metric) { for (String nameToMatch: metricNames) { boolean success; if (metric instanceof Counter) { success = matchInternal(nameToMatch, name, counterSuffixSet, false); } else if (metric instanceof Meter) { success = matchInternal(nameToMatch, name, meterSuffixSet, false); } else if (metric instanceof Histogram) { success = matchInternal(nameToMatch, name, histogramSuffixSet, false); } else if (metric instanceof Timer) { success = matchInternal(nameToMatch, name, timerSuffixSet, false); } else if (metric instanceof Compass) { success = matchInternal(nameToMatch, name, compassSuffixSet, true); if (!success) { success = matchCompassAddon(nameToMatch, name, (Compass)metric); } } else if (metric instanceof Gauge) { success = matchInternal(nameToMatch, name, gaugeSuffixSet, false); } else if (metric instanceof FastCompass) { success = matchInternal(nameToMatch, name, fastCompassSuffixSet, true); } else if (metric instanceof ClusterHistogram) { success = matchInternal(nameToMatch, name, clusterHistogramSuffixSet, false); } else if (metric == null) { if (nameToMatch.equals(name.getKey())) { success = true; } else { int lastIndexOfDot = name.getKey().lastIndexOf("."); if (lastIndexOfDot < 0) { success = false; } else { success = name.getKey().startsWith(nameToMatch) && nameToMatch.length() == lastIndexOfDot; } } } else { success = nameToMatch.equals(name.getKey()); } if (success) return true; } return false; }
MetricNameSetFilter implements MetricFilter { @Override public boolean matches(MetricName name, Metric metric) { for (String nameToMatch: metricNames) { boolean success; if (metric instanceof Counter) { success = matchInternal(nameToMatch, name, counterSuffixSet, false); } else if (metric instanceof Meter) { success = matchInternal(nameToMatch, name, meterSuffixSet, false); } else if (metric instanceof Histogram) { success = matchInternal(nameToMatch, name, histogramSuffixSet, false); } else if (metric instanceof Timer) { success = matchInternal(nameToMatch, name, timerSuffixSet, false); } else if (metric instanceof Compass) { success = matchInternal(nameToMatch, name, compassSuffixSet, true); if (!success) { success = matchCompassAddon(nameToMatch, name, (Compass)metric); } } else if (metric instanceof Gauge) { success = matchInternal(nameToMatch, name, gaugeSuffixSet, false); } else if (metric instanceof FastCompass) { success = matchInternal(nameToMatch, name, fastCompassSuffixSet, true); } else if (metric instanceof ClusterHistogram) { success = matchInternal(nameToMatch, name, clusterHistogramSuffixSet, false); } else if (metric == null) { if (nameToMatch.equals(name.getKey())) { success = true; } else { int lastIndexOfDot = name.getKey().lastIndexOf("."); if (lastIndexOfDot < 0) { success = false; } else { success = name.getKey().startsWith(nameToMatch) && nameToMatch.length() == lastIndexOfDot; } } } else { success = nameToMatch.equals(name.getKey()); } if (success) return true; } return false; } }
MetricNameSetFilter implements MetricFilter { @Override public boolean matches(MetricName name, Metric metric) { for (String nameToMatch: metricNames) { boolean success; if (metric instanceof Counter) { success = matchInternal(nameToMatch, name, counterSuffixSet, false); } else if (metric instanceof Meter) { success = matchInternal(nameToMatch, name, meterSuffixSet, false); } else if (metric instanceof Histogram) { success = matchInternal(nameToMatch, name, histogramSuffixSet, false); } else if (metric instanceof Timer) { success = matchInternal(nameToMatch, name, timerSuffixSet, false); } else if (metric instanceof Compass) { success = matchInternal(nameToMatch, name, compassSuffixSet, true); if (!success) { success = matchCompassAddon(nameToMatch, name, (Compass)metric); } } else if (metric instanceof Gauge) { success = matchInternal(nameToMatch, name, gaugeSuffixSet, false); } else if (metric instanceof FastCompass) { success = matchInternal(nameToMatch, name, fastCompassSuffixSet, true); } else if (metric instanceof ClusterHistogram) { success = matchInternal(nameToMatch, name, clusterHistogramSuffixSet, false); } else if (metric == null) { if (nameToMatch.equals(name.getKey())) { success = true; } else { int lastIndexOfDot = name.getKey().lastIndexOf("."); if (lastIndexOfDot < 0) { success = false; } else { success = name.getKey().startsWith(nameToMatch) && nameToMatch.length() == lastIndexOfDot; } } } else { success = nameToMatch.equals(name.getKey()); } if (success) return true; } return false; } MetricNameSetFilter(String... names);  MetricNameSetFilter(final Set<String> metricNames); }
MetricNameSetFilter implements MetricFilter { @Override public boolean matches(MetricName name, Metric metric) { for (String nameToMatch: metricNames) { boolean success; if (metric instanceof Counter) { success = matchInternal(nameToMatch, name, counterSuffixSet, false); } else if (metric instanceof Meter) { success = matchInternal(nameToMatch, name, meterSuffixSet, false); } else if (metric instanceof Histogram) { success = matchInternal(nameToMatch, name, histogramSuffixSet, false); } else if (metric instanceof Timer) { success = matchInternal(nameToMatch, name, timerSuffixSet, false); } else if (metric instanceof Compass) { success = matchInternal(nameToMatch, name, compassSuffixSet, true); if (!success) { success = matchCompassAddon(nameToMatch, name, (Compass)metric); } } else if (metric instanceof Gauge) { success = matchInternal(nameToMatch, name, gaugeSuffixSet, false); } else if (metric instanceof FastCompass) { success = matchInternal(nameToMatch, name, fastCompassSuffixSet, true); } else if (metric instanceof ClusterHistogram) { success = matchInternal(nameToMatch, name, clusterHistogramSuffixSet, false); } else if (metric == null) { if (nameToMatch.equals(name.getKey())) { success = true; } else { int lastIndexOfDot = name.getKey().lastIndexOf("."); if (lastIndexOfDot < 0) { success = false; } else { success = name.getKey().startsWith(nameToMatch) && nameToMatch.length() == lastIndexOfDot; } } } else { success = nameToMatch.equals(name.getKey()); } if (success) return true; } return false; } MetricNameSetFilter(String... names);  MetricNameSetFilter(final Set<String> metricNames); @Override boolean matches(MetricName name, Metric metric); }
MetricNameSetFilter implements MetricFilter { @Override public boolean matches(MetricName name, Metric metric) { for (String nameToMatch: metricNames) { boolean success; if (metric instanceof Counter) { success = matchInternal(nameToMatch, name, counterSuffixSet, false); } else if (metric instanceof Meter) { success = matchInternal(nameToMatch, name, meterSuffixSet, false); } else if (metric instanceof Histogram) { success = matchInternal(nameToMatch, name, histogramSuffixSet, false); } else if (metric instanceof Timer) { success = matchInternal(nameToMatch, name, timerSuffixSet, false); } else if (metric instanceof Compass) { success = matchInternal(nameToMatch, name, compassSuffixSet, true); if (!success) { success = matchCompassAddon(nameToMatch, name, (Compass)metric); } } else if (metric instanceof Gauge) { success = matchInternal(nameToMatch, name, gaugeSuffixSet, false); } else if (metric instanceof FastCompass) { success = matchInternal(nameToMatch, name, fastCompassSuffixSet, true); } else if (metric instanceof ClusterHistogram) { success = matchInternal(nameToMatch, name, clusterHistogramSuffixSet, false); } else if (metric == null) { if (nameToMatch.equals(name.getKey())) { success = true; } else { int lastIndexOfDot = name.getKey().lastIndexOf("."); if (lastIndexOfDot < 0) { success = false; } else { success = name.getKey().startsWith(nameToMatch) && nameToMatch.length() == lastIndexOfDot; } } } else { success = nameToMatch.equals(name.getKey()); } if (success) return true; } return false; } MetricNameSetFilter(String... names);  MetricNameSetFilter(final Set<String> metricNames); @Override boolean matches(MetricName name, Metric metric);  }