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;
}
});
}
Aggregations