Start building against Spring Framework 6.0.0 SNAPSHOTs

See gh-33136
This commit is contained in:
Brian Clozel 2022-11-14 16:33:29 +01:00
parent 4bd2fe151e
commit 932f7d705f
15 changed files with 46 additions and 32 deletions

View File

@ -24,8 +24,14 @@ import io.micrometer.core.instrument.Tag;
import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider; import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider;
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsContributor; import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsContributor;
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsProvider; import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsProvider;
import org.springframework.http.observation.reactive.ServerRequestObservationContext; import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.observation.reactive.ServerRequestObservationConvention; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;
import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
import org.springframework.web.server.i18n.LocaleContextResolver;
import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
/** /**
* Adapter class that applies {@link WebFluxTagsProvider} tags as a * Adapter class that applies {@link WebFluxTagsProvider} tags as a
@ -37,6 +43,12 @@ import org.springframework.http.observation.reactive.ServerRequestObservationCon
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
class ServerRequestObservationConventionAdapter implements ServerRequestObservationConvention { class ServerRequestObservationConventionAdapter implements ServerRequestObservationConvention {
private final WebSessionManager webSessionManager = new DefaultWebSessionManager();
private final ServerCodecConfigurer serverCodecConfigurer = ServerCodecConfigurer.create();
private final LocaleContextResolver localeContextResolver = new AcceptHeaderLocaleContextResolver();
private final String name; private final String name;
private final WebFluxTagsProvider tagsProvider; private final WebFluxTagsProvider tagsProvider;
@ -58,7 +70,10 @@ class ServerRequestObservationConventionAdapter implements ServerRequestObservat
@Override @Override
public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) { public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) {
Iterable<Tag> tags = this.tagsProvider.httpRequestTags(context.getServerWebExchange(), context.getError()); DefaultServerWebExchange serverWebExchange = new DefaultServerWebExchange(context.getCarrier(),
context.getResponse(), this.webSessionManager, this.serverCodecConfigurer, this.localeContextResolver);
serverWebExchange.getAttributes().putAll(context.getAttributes());
Iterable<Tag> tags = this.tagsProvider.httpRequestTags(serverWebExchange, context.getError());
return KeyValues.of(tags, Tag::getKey, Tag::getValue); return KeyValues.of(tags, Tag::getKey, Tag::getValue);
} }

View File

@ -43,8 +43,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.observation.reactive.DefaultServerRequestObservationConvention; import org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention;
import org.springframework.http.observation.reactive.ServerRequestObservationConvention; import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention;
import org.springframework.web.filter.reactive.ServerHttpObservationFilter; import org.springframework.web.filter.reactive.ServerHttpObservationFilter;
/** /**
@ -85,11 +85,11 @@ public class WebFluxObservationAutoConfiguration {
String name = (observationName != null) ? observationName : metricName; String name = (observationName != null) ? observationName : metricName;
WebFluxTagsProvider tagsProvider = tagConfigurer.getIfAvailable(); WebFluxTagsProvider tagsProvider = tagConfigurer.getIfAvailable();
List<WebFluxTagsContributor> tagsContributors = contributorsProvider.orderedStream().toList(); List<WebFluxTagsContributor> tagsContributors = contributorsProvider.orderedStream().toList();
ServerRequestObservationConvention convention = extracted(name, tagsProvider, tagsContributors); ServerRequestObservationConvention convention = createConvention(name, tagsProvider, tagsContributors);
return new ServerHttpObservationFilter(registry, convention); return new ServerHttpObservationFilter(registry, convention);
} }
private ServerRequestObservationConvention extracted(String name, WebFluxTagsProvider tagsProvider, private ServerRequestObservationConvention createConvention(String name, WebFluxTagsProvider tagsProvider,
List<WebFluxTagsContributor> tagsContributors) { List<WebFluxTagsContributor> tagsContributors) {
if (tagsProvider != null) { if (tagsProvider != null) {
return new ServerRequestObservationConventionAdapter(name, tagsProvider); return new ServerRequestObservationConventionAdapter(name, tagsProvider);

View File

@ -25,8 +25,8 @@ import io.micrometer.observation.Observation;
import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider; import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsContributor; import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsContributor;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsProvider; import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsProvider;
import org.springframework.http.observation.ServerRequestObservationContext; import org.springframework.http.server.observation.ServerRequestObservationContext;
import org.springframework.http.observation.ServerRequestObservationConvention; import org.springframework.http.server.observation.ServerRequestObservationConvention;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;

View File

@ -46,8 +46,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.observation.DefaultServerRequestObservationConvention; import org.springframework.http.server.observation.DefaultServerRequestObservationConvention;
import org.springframework.http.observation.ServerRequestObservationConvention; import org.springframework.http.server.observation.ServerRequestObservationConvention;
import org.springframework.web.filter.ServerHttpObservationFilter; import org.springframework.web.filter.ServerHttpObservationFilter;
import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;

View File

@ -16,13 +16,15 @@
package org.springframework.boot.actuate.autoconfigure.observation.web.reactive; package org.springframework.boot.actuate.autoconfigure.observation.web.reactive;
import java.util.Map;
import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider; import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider;
import org.springframework.http.observation.reactive.ServerRequestObservationContext; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange; import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.util.pattern.PathPatternParser; import org.springframework.web.util.pattern.PathPatternParser;
@ -39,12 +41,6 @@ class ServerRequestObservationConventionAdapterTests {
private static final String TEST_METRIC_NAME = "test.metric.name"; private static final String TEST_METRIC_NAME = "test.metric.name";
private final MockServerHttpRequest request = MockServerHttpRequest.get("/resource/test").build();
private final MockServerWebExchange serverWebExchange = MockServerWebExchange.builder(this.request).build();
private final ServerRequestObservationContext context = new ServerRequestObservationContext(this.serverWebExchange);
private final ServerRequestObservationConventionAdapter convention = new ServerRequestObservationConventionAdapter( private final ServerRequestObservationConventionAdapter convention = new ServerRequestObservationConventionAdapter(
TEST_METRIC_NAME, new DefaultWebFluxTagsProvider()); TEST_METRIC_NAME, new DefaultWebFluxTagsProvider());
@ -55,9 +51,12 @@ class ServerRequestObservationConventionAdapterTests {
@Test @Test
void shouldPushTagsAsLowCardinalityKeyValues() { void shouldPushTagsAsLowCardinalityKeyValues() {
this.serverWebExchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, MockServerHttpRequest request = MockServerHttpRequest.get("/resource/test").build();
PathPatternParser.defaultInstance.parse("/resource/{name}")); MockServerHttpResponse response = new MockServerHttpResponse();
assertThat(this.convention.getLowCardinalityKeyValues(this.context)).contains(KeyValue.of("status", "200"), ServerRequestObservationContext context = new ServerRequestObservationContext(request, response,
Map.of(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
PathPatternParser.defaultInstance.parse("/resource/{name}")));
assertThat(this.convention.getLowCardinalityKeyValues(context)).contains(KeyValue.of("status", "200"),
KeyValue.of("outcome", "SUCCESS"), KeyValue.of("uri", "/resource/{name}"), KeyValue.of("outcome", "SUCCESS"), KeyValue.of("uri", "/resource/{name}"),
KeyValue.of("method", "GET")); KeyValue.of("method", "GET"));
} }

View File

@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider; import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsContributor; import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsContributor;
import org.springframework.http.observation.ServerRequestObservationContext; import org.springframework.http.server.observation.ServerRequestObservationContext;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;

View File

@ -31,7 +31,7 @@ import org.springframework.web.server.ServerWebExchange;
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0 * @since 2.0.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention}
*/ */
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
@SuppressWarnings("removal") @SuppressWarnings("removal")

View File

@ -41,7 +41,7 @@ import org.springframework.web.util.pattern.PathPattern;
* @author Brian Clozel * @author Brian Clozel
* @since 2.0.0 * @since 2.0.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention}
*/ */
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
public final class WebFluxTags { public final class WebFluxTags {

View File

@ -27,7 +27,7 @@ import org.springframework.web.server.ServerWebExchange;
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.3.0 * @since 2.3.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention}
*/ */
@FunctionalInterface @FunctionalInterface
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)

View File

@ -27,7 +27,7 @@ import org.springframework.web.server.ServerWebExchange;
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0 * @since 2.0.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention}
*/ */
@FunctionalInterface @FunctionalInterface
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)

View File

@ -30,7 +30,7 @@ import jakarta.servlet.http.HttpServletResponse;
* @author Jon Schneider * @author Jon Schneider
* @since 2.0.0 * @since 2.0.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.ServerRequestObservationConvention} * {@link org.springframework.http.server.observation.ServerRequestObservationConvention}
*/ */
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
@SuppressWarnings("removal") @SuppressWarnings("removal")

View File

@ -38,7 +38,7 @@ import org.springframework.web.util.pattern.PathPattern;
* @author Michael McFadyen * @author Michael McFadyen
* @since 2.0.0 * @since 2.0.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.ServerRequestObservationConvention} * {@link org.springframework.http.server.observation.ServerRequestObservationConvention}
*/ */
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
public final class WebMvcTags { public final class WebMvcTags {

View File

@ -28,7 +28,7 @@ import jakarta.servlet.http.HttpServletResponse;
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.3.0 * @since 2.3.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.ServerRequestObservationConvention} * {@link org.springframework.http.server.observation.ServerRequestObservationConvention}
*/ */
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
public interface WebMvcTagsContributor { public interface WebMvcTagsContributor {

View File

@ -28,7 +28,7 @@ import jakarta.servlet.http.HttpServletResponse;
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0 * @since 2.0.0
* @deprecated since 3.0.0 for removal in 3.2.0 in favor of * @deprecated since 3.0.0 for removal in 3.2.0 in favor of
* {@link org.springframework.http.observation.ServerRequestObservationConvention} * {@link org.springframework.http.server.observation.ServerRequestObservationConvention}
*/ */
@Deprecated(since = "3.0.0", forRemoval = true) @Deprecated(since = "3.0.0", forRemoval = true)
public interface WebMvcTagsProvider { public interface WebMvcTagsProvider {

View File

@ -1357,7 +1357,7 @@ bom {
] ]
} }
} }
library("Spring Framework", "6.0.0-RC4") { library("Spring Framework", "6.0.0-SNAPSHOT") {
group("org.springframework") { group("org.springframework") {
imports = [ imports = [
"spring-framework-bom" "spring-framework-bom"