Polish
This commit is contained in:
parent
d238a31d3d
commit
6771cc9674
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics.config;
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.config.MissingRequiredConfigurationException;
|
||||
|
|
@ -68,8 +68,8 @@ public class RabbitMetricsAutoConfiguration {
|
|||
ConnectionFactory rabbitConnectionFactory = connectionFactory
|
||||
.getRabbitConnectionFactory();
|
||||
String connectionFactoryName = getConnectionFactoryName(beanName);
|
||||
new RabbitMetrics(rabbitConnectionFactory,
|
||||
Tags.of("name", connectionFactoryName)).bindTo(this.registry);
|
||||
new RabbitMetrics(rabbitConnectionFactory, Tags.of("name", connectionFactoryName))
|
||||
.bindTo(this.registry);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
|
|
@ -69,8 +69,8 @@ public class DataSourcePoolMetricsAutoConfiguration {
|
|||
|
||||
private void bindDataSourceToRegistry(String beanName, DataSource dataSource) {
|
||||
String dataSourceName = getDataSourceName(beanName);
|
||||
new DataSourcePoolMetrics(dataSource, this.metadataProviders,
|
||||
dataSourceName, Collections.emptyList()).bindTo(this.registry);
|
||||
new DataSourcePoolMetrics(dataSource, this.metadataProviders, dataSourceName,
|
||||
Collections.emptyList()).bindTo(this.registry);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
|
|
@ -41,8 +41,7 @@ class MongoHealthIndicatorConfiguration extends
|
|||
|
||||
private final Map<String, MongoTemplate> mongoTemplates;
|
||||
|
||||
MongoHealthIndicatorConfiguration(
|
||||
Map<String, MongoTemplate> mongoTemplates) {
|
||||
MongoHealthIndicatorConfiguration(Map<String, MongoTemplate> mongoTemplates) {
|
||||
this.mongoTemplates = mongoTemplates;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,5 +75,6 @@ org.springframework.boot.actuate.autoconfigure.web.jersey.JerseyManagementChildC
|
|||
org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementChildContextConfiguration,\
|
||||
org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChildContextConfiguration,\
|
||||
org.springframework.boot.actuate.autoconfigure.web.servlet.WebMvcEndpointChildContextConfiguration
|
||||
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
org.springframework.boot.actuate.autoconfigure.metrics.config.MissingRequiredConfigurationFailureAnalyzer
|
||||
org.springframework.boot.actuate.autoconfigure.metrics.MissingRequiredConfigurationFailureAnalyzer
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics.config;
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.Clock;
|
||||
import io.micrometer.newrelic.NewRelicConfig;
|
|
@ -47,8 +47,7 @@ public class RabbitMetricsAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.metrics.enable.rabbitmq=false")
|
||||
this.contextRunner.withPropertyValues("management.metrics.enable.rabbitmq=false")
|
||||
.run((context) -> {
|
||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||
assertThat(registry.find("rabbitmq.connections").meter()).isNull();
|
||||
|
|
|
@ -88,8 +88,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
|||
context.getBean("secondOne", DataSource.class).getConnection()
|
||||
.getMetaData();
|
||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||
registry.get("jdbc.max.connections").tags("name", "first")
|
||||
.meter();
|
||||
registry.get("jdbc.max.connections").tags("name", "first").meter();
|
||||
registry.get("jdbc.max.connections").tags("name", "secondOne")
|
||||
.meter();
|
||||
});
|
||||
|
|
|
@ -39,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class MongoReactiveHealthIndicatorConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
MongoAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
||||
MongoDataAutoConfiguration.class,
|
||||
MongoReactiveAutoConfiguration.class,
|
||||
MongoReactiveDataAutoConfiguration.class,
|
||||
|
@ -49,10 +48,10 @@ public class MongoReactiveHealthIndicatorConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void runShouldCreateIndicator() {
|
||||
this.contextRunner.run(
|
||||
(context) -> assertThat(context).hasSingleBean(MongoReactiveHealthIndicator.class)
|
||||
.doesNotHaveBean(MongoHealthIndicator.class)
|
||||
.doesNotHaveBean(ApplicationHealthIndicator.class));
|
||||
this.contextRunner.run((context) -> assertThat(context)
|
||||
.hasSingleBean(MongoReactiveHealthIndicator.class)
|
||||
.doesNotHaveBean(MongoHealthIndicator.class)
|
||||
.doesNotHaveBean(ApplicationHealthIndicator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -49,8 +49,8 @@ public class DataSourcePoolMetrics implements MeterBinder {
|
|||
private final Iterable<Tag> tags;
|
||||
|
||||
public DataSourcePoolMetrics(DataSource dataSource,
|
||||
Collection<DataSourcePoolMetadataProvider> metadataProviders, String dataSourceName,
|
||||
Iterable<Tag> tags) {
|
||||
Collection<DataSourcePoolMetadataProvider> metadataProviders,
|
||||
String dataSourceName, Iterable<Tag> tags) {
|
||||
this(dataSource, new CompositeDataSourcePoolMetadataProvider(metadataProviders),
|
||||
dataSourceName, tags);
|
||||
}
|
||||
|
@ -75,9 +75,10 @@ public class DataSourcePoolMetrics implements MeterBinder {
|
|||
}
|
||||
}
|
||||
|
||||
private <N extends Number> void bindPoolMetadata(MeterRegistry registry, String metricName,
|
||||
Function<DataSourcePoolMetadata, N> function) {
|
||||
bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function));
|
||||
private <N extends Number> void bindPoolMetadata(MeterRegistry registry,
|
||||
String metricName, Function<DataSourcePoolMetadata, N> function) {
|
||||
bindDataSource(registry, metricName,
|
||||
this.metadataProvider.getValueFunction(function));
|
||||
}
|
||||
|
||||
private <N extends Number> void bindDataSource(MeterRegistry registry,
|
||||
|
|
|
@ -43,8 +43,7 @@ public class RabbitMetricsTests {
|
|||
public void connectionFactoryWithTagsIsInstrumented() {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
SimpleMeterRegistry registry = new SimpleMeterRegistry();
|
||||
new RabbitMetrics(connectionFactory, Tags.of("env", "prod"))
|
||||
.bindTo(registry);
|
||||
new RabbitMetrics(connectionFactory, Tags.of("env", "prod")).bindTo(registry);
|
||||
assertThat(registry.get("rabbitmq.connections").tags("env", "prod").meter())
|
||||
.isNotNull();
|
||||
assertThat(registry.find("rabbitmq.connections").tags("env", "dev").meter())
|
||||
|
|
|
@ -50,8 +50,8 @@ public class DataSourcePoolMetricsTests {
|
|||
"metrics.use-global-registry=false")
|
||||
.run((context) -> {
|
||||
context.getBean(DataSource.class).getConnection().getMetaData();
|
||||
context.getBean(MeterRegistry.class)
|
||||
.get("jdbc.max.connections").meter();
|
||||
context.getBean(MeterRegistry.class).get("jdbc.max.connections")
|
||||
.meter();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -42,10 +42,10 @@ public class MongoReactiveHealthIndicatorTest {
|
|||
Document buildInfo = mock(Document.class);
|
||||
given(buildInfo.getString("version")).willReturn("2.6.4");
|
||||
ReactiveMongoTemplate reactiveMongoTemplate = mock(ReactiveMongoTemplate.class);
|
||||
given(reactiveMongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(
|
||||
Mono.just(buildInfo));
|
||||
|
||||
MongoReactiveHealthIndicator mongoReactiveHealthIndicator = new MongoReactiveHealthIndicator(reactiveMongoTemplate);
|
||||
given(reactiveMongoTemplate.executeCommand("{ buildInfo: 1 }"))
|
||||
.willReturn(Mono.just(buildInfo));
|
||||
MongoReactiveHealthIndicator mongoReactiveHealthIndicator = new MongoReactiveHealthIndicator(
|
||||
reactiveMongoTemplate);
|
||||
Mono<Health> health = mongoReactiveHealthIndicator.health();
|
||||
StepVerifier.create(health).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
|
@ -57,10 +57,10 @@ public class MongoReactiveHealthIndicatorTest {
|
|||
@Test
|
||||
public void testMongoIsDown() {
|
||||
ReactiveMongoTemplate reactiveMongoTemplate = mock(ReactiveMongoTemplate.class);
|
||||
given(reactiveMongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow(
|
||||
new MongoException("Connection failed"));
|
||||
|
||||
MongoReactiveHealthIndicator mongoReactiveHealthIndicator = new MongoReactiveHealthIndicator(reactiveMongoTemplate);
|
||||
given(reactiveMongoTemplate.executeCommand("{ buildInfo: 1 }"))
|
||||
.willThrow(new MongoException("Connection failed"));
|
||||
MongoReactiveHealthIndicator mongoReactiveHealthIndicator = new MongoReactiveHealthIndicator(
|
||||
reactiveMongoTemplate);
|
||||
Mono<Health> health = mongoReactiveHealthIndicator.health();
|
||||
StepVerifier.create(health).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Collections;
|
|||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -189,29 +190,23 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
|
|||
}
|
||||
|
||||
/**
|
||||
* Log the original exception if handling it results in a Server Error or a Bad Request
|
||||
* (Client Error with 400 status code) one.
|
||||
* Log the original exception if handling it results in a Server Error or a Bad
|
||||
* Request (Client Error with 400 status code) one.
|
||||
* @param request the source request
|
||||
* @param errorStatus the HTTP error status
|
||||
*/
|
||||
protected void logError(ServerRequest request, HttpStatus errorStatus) {
|
||||
if (errorStatus.is5xxServerError()) {
|
||||
Throwable ex = getError(request);
|
||||
if (ex instanceof ResponseStatusException) {
|
||||
logger.error(buildMessage(request, ex));
|
||||
}
|
||||
else {
|
||||
logger.error(buildMessage(request, null), ex);
|
||||
}
|
||||
Throwable ex = getError(request);
|
||||
log(request, ex, (errorStatus.is5xxServerError() ? logger::error : logger::warn));
|
||||
}
|
||||
|
||||
private void log(ServerRequest request, Throwable ex,
|
||||
BiConsumer<Object, Throwable> logger) {
|
||||
if (ex instanceof ResponseStatusException) {
|
||||
logger.accept(buildMessage(request, ex), null);
|
||||
}
|
||||
else if (errorStatus == HttpStatus.BAD_REQUEST) {
|
||||
Throwable ex = getError(request);
|
||||
if (ex instanceof ResponseStatusException) {
|
||||
logger.warn(buildMessage(request, ex));
|
||||
}
|
||||
else {
|
||||
logger.warn(buildMessage(request, null), ex);
|
||||
}
|
||||
else {
|
||||
logger.accept(buildMessage(request, null), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue