Skip to content

Commit

Permalink
Merge branch '1.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatan-ivanov committed Aug 31, 2021
2 parents df8a65c + 8e2fb63 commit faedc1c
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.stream.Collectors;

import io.micrometer.core.lang.Nullable;
import io.micrometer.core.util.internal.logging.InternalLogger;
Expand Down Expand Up @@ -158,6 +159,10 @@ void checkAndBindMetrics(MeterRegistry registry) {

if (!currentMeters.equals(metrics.keySet())) {
currentMeters = new HashSet<>(metrics.keySet());

Map<String, List<Meter>> registryMetersByNames = registry.getMeters().stream()
.collect(Collectors.groupingBy(meter -> meter.getId().getName()));

metrics.forEach((name, metric) -> {
// Filter out non-numeric values
// Filter out metrics from groups that include metadata
Expand All @@ -172,7 +177,7 @@ void checkAndBindMetrics(MeterRegistry registry) {
// Kafka has metrics with lower number of tags (e.g. with/without topic or partition tag)
// Remove meters with lower number of tags
boolean hasLessTags = false;
for (Meter other : registry.find(meterName).meters()) {
for (Meter other : registryMetersByNames.getOrDefault(meterName, emptyList())) {
List<Tag> tags = other.getId().getTags();
List<Tag> meterTagsWithCommonTags = meterTags(metric, true);
if (tags.size() < meterTagsWithCommonTags.size()) {
Expand All @@ -186,9 +191,12 @@ else if (tags.size() == meterTagsWithCommonTags.size())
else hasLessTags = true;
}
if (hasLessTags) return;

List<Tag> tags = meterTags(metric);
try {
bindMeter(registry, metric, meterName, tags);
Meter meter = bindMeter(registry, metric, meterName, tags);
List<Meter> meters = registryMetersByNames.computeIfAbsent(meterName, k -> new ArrayList<>());
meters.add(meter);
}
catch (Exception ex) {
String message = ex.getMessage();
Expand All @@ -204,9 +212,10 @@ else if (tags.size() == meterTagsWithCommonTags.size())
}
}

private void bindMeter(MeterRegistry registry, Metric metric, String name, Iterable<Tag> tags) {
private Meter bindMeter(MeterRegistry registry, Metric metric, String name, Iterable<Tag> tags) {
Meter meter = registerMeter(registry, metric, name, tags);
registeredMeters.add(meter);
return meter;
}

private Meter registerMeter(MeterRegistry registry, Metric metric, String name, Iterable<Tag> tags) {
Expand Down

0 comments on commit faedc1c

Please sign in to comment.