|
|
@ -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");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with 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;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.redis;
|
|
|
|
|
|
|
|
|
|
|
|
import io.lettuce.core.metrics.MicrometerCommandLatencyRecorder;
|
|
|
|
import io.lettuce.core.metrics.MicrometerCommandLatencyRecorder;
|
|
|
|
|
|
|
|
import io.lettuce.core.metrics.MicrometerOptions;
|
|
|
|
import io.lettuce.core.resource.ClientResources;
|
|
|
|
import io.lettuce.core.resource.ClientResources;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
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.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
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 org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
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
|
|
|
|
@Test
|
|
|
|
void whenThereIsNoMeterRegistryThenClientResourcesCustomizationBacksOff() {
|
|
|
|
void whenThereIsNoMeterRegistryThenClientResourcesCustomizationBacksOff() {
|
|
|
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
|
|
|
|
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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|