Polish
This commit is contained in:
parent
cdb5677375
commit
05faac2b09
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -54,19 +54,16 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autoConfiguredDataSourceIsInstrumented() {
|
public void autoConfiguredDataSourceIsInstrumented() {
|
||||||
this.contextRunner
|
this.contextRunner.run((context) -> {
|
||||||
.run((context) -> {
|
context.getBean(DataSource.class).getConnection().getMetaData();
|
||||||
context.getBean(DataSource.class).getConnection().getMetaData();
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
registry.get("jdbc.connections.max").tags("name", "dataSource").meter();
|
||||||
registry.get("jdbc.connections.max").tags("name", "dataSource")
|
});
|
||||||
.meter();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataSourceInstrumentationCanBeDisabled() {
|
public void dataSourceInstrumentationCanBeDisabled() {
|
||||||
this.contextRunner
|
this.contextRunner.withPropertyValues("management.metrics.enable.jdbc=false")
|
||||||
.withPropertyValues("management.metrics.enable.jdbc=false")
|
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
context.getBean(DataSource.class).getConnection().getMetaData();
|
context.getBean(DataSource.class).getConnection().getMetaData();
|
||||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||||
|
@ -92,23 +89,20 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autoConfiguredHikariDataSourceIsInstrumented() {
|
public void autoConfiguredHikariDataSourceIsInstrumented() {
|
||||||
this.contextRunner
|
this.contextRunner.run((context) -> {
|
||||||
.run((context) -> {
|
context.getBean(DataSource.class).getConnection();
|
||||||
context.getBean(DataSource.class).getConnection();
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
registry.get("hikaricp.connections").meter();
|
||||||
registry.get("hikaricp.connections").meter();
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hikariDataSourceInstrumentationCanBeDisabled() {
|
public void hikariDataSourceInstrumentationCanBeDisabled() {
|
||||||
this.contextRunner
|
this.contextRunner.withPropertyValues("management.metrics.enable.hikaricp=false")
|
||||||
.withPropertyValues("management.metrics.enable.hikaricp=false")
|
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
context.getBean(DataSource.class).getConnection();
|
context.getBean(DataSource.class).getConnection();
|
||||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||||
assertThat(registry.find("hikaricp.connections").meter())
|
assertThat(registry.find("hikaricp.connections").meter()).isNull();
|
||||||
.isNull();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +129,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
||||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||||
assertThat(registry.get("hikaricp.connections").meter().getId()
|
assertThat(registry.get("hikaricp.connections").meter().getId()
|
||||||
.getTags())
|
.getTags())
|
||||||
.containsExactly(Tag.of("pool", "firstDataSource"));
|
.containsExactly(Tag.of("pool", "firstDataSource"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,8 +209,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
||||||
|
|
||||||
private org.apache.tomcat.jdbc.pool.DataSource createTomcatDataSource() {
|
private org.apache.tomcat.jdbc.pool.DataSource createTomcatDataSource() {
|
||||||
String url = "jdbc:hsqldb:mem:test-" + UUID.randomUUID();
|
String url = "jdbc:hsqldb:mem:test-" + UUID.randomUUID();
|
||||||
return DataSourceBuilder
|
return DataSourceBuilder.create().url(url)
|
||||||
.create().url(url)
|
|
||||||
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,20 @@ import java.security.Principal;
|
||||||
*/
|
*/
|
||||||
public interface SecurityContext {
|
public interface SecurityContext {
|
||||||
|
|
||||||
|
public static SecurityContext NONE = new SecurityContext() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Principal getPrincipal() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUserInRole(String role) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently authenticated {@link Principal} or {@code null}.
|
* Return the currently authenticated {@link Principal} or {@code null}.
|
||||||
* @return the principal or {@code null}
|
* @return the principal or {@code null}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.endpoint.jmx;
|
package org.springframework.boot.actuate.endpoint.jmx;
|
||||||
|
|
||||||
import java.security.Principal;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -100,7 +99,7 @@ public class EndpointMBean implements DynamicMBean {
|
||||||
.map(JmxOperationParameter::getName).toArray(String[]::new);
|
.map(JmxOperationParameter::getName).toArray(String[]::new);
|
||||||
Map<String, Object> arguments = getArguments(parameterNames, params);
|
Map<String, Object> arguments = getArguments(parameterNames, params);
|
||||||
Object result = operation
|
Object result = operation
|
||||||
.invoke(new InvocationContext(new JmxSecurityContext(), arguments));
|
.invoke(new InvocationContext(SecurityContext.NONE, arguments));
|
||||||
if (REACTOR_PRESENT) {
|
if (REACTOR_PRESENT) {
|
||||||
result = ReactiveHandler.handle(result);
|
result = ReactiveHandler.handle(result);
|
||||||
}
|
}
|
||||||
|
@ -152,18 +151,4 @@ public class EndpointMBean implements DynamicMBean {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class JmxSecurityContext implements SecurityContext {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Principal getPrincipal() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUserInRole(String role) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,14 +271,16 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
|
||||||
|
|
||||||
private ReactiveWebOperationAdapter(OperationInvoker invoker) {
|
private ReactiveWebOperationAdapter(OperationInvoker invoker) {
|
||||||
this.invoker = invoker;
|
this.invoker = invoker;
|
||||||
|
this.securityContextSupplier = getSecurityContextSupplier();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Supplier<Mono<? extends SecurityContext>> getSecurityContextSupplier() {
|
||||||
if (ClassUtils.isPresent(
|
if (ClassUtils.isPresent(
|
||||||
"org.springframework.security.core.context.ReactiveSecurityContextHolder",
|
"org.springframework.security.core.context.ReactiveSecurityContextHolder",
|
||||||
getClass().getClassLoader())) {
|
getClass().getClassLoader())) {
|
||||||
this.securityContextSupplier = this::springSecurityContext;
|
return this::springSecurityContext;
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.securityContextSupplier = this::emptySecurityContext;
|
|
||||||
}
|
}
|
||||||
|
return this::emptySecurityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<? extends SecurityContext> springSecurityContext() {
|
public Mono<? extends SecurityContext> springSecurityContext() {
|
||||||
|
@ -289,19 +291,7 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<SecurityContext> emptySecurityContext() {
|
public Mono<SecurityContext> emptySecurityContext() {
|
||||||
return Mono.just(new SecurityContext() {
|
return Mono.just(SecurityContext.NONE);
|
||||||
|
|
||||||
@Override
|
|
||||||
public Principal getPrincipal() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUserInRole(String role) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -84,8 +84,8 @@ public class DataSourcePoolMetrics implements MeterBinder {
|
||||||
private <N extends Number> void bindDataSource(MeterRegistry registry,
|
private <N extends Number> void bindDataSource(MeterRegistry registry,
|
||||||
String metricName, Function<DataSource, N> function) {
|
String metricName, Function<DataSource, N> function) {
|
||||||
if (function.apply(this.dataSource) != null) {
|
if (function.apply(this.dataSource) != null) {
|
||||||
registry.gauge("jdbc.connections." + metricName, this.tags,
|
registry.gauge("jdbc.connections." + metricName, this.tags, this.dataSource,
|
||||||
this.dataSource, (m) -> function.apply(m).doubleValue());
|
(m) -> function.apply(m).doubleValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
|
|
@ -79,10 +79,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Matchers.anyString;
|
|
||||||
import static org.mockito.Matchers.eq;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@ -989,6 +989,7 @@ public class ConfigurationPropertiesTests {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
Loading…
Reference in New Issue