Java Code Examples for io.micrometer.core.instrument.config.MeterFilterReply#NEUTRAL

The following examples show how to use io.micrometer.core.instrument.config.MeterFilterReply#NEUTRAL . 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: CommonMetricsFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * 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 2
Source File: CommonMetricsFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * 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 3
Source File: CommonMetricsFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: CommonMetricsFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: Search.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * @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 6
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Override
public MeterFilterReply accept(Meter.Id id) {
    boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, true);
    return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY;
}
 
Example 7
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Override
public MeterFilterReply accept(Meter.Id id) {
    boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, true);
    return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY;
}