Allow histograms to be disabled for Lettuce metrics
Closes gh-32985
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.data.redis.ClientResourcesBuilderCustomizer;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -47,8 +48,13 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class LettuceMetricsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public ClientResourcesBuilderCustomizer lettuceMetrics(MeterRegistry meterRegistry) {
|
||||
MicrometerOptions options = MicrometerOptions.builder().histogram(true).build();
|
||||
@ConditionalOnMissingBean
|
||||
MicrometerOptions micrometerOptions() {
|
||||
return MicrometerOptions.builder().histogram(true).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
ClientResourcesBuilderCustomizer lettuceMetrics(MeterRegistry meterRegistry, MicrometerOptions options) {
|
||||
return (client) -> client.commandLatencyRecorder(new MicrometerCommandLatencyRecorder(meterRegistry, options));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics.redis;
|
||||
|
||||
import io.lettuce.core.metrics.MicrometerCommandLatencyRecorder;
|
||||
import io.lettuce.core.metrics.MicrometerOptions;
|
||||
import io.lettuce.core.resource.ClientResources;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -24,6 +25,8 @@ import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -49,6 +52,20 @@ class LettuceMetricsAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUserDefinesAMicrometerOptionsBeanThenCommandLatencyRecorderUsesIt() {
|
||||
this.contextRunner.with(MetricsRun.simple())
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.withUserConfiguration(CustomMicrometerOptionsConfiguration.class).run((context) -> {
|
||||
ClientResources clientResources = context.getBean(LettuceConnectionFactory.class)
|
||||
.getClientResources();
|
||||
assertThat(clientResources.commandLatencyRecorder())
|
||||
.isInstanceOf(MicrometerCommandLatencyRecorder.class);
|
||||
assertThat(clientResources.commandLatencyRecorder()).hasFieldOrPropertyWithValue("options",
|
||||
context.getBean("customMicrometerOptions"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenThereIsNoMeterRegistryThenClientResourcesCustomizationBacksOff() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
|
||||
@@ -58,4 +75,14 @@ class LettuceMetricsAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomMicrometerOptionsConfiguration {
|
||||
|
||||
@Bean
|
||||
MicrometerOptions customMicrometerOptions() {
|
||||
return MicrometerOptions.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user