Move Jetty metrics auto-configuration into spring-boot-jetty

This commit is contained in:
Stéphane Nicoll
2025-05-21 10:55:20 +02:00
committed by Phillip Webb
parent 7129385ddb
commit 999002119c
13 changed files with 42 additions and 41 deletions

View File

@@ -38,7 +38,6 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver.Stackd
org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration
org.springframework.boot.actuate.autoconfigure.metrics.jersey.JerseyServerMetricsAutoConfiguration
org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration
org.springframework.boot.actuate.autoconfigure.metrics.web.jetty.JettyMetricsAutoConfiguration
org.springframework.boot.actuate.autoconfigure.metrics.web.tomcat.TomcatMetricsAutoConfiguration
org.springframework.boot.actuate.autoconfigure.observation.batch.BatchObservationAutoConfiguration
org.springframework.boot.actuate.autoconfigure.observation.graphql.GraphQlObservationAutoConfiguration

View File

@@ -12,7 +12,6 @@ dependencies {
api(project(":spring-boot-project:spring-boot"))
optional(project(":spring-boot-project:spring-boot-http-converter"))
optional(project(":spring-boot-project:spring-boot-jetty"))
optional(project(":spring-boot-project:spring-boot-jsonb"))
optional(project(":spring-boot-project:spring-boot-reactor-netty"))
optional(project(":spring-boot-project:spring-boot-tomcat"))
@@ -38,9 +37,6 @@ dependencies {
optional("org.apache.tomcat.embed:tomcat-embed-core")
optional("org.aspectj:aspectjweaver")
optional("org.eclipse.angus:angus-mail")
optional("org.eclipse.jetty:jetty-server") {
exclude(group: "org.eclipse.jetty.toolchain", module: "jetty-jakarta-servlet-api")
}
optional("org.glassfish.jersey.core:jersey-server")
optional("org.glassfish.jersey.containers:jersey-container-servlet-core")
optional("org.hibernate.validator:hibernate-validator")

View File

@@ -14,6 +14,7 @@ dependencies {
api("org.eclipse.jetty.ee10:jetty-ee10-webapp")
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
optional(project(":spring-boot-project:spring-boot-metrics"))
optional("org.apache.tomcat.embed:tomcat-embed-jasper")
optional("org.eclipse.jetty:jetty-alpn-conscrypt-server")
optional("org.eclipse.jetty.ee10.websocket:jetty-ee10-websocket-jakarta-server")

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics;
import org.eclipse.jetty.server.Server;
@@ -29,7 +29,7 @@ import org.springframework.context.ApplicationListener;
* Base class for binding Jetty metrics in response to an {@link ApplicationStartedEvent}.
*
* @author Andy Wilkinson
* @since 2.6.0
* @since 4.0.0
*/
public abstract class AbstractJettyMetricsBinder implements ApplicationListener<ApplicationStartedEvent> {

View File

@@ -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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics;
import java.util.Collections;
@@ -27,7 +27,7 @@ import org.eclipse.jetty.server.Server;
* {@link AbstractJettyMetricsBinder} for {@link JettyConnectionMetrics}.
*
* @author Chris Bono
* @since 2.6.0
* @since 4.0.0
*/
public class JettyConnectionMetricsBinder extends AbstractJettyMetricsBinder {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics;
import java.util.Collections;
@@ -28,7 +28,7 @@ import org.eclipse.jetty.util.thread.ThreadPool;
* {@link AbstractJettyMetricsBinder} for {@link JettyServerThreadPoolMetrics}.
*
* @author Andy Wilkinson
* @since 2.1.0
* @since 4.0.0
*/
public class JettyServerThreadPoolMetricsBinder extends AbstractJettyMetricsBinder {

View File

@@ -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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics;
import java.util.Collections;
@@ -27,7 +27,7 @@ import org.eclipse.jetty.server.Server;
* {@link AbstractJettyMetricsBinder} for {@link JettySslHandshakeMetrics}.
*
* @author Chris Bono
* @since 2.6.0
* @since 4.0.0
*/
public class JettySslHandshakeMetricsBinder extends AbstractJettyMetricsBinder {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics.autoconfigure;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.jetty.JettyConnectionMetrics;
@@ -22,9 +22,6 @@ import io.micrometer.core.instrument.binder.jetty.JettyServerThreadPoolMetrics;
import io.micrometer.core.instrument.binder.jetty.JettySslHandshakeMetrics;
import org.eclipse.jetty.server.Server;
import org.springframework.boot.actuate.metrics.web.jetty.JettyConnectionMetricsBinder;
import org.springframework.boot.actuate.metrics.web.jetty.JettyServerThreadPoolMetricsBinder;
import org.springframework.boot.actuate.metrics.web.jetty.JettySslHandshakeMetricsBinder;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -32,7 +29,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProp
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.jetty.actuate.metrics.JettyConnectionMetricsBinder;
import org.springframework.boot.jetty.actuate.metrics.JettyServerThreadPoolMetricsBinder;
import org.springframework.boot.jetty.actuate.metrics.JettySslHandshakeMetricsBinder;
import org.springframework.context.annotation.Bean;
/**
@@ -40,11 +39,11 @@ import org.springframework.context.annotation.Bean;
*
* @author Andy Wilkinson
* @author Chris Bono
* @since 2.1.0
* @since 4.0.0
*/
@AutoConfiguration(after = CompositeMeterRegistryAutoConfiguration.class)
@AutoConfiguration(afterName = "org.springframework.boot.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration")
@ConditionalOnWebApplication
@ConditionalOnClass({ JettyServerThreadPoolMetrics.class, Server.class })
@ConditionalOnClass({ JettyServerThreadPoolMetrics.class, Server.class, MeterRegistry.class })
@ConditionalOnBean(MeterRegistry.class)
public class JettyMetricsAutoConfiguration {

View File

@@ -17,4 +17,4 @@
/**
* Auto-configuration for Jetty actuator metrics.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics.autoconfigure;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 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.
@@ -17,4 +17,4 @@
/**
* Actuator support for Jetty metrics.
*/
package org.springframework.boot.actuate.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics;

View File

@@ -1,2 +1,3 @@
org.springframework.boot.jetty.actuate.metrics.autoconfigure.JettyMetricsAutoConfiguration
org.springframework.boot.jetty.autoconfigure.reactive.JettyReactiveWebServerAutoConfiguration
org.springframework.boot.jetty.autoconfigure.servlet.JettyServletWebServerAutoConfiguration

View File

@@ -14,19 +14,20 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.web.jetty;
package org.springframework.boot.jetty.actuate.metrics.autoconfigure;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.metrics.web.jetty.JettyConnectionMetricsBinder;
import org.springframework.boot.actuate.metrics.web.jetty.JettyServerThreadPoolMetricsBinder;
import org.springframework.boot.actuate.metrics.web.jetty.JettySslHandshakeMetricsBinder;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.boot.jetty.actuate.metrics.JettyConnectionMetricsBinder;
import org.springframework.boot.jetty.actuate.metrics.JettyServerThreadPoolMetricsBinder;
import org.springframework.boot.jetty.actuate.metrics.JettySslHandshakeMetricsBinder;
import org.springframework.boot.jetty.autoconfigure.reactive.JettyReactiveWebServerAutoConfiguration;
import org.springframework.boot.jetty.autoconfigure.servlet.JettyServletWebServerAutoConfiguration;
import org.springframework.boot.jetty.reactive.JettyReactiveWebServerFactory;
@@ -62,7 +63,7 @@ class JettyMetricsAutoConfigurationTests {
context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
assertThat(context).hasSingleBean(JettyServerThreadPoolMetricsBinder.class);
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.threads.config.min").meter()).isNotNull();
Assertions.assertThat(registry.find("jetty.threads.config.min").meter()).isNotNull();
});
}
@@ -75,7 +76,7 @@ class JettyMetricsAutoConfigurationTests {
.run((context) -> {
context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.threads.config.min").meter()).isNotNull();
Assertions.assertThat(registry.find("jetty.threads.config.min").meter()).isNotNull();
});
}
@@ -97,7 +98,7 @@ class JettyMetricsAutoConfigurationTests {
context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
assertThat(context).hasSingleBean(JettyConnectionMetricsBinder.class);
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.connections.messages.in").meter()).isNotNull();
Assertions.assertThat(registry.find("jetty.connections.messages.in").meter()).isNotNull();
});
}
@@ -110,7 +111,7 @@ class JettyMetricsAutoConfigurationTests {
.run((context) -> {
context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.connections.messages.in").meter()).isNotNull();
Assertions.assertThat(registry.find("jetty.connections.messages.in").meter()).isNotNull();
});
}
@@ -126,9 +127,11 @@ class JettyMetricsAutoConfigurationTests {
assertThat(context).hasSingleBean(JettyConnectionMetricsBinder.class)
.hasBean("customJettyConnectionMetricsBinder");
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.connections.messages.in")
.tag("custom-tag-name", "custom-tag-value")
.meter()).isNotNull();
Assertions
.assertThat(registry.find("jetty.connections.messages.in")
.tag("custom-tag-name", "custom-tag-value")
.meter())
.isNotNull();
});
}
@@ -145,7 +148,7 @@ class JettyMetricsAutoConfigurationTests {
context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
assertThat(context).hasSingleBean(JettySslHandshakeMetricsBinder.class);
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.ssl.handshakes").meter()).isNotNull();
Assertions.assertThat(registry.find("jetty.ssl.handshakes").meter()).isNotNull();
});
}
@@ -161,7 +164,7 @@ class JettyMetricsAutoConfigurationTests {
.run((context) -> {
context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.ssl.handshakes").meter()).isNotNull();
Assertions.assertThat(registry.find("jetty.ssl.handshakes").meter()).isNotNull();
});
}
@@ -180,7 +183,9 @@ class JettyMetricsAutoConfigurationTests {
assertThat(context).hasSingleBean(JettySslHandshakeMetricsBinder.class)
.hasBean("customJettySslHandshakeMetricsBinder");
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("jetty.ssl.handshakes").tag("custom-tag-name", "custom-tag-value").meter())
Assertions
.assertThat(
registry.find("jetty.ssl.handshakes").tag("custom-tag-name", "custom-tag-value").meter())
.isNotNull();
});