Search in sources :

Example 1 with Label

use of io.vertx.micrometer.Label in project vertx-micrometer-metrics by vert-x3.

the class BackendRegistries method registerMatchers.

public static void registerMatchers(MeterRegistry registry, Set<Label> enabledLabels, List<Match> matches) {
    String[] ignored = EnumSet.complementOf(EnumSet.copyOf(enabledLabels)).stream().map(Label::toString).toArray(String[]::new);
    registry.config().meterFilter(MeterFilter.ignoreTags(ignored));
    matches.forEach(m -> {
        switch(m.getType()) {
            case EQUALS:
                if (m.getAlias() == null) {
                    // Exact match => accept
                    registry.config().meterFilter(MeterFilter.deny(id -> {
                        if (m.getDomain() != null && !id.getName().startsWith(m.getDomain().getPrefix())) {
                            // If domain has been specified and we're not in that domain, ignore rule
                            return false;
                        }
                        String tagValue = id.getTag(m.getLabel());
                        return !m.getValue().equals(tagValue);
                    }));
                } else {
                    // Exact match => alias
                    registry.config().meterFilter(replaceTagValues(m.getDomain(), m.getLabel(), val -> {
                        if (m.getValue().equals(val)) {
                            return m.getAlias();
                        }
                        return val;
                    }));
                }
                break;
            case REGEX:
                Pattern pattern = Pattern.compile(m.getValue());
                if (m.getAlias() == null) {
                    // Regex match => accept
                    registry.config().meterFilter(MeterFilter.accept(id -> {
                        if (m.getDomain() != null && !id.getName().startsWith(m.getDomain().getPrefix())) {
                            // If domain has been specified and we're not in that domain, ignore rule
                            return true;
                        }
                        String tagValue = id.getTag(m.getLabel());
                        if (tagValue == null) {
                            return false;
                        }
                        return pattern.matcher(tagValue).matches();
                    }));
                } else {
                    // Regex match => alias
                    registry.config().meterFilter(replaceTagValues(m.getDomain(), m.getLabel(), val -> {
                        if (pattern.matcher(val).matches()) {
                            return m.getAlias();
                        }
                        return val;
                    }));
                }
                break;
        }
    });
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) VertxInfluxDbOptions(io.vertx.micrometer.VertxInfluxDbOptions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Meter(io.micrometer.core.instrument.Meter) MetricsDomain(io.vertx.micrometer.MetricsDomain) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Function(java.util.function.Function) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) List(java.util.List) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) Map(java.util.Map) Label(io.vertx.micrometer.Label) Match(io.vertx.micrometer.Match) Pattern(java.util.regex.Pattern) EnumSet(java.util.EnumSet) Pattern(java.util.regex.Pattern)

Aggregations

Meter (io.micrometer.core.instrument.Meter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)1 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)1 Label (io.vertx.micrometer.Label)1 Match (io.vertx.micrometer.Match)1 MetricsDomain (io.vertx.micrometer.MetricsDomain)1 MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)1 VertxInfluxDbOptions (io.vertx.micrometer.VertxInfluxDbOptions)1 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Function (java.util.function.Function)1 Pattern (java.util.regex.Pattern)1