Merge branch '2.6.x' into 2.7.x

Closes gh-32989
pull/33648/head
Andy Wilkinson 2 years ago
commit 394ae76b04

@ -26,6 +26,7 @@ import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfigu
import org.springframework.boot.autoconfigure.AutoConfiguration;
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;
@ -44,8 +45,13 @@ import org.springframework.context.annotation.Bean;
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();
}
}
}

Loading…
Cancel
Save