io.micrometer.core.instrument.config.MeterFilterReply Java Examples
The following examples show how to use
io.micrometer.core.instrument.config.MeterFilterReply.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void enableMetric() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsBlacklist("prefix_abc"); k8sMetricsProperties.setEnableCommonMetricsFilterAction(true); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); filter.setPrefixes(new String[]{"prefix"}); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); //Backlist filter.enableMetric("prefix_abc"); reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); }
Example #2
Source File: DropwizardMeterRegistries.java From armeria with Apache License 2.0 | 6 votes |
/** * Configures the {@link DropwizardMeterRegistry} with Armeria's defaults. Useful when using a different * implementation of {@link DropwizardMeterRegistry}, e.g., a {@code JmxMeterRegistry}. * * @return the specified {@link DropwizardMeterRegistry} */ public static <T extends DropwizardMeterRegistry> T configureRegistry(T meterRegistry) { requireNonNull(meterRegistry, "meterRegistry"); meterRegistry.config().meterFilter(new MeterFilter() { @Override public MeterFilterReply accept(Meter.Id id) { if (id.getName().endsWith(".percentile") && id.getTag("phi") != null) { return MeterFilterReply.DENY; } if (id.getName().endsWith(".histogram") && id.getTag("le") != null) { return MeterFilterReply.DENY; } return MeterFilterReply.NEUTRAL; } }); meterRegistry.config().namingConvention(MoreNamingConventions.dropwizard()); return meterRegistry; }
Example #3
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void disableMetric() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsWhitelist("prefix_abc"); k8sMetricsProperties.setEnableCommonMetricsFilterAction(true); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); //Whitelist filter.disableMetric("prefix_abc"); reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); }
Example #4
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void disableAction() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsWhitelist("prefix_abc"); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); //Whitelist filter.disableMetric("prefix_abc"); reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); }
Example #5
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void acceptEnabled() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); filter.setPrefixes(new String[]{"prefix"}); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.ACCEPT); filter.setPrefixes(new String[]{"prefix"}); reply = filter.accept(new Meter.Id("abc_.omething", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); }
Example #6
Source File: CommonMetricsFilter.java From foremast with Apache License 2.0 | 5 votes |
/** * Filter for "[PREFIX]_*" * * @param id * @return MeterFilterReply */ public MeterFilterReply accept(Meter.Id id) { if (!k8sMetricsProperties.isEnableCommonMetricsFilter()) { return MeterFilter.super.accept(id); } String metricName = id.getName(); Boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, null); if (enabled != null) { return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; } if (whitelist.contains(metricName)) { return MeterFilterReply.NEUTRAL; } if (blacklist.contains(metricName)) { return MeterFilterReply.DENY; } for(String prefix: prefixes) { if (metricName.startsWith(prefix)) { return MeterFilterReply.ACCEPT; } } for(String key: tagRules.keySet()) { String expectedValue = tagRules.get(key); if (expectedValue != null) { if (expectedValue.equals(id.getTag(key))) { return MeterFilterReply.ACCEPT; } } } return MeterFilterReply.DENY; }
Example #7
Source File: OnlyOnceLoggingDenyMeterFilter.java From foremast with Apache License 2.0 | 5 votes |
@Override public MeterFilterReply accept(Meter.Id id) { if (logger.isWarnEnabled() && this.alreadyWarned.compareAndSet(false, true)) { logger.warn(this.message.get()); } return MeterFilterReply.DENY; }
Example #8
Source File: HealthMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
private boolean accept(Meter.Id id) { for (MeterFilter filter : serviceLevelObjectiveFilters) { MeterFilterReply reply = filter.accept(id); if (reply == MeterFilterReply.DENY) { return false; } else if (reply == MeterFilterReply.ACCEPT) { return true; } } return true; }
Example #9
Source File: MeterFilterTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void acceptNameStartsWith() { Meter.Id id1 = new Meter.Id("my.counter", Tags.empty(), null, null, Meter.Type.COUNTER); Meter.Id id2 = new Meter.Id("other.counter", Tags.empty(), null, null, Meter.Type.COUNTER); MeterFilter filter = MeterFilter.acceptNameStartsWith("my"); assertThat(filter.accept(id1)).isEqualTo(MeterFilterReply.ACCEPT); assertThat(filter.accept(id2)).isEqualTo(MeterFilterReply.NEUTRAL); }
Example #10
Source File: MeterFilterTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void denyUnless() { Meter.Id id1 = new Meter.Id("my.counter", Tags.empty(), null, null, Meter.Type.COUNTER); Meter.Id id2 = new Meter.Id("other.counter", Tags.empty(), null, null, Meter.Type.COUNTER); MeterFilter filter = MeterFilter.denyUnless(id -> id.getName().startsWith("my")); assertThat(filter.accept(id1)).isEqualTo(MeterFilterReply.NEUTRAL); assertThat(filter.accept(id2)).isEqualTo(MeterFilterReply.DENY); }
Example #11
Source File: MeterFilterTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void maximumAllowableMetrics() { MeterFilter filter = MeterFilter.maximumAllowableMetrics(1); Meter.Id id = new Meter.Id("name", Tags.empty(), null, null, Meter.Type.COUNTER); Meter.Id id2 = new Meter.Id("name2", Tags.empty(), null, null, Meter.Type.COUNTER); assertThat(filter.accept(id)).isEqualTo(MeterFilterReply.NEUTRAL); assertThat(filter.accept(id)).isEqualTo(MeterFilterReply.NEUTRAL); assertThat(filter.accept(id2)).isEqualTo(MeterFilterReply.DENY); }
Example #12
Source File: MeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void acceptMeterFilter() { registry.config().meterFilter(new MeterFilter() { @Override public MeterFilterReply accept(Meter.Id id) { return id.getName().contains("jvm") ? MeterFilterReply.DENY : MeterFilterReply.NEUTRAL; } }); assertThat(registry.counter("jvm.my.counter")).isInstanceOf(NoopCounter.class); assertThat(registry.counter("my.counter")).isNotInstanceOf(NoopCounter.class); }
Example #13
Source File: OnlyOnceLoggingDenyMeterFilter.java From micrometer with Apache License 2.0 | 5 votes |
@Override public MeterFilterReply accept(Id id) { if (logger.isWarnEnabled() && this.alreadyWarned.compareAndSet(false, true)) { logger.warn(this.message.get()); } return MeterFilterReply.DENY; }
Example #14
Source File: MeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
private boolean accept(Meter.Id id) { for (MeterFilter filter : filters) { MeterFilterReply reply = filter.accept(id); if (reply == MeterFilterReply.DENY) { return false; } else if (reply == MeterFilterReply.ACCEPT) { return true; } } return true; }
Example #15
Source File: Search.java From micrometer with Apache License 2.0 | 5 votes |
/** * @return An accept filter that accepts any meter that matches this search. * @since 1.6.0 */ public MeterFilter acceptFilter() { return new MeterFilter() { @Override public MeterFilterReply accept(Meter.Id id) { if (!nameMatches.test(id.getName())) { return MeterFilterReply.NEUTRAL; } boolean requiredKeysPresent = true; if (!requiredTagKeys.isEmpty()) { final List<String> tagKeys = new ArrayList<>(); id.getTags().forEach(t -> tagKeys.add(t.getKey())); requiredKeysPresent = tagKeys.containsAll(requiredTagKeys); } boolean tagPredicatesMatched = true; if (!tagMatches.isEmpty()) { final Set<String> matchingTagKeys = new HashSet<>(); id.getTags().forEach(t -> { Collection<Predicate<String>> tagValueMatchers = tagMatches.get(t.getKey()); if (tagValueMatchers != null) { if (tagValueMatchers.stream().allMatch(matcher -> matcher.test(t.getValue()))) { matchingTagKeys.add(t.getKey()); } } }); tagPredicatesMatched = tagMatches.keySet().size() == matchingTagKeys.size(); } return requiredKeysPresent && tagPredicatesMatched && id.getTags().containsAll(tags) ? MeterFilterReply.ACCEPT : MeterFilterReply.NEUTRAL; } }; }
Example #16
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void defaultMetricsProperties() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); MetricsProperties metricsProperties = new MetricsProperties(); metricsProperties.getEnable().put("prefix.abc", false); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); //Disabled }
Example #17
Source File: OnlyOnceLoggingDenyMeterFilter.java From foremast with Apache License 2.0 | 5 votes |
@Override public MeterFilterReply accept(Meter.Id id) { if (logger.isWarnEnabled() && this.alreadyWarned.compareAndSet(false, true)) { logger.warn(this.message.get()); } return MeterFilterReply.DENY; }
Example #18
Source File: CommonMetricsFilter.java From foremast with Apache License 2.0 | 5 votes |
/** * Filter for "[PREFIX]_*" * * @param id * @return MeterFilterReply */ public MeterFilterReply accept(Meter.Id id) { if (!k8sMetricsProperties.isEnableCommonMetricsFilter()) { return MeterFilter.super.accept(id); } String metricName = id.getName(); Boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, null); if (enabled != null) { return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; } if (whitelist.contains(metricName)) { return MeterFilterReply.NEUTRAL; } if (blacklist.contains(metricName)) { return MeterFilterReply.DENY; } for(String prefix: prefixes) { if (metricName.startsWith(prefix)) { return MeterFilterReply.ACCEPT; } } for(String key: tagRules.keySet()) { String expectedValue = tagRules.get(key); if (expectedValue != null) { if (expectedValue.equals(id.getTag(key))) { return MeterFilterReply.ACCEPT; } } } return MeterFilterReply.DENY; }
Example #19
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void tagRules() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsTagRules("myTag:true"); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", Tags.of("myTag", "true"), "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.ACCEPT); reply = filter.accept(new Meter.Id("prefix.abc", Tags.of("myTag", "false"), "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); }
Example #20
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void acceptWhiteList() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsWhitelist("prefix_abc"); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); //Whitelist }
Example #21
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void acceptBlackList() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsBlacklist("prefix_abc"); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); filter.setPrefixes(new String[]{"prefix"}); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); //Backlist }
Example #22
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void acceptDisabled() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); filter.setPrefixes(new String[]{"prefix"}); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); filter.setPrefixes(new String[]{"prefix"}); reply = filter.accept(new Meter.Id("abc.something", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); }
Example #23
Source File: CommonMetricsFilter.java From foremast with Apache License 2.0 | 5 votes |
/** * Filter for "[PREFIX]_*" * * @param id * @return MeterFilterReply */ public MeterFilterReply accept(Meter.Id id) { if (!k8sMetricsProperties.isEnableCommonMetricsFilter()) { return MeterFilter.super.accept(id); } String metricName = id.getName(); Boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, null); if (enabled != null) { return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; } if (whitelist.contains(metricName)) { return MeterFilterReply.NEUTRAL; } if (blacklist.contains(metricName)) { return MeterFilterReply.DENY; } for(String prefix: prefixes) { if (metricName.startsWith(prefix)) { return MeterFilterReply.ACCEPT; } } for(String key: tagRules.keySet()) { String expectedValue = tagRules.get(key); if (expectedValue != null) { if (expectedValue.equals(id.getTag(key))) { return MeterFilterReply.ACCEPT; } } } return MeterFilterReply.DENY; }
Example #24
Source File: CommonMetricsFilter.java From foremast with Apache License 2.0 | 5 votes |
/** * Filter for "[PREFIX]_*" * * @param id * @return MeterFilterReply */ public MeterFilterReply accept(Meter.Id id) { if (!k8sMetricsProperties.isEnableCommonMetricsFilter()) { return MeterFilter.super.accept(id); } String metricName = id.getName(); Boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, null); if (enabled != null) { return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; } if (whitelist.contains(metricName)) { return MeterFilterReply.NEUTRAL; } if (blacklist.contains(metricName)) { return MeterFilterReply.DENY; } for(String prefix: prefixes) { if (metricName.startsWith(prefix)) { return MeterFilterReply.ACCEPT; } } for(String key: tagRules.keySet()) { String expectedValue = tagRules.get(key); if (expectedValue != null) { if (expectedValue.equals(id.getTag(key))) { return MeterFilterReply.ACCEPT; } } } return MeterFilterReply.DENY; }
Example #25
Source File: PropertiesMeterFilter.java From foremast with Apache License 2.0 | 4 votes |
@Override public MeterFilterReply accept(Meter.Id id) { boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, true); return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; }
Example #26
Source File: PropertiesMeterFilter.java From foremast with Apache License 2.0 | 4 votes |
@Override public MeterFilterReply accept(Meter.Id id) { boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, true); return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; }