Move metrics and endpoint auto-config into spring-boot-integration
This commit is contained in:
committed by
Phillip Webb
parent
84d01cbad4
commit
bb3bd2a81e
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.integration.actuate.endpoint.autoconfigure;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
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.integration.actuate.endpoint.IntegrationGraphEndpoint;
|
||||
import org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.integration.config.IntegrationConfigurationBeanFactoryPostProcessor;
|
||||
import org.springframework.integration.graph.IntegrationGraphServer;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for the
|
||||
* {@link IntegrationGraphEndpoint}.
|
||||
*
|
||||
* @author Tim Ysewyn
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@AutoConfiguration(after = IntegrationAutoConfiguration.class)
|
||||
@ConditionalOnClass({ IntegrationGraphServer.class, IntegrationGraphEndpoint.class,
|
||||
ConditionalOnAvailableEndpoint.class })
|
||||
@ConditionalOnBean(IntegrationConfigurationBeanFactoryPostProcessor.class)
|
||||
@ConditionalOnAvailableEndpoint(IntegrationGraphEndpoint.class)
|
||||
public class IntegrationGraphEndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public IntegrationGraphEndpoint integrationGraphEndpoint(IntegrationGraphServer integrationGraphServer) {
|
||||
return new IntegrationGraphEndpoint(integrationGraphServer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public IntegrationGraphServer integrationGraphServer() {
|
||||
return new IntegrationGraphServer();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Spring Integration actuator endpoint.
|
||||
*/
|
||||
package org.springframework.boot.integration.actuate.endpoint.autoconfigure;
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.integration.actuate.metrics.autoconfigure;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Integration's metrics.
|
||||
* Orders auto-configuration classes to ensure that the {@link MeterRegistry} bean has
|
||||
* been defined before Spring Integration's Micrometer support queries the bean factory
|
||||
* for it.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@AutoConfiguration(before = IntegrationAutoConfiguration.class,
|
||||
afterName = "org.springframework.boot.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration")
|
||||
class IntegrationMetricsAutoConfiguration {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Spring Integration metrics.
|
||||
*/
|
||||
package org.springframework.boot.integration.actuate.metrics.autoconfigure;
|
||||
@@ -85,7 +85,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Madhura Bhave
|
||||
* @author Yong-Hyun Kim
|
||||
* @author Yanming Zhou
|
||||
* @since 1.1.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@AutoConfiguration(beforeName = "org.springframework.boot.rsocket.autoconfigure.RSocketMessagingAutoConfiguration",
|
||||
after = { JmxAutoConfiguration.class, TaskSchedulingAutoConfiguration.class },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2025 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.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Andy Wilkinson
|
||||
* @since 2.6.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class IntegrationDataSourceScriptDatabaseInitializer extends DataSourceScriptDatabaseInitializer {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
* @author Artem Bilan
|
||||
* @since 2.0.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@ConfigurationProperties("spring.integration")
|
||||
public class IntegrationProperties {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.integration.scheduling.PollerMetadata;
|
||||
* {@link PollerMetadata} whilst retaining default auto-configuration.
|
||||
*
|
||||
* @author Yanming Zhou
|
||||
* @since 3.5.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PollerMetadataCustomizer {
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
org.springframework.boot.integration.actuate.endpoint.autoconfigure.IntegrationGraphEndpointAutoConfiguration
|
||||
org.springframework.boot.integration.actuate.metrics.autoconfigure.IntegrationMetricsAutoConfiguration
|
||||
org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.integration;
|
||||
package org.springframework.boot.integration.actuate.endpoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -23,7 +23,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.integration.actuate.endpoint.IntegrationGraphEndpoint;
|
||||
import org.springframework.boot.integration.actuate.endpoint.IntegrationGraphEndpoint.GraphDescriptor;
|
||||
import org.springframework.integration.graph.Graph;
|
||||
import org.springframework.integration.graph.IntegrationGraphServer;
|
||||
@@ -14,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.integration;
|
||||
package org.springframework.boot.integration.actuate.endpoint;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.boot.integration.actuate.endpoint.IntegrationGraphEndpoint;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.integration.actuate.endpoint.autoconfigure;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||
import org.springframework.boot.integration.actuate.endpoint.IntegrationGraphEndpoint;
|
||||
import org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.integration.graph.IntegrationGraphServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link IntegrationGraphEndpointAutoConfiguration}.
|
||||
*
|
||||
* @author Tim Ysewyn
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class IntegrationGraphEndpointAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class, IntegrationAutoConfiguration.class,
|
||||
IntegrationGraphEndpointAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void runShouldHaveEndpointBean() {
|
||||
this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=integrationgraph")
|
||||
.run((context) -> assertThat(context).hasSingleBean(IntegrationGraphEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() {
|
||||
this.contextRunner.withPropertyValues("management.endpoint.integrationgraph.enabled:false").run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(IntegrationGraphEndpoint.class);
|
||||
assertThat(context).doesNotHaveBean(IntegrationGraphServer.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenNotExposedShouldNotHaveEndpointBean() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(IntegrationGraphEndpoint.class);
|
||||
assertThat(context).doesNotHaveBean(IntegrationGraphServer.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenSpringIntegrationIsNotEnabledShouldNotHaveEndpointBean() {
|
||||
ApplicationContextRunner noSpringIntegrationRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(IntegrationGraphEndpointAutoConfiguration.class));
|
||||
noSpringIntegrationRunner.run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(IntegrationGraphEndpoint.class);
|
||||
assertThat(context).doesNotHaveBean(IntegrationGraphServer.class);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.integration.actuate.metrics.autoconfigure;
|
||||
|
||||
import io.micrometer.core.instrument.Gauge;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.integration.actuate.endpoint.autoconfigure.IntegrationGraphEndpointAutoConfiguration;
|
||||
import org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration;
|
||||
import org.springframework.boot.metrics.autoconfigure.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link IntegrationMetricsAutoConfiguration}.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
class IntegrationMetricsAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(IntegrationAutoConfiguration.class,
|
||||
IntegrationGraphEndpointAutoConfiguration.class, IntegrationMetricsAutoConfiguration.class,
|
||||
MetricsAutoConfiguration.class))
|
||||
.withBean(SimpleMeterRegistry.class)
|
||||
.withPropertyValues("management.metrics.tags.someTag=someValue",
|
||||
"management.metrics.use-global-registry=false");
|
||||
|
||||
@Test
|
||||
void integrationMetersAreInstrumented() {
|
||||
this.contextRunner.run((context) -> {
|
||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||
Gauge gauge = registry.get("spring.integration.channels").tag("someTag", "someValue").gauge();
|
||||
assertThat(gauge).isNotNull().extracting(Gauge::value).isEqualTo(2.0);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user