Skip to content

Commit

Permalink
keep lettuce metrics; strip remote tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-signal committed Aug 18, 2023
1 parent eeea97e commit 17d48b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,21 @@ public DistributionStatisticConfig configure(final Meter.Id id, final Distributi
return defaultDistributionStatisticConfig.merge(config);
}
})
// Remove high-cardinality `command` tags from Lettuce metrics and prepend "chat." to meter names
// Remove high-cardinality `command` and `remote` tags from Lettuce metrics and prepend "chat." to meter names
.meterFilter(new MeterFilter() {
@Override
public Meter.Id map(final Meter.Id id) {
if (id.getName().startsWith("lettuce")) {
return id.withName(PREFIX + "." + id.getName())
.replaceTags(id.getTags().stream()
.filter(tag -> !"command".equals(tag.getKey()))
.filter(tag -> !"remote".equals(tag.getKey()))
.toList());
}

return MeterFilter.super.map(id);
}
})
// Deny lettuce metrics, but leave command.completions.max. Note that regardless of configured order, accept
// filters are applied after map filters.
.meterFilter(MeterFilter.deny(id ->
id.getName().startsWith(PREFIX + ".lettuce") && !id.getName().contains("command.completion.max")
))
.meterFilter(MeterFilter.denyNameStartsWith(PushLatencyManager.TIMER_NAME + ".percentile"))
.meterFilter(MeterFilter.denyNameStartsWith(MessageMetrics.DELIVERY_LATENCY_TIMER_NAME + ".percentile"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,18 @@ void name() {
}

@Test
void lettuceRejection() {
void lettuceTagRejection() {
MeterRegistry registry = new SimpleMeterRegistry();
MetricsUtil.configureMeterFilters(registry.config());

registry.counter("lettuce.command.completion.count").increment();
registry.counter("lettuce.command.firstresponse.max").increment();
registry.counter("lettuce.test").increment();
assertThat(registry.getMeters()).isEmpty();

// this lettuce statistic is allow-listed
registry.counter("lettuce.command.completion.max", "command", "hello", "remote", "world").increment();
registry.counter("lettuce.command.completion.max", "command", "hello", "remote", "world", "allowed", "!").increment();
final List<Meter> meters = registry.getMeters();
assertThat(meters).hasSize(1);

Meter meter = meters.get(0);
assertThat(meter.getId().getName()).isEqualTo("chat.lettuce.command.completion.max");
assertThat(meter.getId().getTag("command")).isNull();
assertThat(meter.getId().getTag("remote")).isNotNull();
assertThat(meter.getId().getTag("remote")).isNull();
assertThat(meter.getId().getTag("allowed")).isNotNull();
}
}

0 comments on commit 17d48b9

Please sign in to comment.