mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Rename OnlyOnceLoggingDenyMeterFilter
Rename `OnlyOnceLoggingDenyMeterFilter` to `MaximumAllowableTagsMeterFilter`. Closes gh-47925
This commit is contained in:
+3
-3
@@ -23,7 +23,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.micrometer.metrics.OnlyOnceLoggingDenyMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.MaximumAllowableTagsMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsProperties;
|
||||
import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsProperties.Web.Client;
|
||||
import org.springframework.boot.micrometer.observation.autoconfigure.ObservationProperties;
|
||||
@@ -50,12 +50,12 @@ public final class HttpClientMetricsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@Order(0)
|
||||
OnlyOnceLoggingDenyMeterFilter metricsHttpClientUriTagFilter(ObservationProperties observationProperties,
|
||||
MaximumAllowableTagsMeterFilter metricsHttpClientUriTagFilter(ObservationProperties observationProperties,
|
||||
MetricsProperties metricsProperties) {
|
||||
Client clientProperties = metricsProperties.getWeb().getClient();
|
||||
String meterNamePrefix = observationProperties.getHttp().getClient().getRequests().getName();
|
||||
int maxUriTags = clientProperties.getMaxUriTags();
|
||||
return new OnlyOnceLoggingDenyMeterFilter(meterNamePrefix, "uri", maxUriTags, "Are you using 'uriVariables'?");
|
||||
return new MaximumAllowableTagsMeterFilter(meterNamePrefix, "uri", maxUriTags, "Are you using 'uriVariables'?");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -39,7 +39,7 @@ import org.springframework.util.Assert;
|
||||
* @author Phillip Webb
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public final class OnlyOnceLoggingDenyMeterFilter implements MeterFilter {
|
||||
public final class MaximumAllowableTagsMeterFilter implements MeterFilter {
|
||||
|
||||
private final Log logger;
|
||||
|
||||
@@ -56,36 +56,36 @@ public final class OnlyOnceLoggingDenyMeterFilter implements MeterFilter {
|
||||
private final Set<String> observedTagValues = ConcurrentHashMap.newKeySet();
|
||||
|
||||
/**
|
||||
* Create a new {@link OnlyOnceLoggingDenyMeterFilter} with an upper bound on the
|
||||
* Create a new {@link MaximumAllowableTagsMeterFilter} with an upper bound on the
|
||||
* number of tags produced by matching metrics.
|
||||
* @param meterNamePrefix the prefix of the meter name to apply the filter to
|
||||
* @param tagKey the tag to place an upper bound on
|
||||
* @param maximumTagValues the total number of tag values that are allowable
|
||||
*/
|
||||
public OnlyOnceLoggingDenyMeterFilter(String meterNamePrefix, String tagKey, int maximumTagValues) {
|
||||
public MaximumAllowableTagsMeterFilter(String meterNamePrefix, String tagKey, int maximumTagValues) {
|
||||
this(meterNamePrefix, tagKey, maximumTagValues, (String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link OnlyOnceLoggingDenyMeterFilter} with an upper bound on the
|
||||
* Create a new {@link MaximumAllowableTagsMeterFilter} with an upper bound on the
|
||||
* number of tags produced by matching metrics.
|
||||
* @param meterNamePrefix the prefix of the meter name to apply the filter to
|
||||
* @param tagKey the tag to place an upper bound on
|
||||
* @param maximumTagValues the total number of tag values that are allowable
|
||||
* @param hint an additional hint to add to the logged message or {@code null}
|
||||
*/
|
||||
public OnlyOnceLoggingDenyMeterFilter(String meterNamePrefix, String tagKey, int maximumTagValues,
|
||||
public MaximumAllowableTagsMeterFilter(String meterNamePrefix, String tagKey, int maximumTagValues,
|
||||
@Nullable String hint) {
|
||||
this(null, meterNamePrefix, tagKey, maximumTagValues,
|
||||
() -> String.format("Reached the maximum number of '%s' tags for '%s'.%s", tagKey, meterNamePrefix,
|
||||
(hint != null) ? " " + hint : ""));
|
||||
}
|
||||
|
||||
private OnlyOnceLoggingDenyMeterFilter(@Nullable Log logger, String meterNamePrefix, String tagKey,
|
||||
private MaximumAllowableTagsMeterFilter(@Nullable Log logger, String meterNamePrefix, String tagKey,
|
||||
int maximumTagValues, Supplier<String> message) {
|
||||
Assert.notNull(message, "'message' must not be null");
|
||||
Assert.isTrue(maximumTagValues >= 0, "'maximumTagValues' must be positive");
|
||||
this.logger = (logger != null) ? logger : LogFactory.getLog(OnlyOnceLoggingDenyMeterFilter.class);
|
||||
this.logger = (logger != null) ? logger : LogFactory.getLog(MaximumAllowableTagsMeterFilter.class);
|
||||
this.meterNamePrefix = meterNamePrefix;
|
||||
this.maximumTagValues = maximumTagValues;
|
||||
this.tagKey = tagKey;
|
||||
+2
-2
@@ -31,7 +31,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.micrometer.metrics.OnlyOnceLoggingDenyMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.MaximumAllowableTagsMeterFilter;
|
||||
import org.springframework.boot.util.LambdaSafe;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
@@ -114,7 +114,7 @@ class MeterRegistryPostProcessor implements BeanPostProcessor, SmartInitializing
|
||||
if (this.filters != null) {
|
||||
Stream<MeterFilter> filters = this.filters.orderedStream();
|
||||
if (isAutoConfiguredComposite(meterRegistry)) {
|
||||
filters = filters.filter(OnlyOnceLoggingDenyMeterFilter.class::isInstance);
|
||||
filters = filters.filter(MaximumAllowableTagsMeterFilter.class::isInstance);
|
||||
}
|
||||
filters.forEach(meterRegistry.config()::meterFilter);
|
||||
}
|
||||
|
||||
+5
-5
@@ -29,22 +29,22 @@ import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnlyOnceLoggingDenyMeterFilter}.
|
||||
* Tests for {@link MaximumAllowableTagsMeterFilter}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class OnlyOnceLoggingDenyMeterFilterTests {
|
||||
class MaximumAllowableTagsMeterFilterTests {
|
||||
|
||||
@Test
|
||||
void applyWhenNameDoesNotHavePrefixReturnsNeutral() {
|
||||
OnlyOnceLoggingDenyMeterFilter filter = new OnlyOnceLoggingDenyMeterFilter("test", "k", 1);
|
||||
MaximumAllowableTagsMeterFilter filter = new MaximumAllowableTagsMeterFilter("test", "k", 1);
|
||||
assertThat(filter.accept(meterId("tset", "k", "v"))).isEqualTo(MeterFilterReply.NEUTRAL);
|
||||
assertThat(filter).extracting("observedTagValues").asInstanceOf(InstanceOfAssertFactories.COLLECTION).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyWhenNameHasPrefixButNoTagKeyReturnsNeutral() {
|
||||
OnlyOnceLoggingDenyMeterFilter filter = new OnlyOnceLoggingDenyMeterFilter("test", "k", 1);
|
||||
MaximumAllowableTagsMeterFilter filter = new MaximumAllowableTagsMeterFilter("test", "k", 1);
|
||||
assertThat(filter.accept(meterId("test", "k", "v"))).isEqualTo(MeterFilterReply.NEUTRAL);
|
||||
assertThat(filter).extracting("observedTagValues")
|
||||
.asInstanceOf(InstanceOfAssertFactories.COLLECTION)
|
||||
@@ -53,7 +53,7 @@ class OnlyOnceLoggingDenyMeterFilterTests {
|
||||
|
||||
@Test
|
||||
void applyWhenNameHasPrefixAndTagKeyReturnsNeutralUntilLimit() {
|
||||
OnlyOnceLoggingDenyMeterFilter filter = new OnlyOnceLoggingDenyMeterFilter("test", "k", 1);
|
||||
MaximumAllowableTagsMeterFilter filter = new MaximumAllowableTagsMeterFilter("test", "k", 1);
|
||||
assertThat(filter.accept(meterId("test", "k", "v1"))).isEqualTo(MeterFilterReply.NEUTRAL);
|
||||
assertThat(filter.accept(meterId("test", "k", "v2"))).isEqualTo(MeterFilterReply.DENY);
|
||||
assertThat(filter.accept(meterId("test", "k", "v3"))).isEqualTo(MeterFilterReply.DENY);
|
||||
+2
-2
@@ -38,7 +38,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.micrometer.metrics.OnlyOnceLoggingDenyMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.MaximumAllowableTagsMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.autoconfigure.MeterRegistryPostProcessor.CompositeMeterRegistries;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -136,7 +136,7 @@ class MeterRegistryPostProcessorTests {
|
||||
|
||||
@Test
|
||||
void postProcessAndInitializeOnlyAppliesLmiitedFiltersToAutoConfigured() {
|
||||
OnlyOnceLoggingDenyMeterFilter onlyOnceFilter = mock();
|
||||
MaximumAllowableTagsMeterFilter onlyOnceFilter = mock();
|
||||
this.filters.add(this.mockFilter);
|
||||
this.filters.add(onlyOnceFilter);
|
||||
MeterRegistryPostProcessor processor = new MeterRegistryPostProcessor(CompositeMeterRegistries.AUTO_CONFIGURED,
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.micrometer.metrics.OnlyOnceLoggingDenyMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.MaximumAllowableTagsMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsProperties;
|
||||
import org.springframework.boot.micrometer.observation.autoconfigure.ObservationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -63,10 +63,10 @@ public final class WebFluxObservationAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@Order(0)
|
||||
OnlyOnceLoggingDenyMeterFilter metricsHttpServerUriTagFilter(MetricsProperties metricsProperties) {
|
||||
MaximumAllowableTagsMeterFilter metricsHttpServerUriTagFilter(MetricsProperties metricsProperties) {
|
||||
String meterNamePrefix = this.observationProperties.getHttp().getServer().getRequests().getName();
|
||||
int maxUriTags = metricsProperties.getWeb().getServer().getMaxUriTags();
|
||||
return new OnlyOnceLoggingDenyMeterFilter(meterNamePrefix, "uri", maxUriTags);
|
||||
return new MaximumAllowableTagsMeterFilter(meterNamePrefix, "uri", maxUriTags);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingFilt
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.micrometer.metrics.OnlyOnceLoggingDenyMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.MaximumAllowableTagsMeterFilter;
|
||||
import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsProperties;
|
||||
import org.springframework.boot.micrometer.observation.autoconfigure.ObservationProperties;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
@@ -85,11 +85,11 @@ public final class WebMvcObservationAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@Order(0)
|
||||
OnlyOnceLoggingDenyMeterFilter metricsHttpServerUriTagFilter(ObservationProperties observationProperties,
|
||||
MaximumAllowableTagsMeterFilter metricsHttpServerUriTagFilter(ObservationProperties observationProperties,
|
||||
MetricsProperties metricsProperties) {
|
||||
String meterNamePrefix = observationProperties.getHttp().getServer().getRequests().getName();
|
||||
int maxUriTags = metricsProperties.getWeb().getServer().getMaxUriTags();
|
||||
return new OnlyOnceLoggingDenyMeterFilter(meterNamePrefix, "uri", maxUriTags);
|
||||
return new MaximumAllowableTagsMeterFilter(meterNamePrefix, "uri", maxUriTags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user