Skip to content

Commit

Permalink
Start building against Spring Framework 6.0.0 SNAPSHOTs
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Nov 14, 2022
1 parent 4bd2fe1 commit 932f7d7
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 32 deletions.
Expand Up @@ -24,8 +24,14 @@
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.WebFluxTagsProvider;
import org.springframework.http.observation.reactive.ServerRequestObservationContext;
import org.springframework.http.observation.reactive.ServerRequestObservationConvention;
import org.springframework.http.codec.ServerCodecConfigurer;
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
Expand All @@ -37,6 +43,12 @@
@Deprecated(since = "3.0.0", forRemoval = true)
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 WebFluxTagsProvider tagsProvider;
Expand All @@ -58,7 +70,10 @@ public String getName() {

@Override
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);
}

Expand Down
Expand Up @@ -43,8 +43,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.observation.reactive.DefaultServerRequestObservationConvention;
import org.springframework.http.observation.reactive.ServerRequestObservationConvention;
import org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention;
import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention;
import org.springframework.web.filter.reactive.ServerHttpObservationFilter;

/**
Expand Down Expand Up @@ -85,11 +85,11 @@ public ServerHttpObservationFilter webfluxObservationFilter(ObservationRegistry
String name = (observationName != null) ? observationName : metricName;
WebFluxTagsProvider tagsProvider = tagConfigurer.getIfAvailable();
List<WebFluxTagsContributor> tagsContributors = contributorsProvider.orderedStream().toList();
ServerRequestObservationConvention convention = extracted(name, tagsProvider, tagsContributors);
ServerRequestObservationConvention convention = createConvention(name, tagsProvider, tagsContributors);
return new ServerHttpObservationFilter(registry, convention);
}

private ServerRequestObservationConvention extracted(String name, WebFluxTagsProvider tagsProvider,
private ServerRequestObservationConvention createConvention(String name, WebFluxTagsProvider tagsProvider,
List<WebFluxTagsContributor> tagsContributors) {
if (tagsProvider != null) {
return new ServerRequestObservationConventionAdapter(name, tagsProvider);
Expand Down
Expand Up @@ -25,8 +25,8 @@
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.WebMvcTagsProvider;
import org.springframework.http.observation.ServerRequestObservationContext;
import org.springframework.http.observation.ServerRequestObservationConvention;
import org.springframework.http.server.observation.ServerRequestObservationContext;
import org.springframework.http.server.observation.ServerRequestObservationConvention;
import org.springframework.util.Assert;
import org.springframework.web.servlet.HandlerMapping;

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

Expand Down
Expand Up @@ -16,13 +16,15 @@

package org.springframework.boot.actuate.autoconfigure.observation.web.reactive;

import java.util.Map;

import io.micrometer.common.KeyValue;
import org.junit.jupiter.api.Test;

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.web.server.MockServerWebExchange;
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.util.pattern.PathPatternParser;

Expand All @@ -39,12 +41,6 @@ class ServerRequestObservationConventionAdapterTests {

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(
TEST_METRIC_NAME, new DefaultWebFluxTagsProvider());

Expand All @@ -55,9 +51,12 @@ void shouldUseConfiguredName() {

@Test
void shouldPushTagsAsLowCardinalityKeyValues() {
this.serverWebExchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
PathPatternParser.defaultInstance.parse("/resource/{name}"));
assertThat(this.convention.getLowCardinalityKeyValues(this.context)).contains(KeyValue.of("status", "200"),
MockServerHttpRequest request = MockServerHttpRequest.get("/resource/test").build();
MockServerHttpResponse response = new MockServerHttpResponse();
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("method", "GET"));
}
Expand Down
Expand Up @@ -28,7 +28,7 @@

import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider;
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.MockHttpServletResponse;
import org.springframework.web.servlet.HandlerMapping;
Expand Down
Expand Up @@ -31,7 +31,7 @@
* @author Andy Wilkinson
* @since 2.0.0
* @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)
@SuppressWarnings("removal")
Expand Down
Expand Up @@ -41,7 +41,7 @@
* @author Brian Clozel
* @since 2.0.0
* @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)
public final class WebFluxTags {
Expand Down
Expand Up @@ -27,7 +27,7 @@
* @author Andy Wilkinson
* @since 2.3.0
* @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
@Deprecated(since = "3.0.0", forRemoval = true)
Expand Down
Expand Up @@ -27,7 +27,7 @@
* @author Andy Wilkinson
* @since 2.0.0
* @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
@Deprecated(since = "3.0.0", forRemoval = true)
Expand Down
Expand Up @@ -30,7 +30,7 @@
* @author Jon Schneider
* @since 2.0.0
* @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)
@SuppressWarnings("removal")
Expand Down
Expand Up @@ -38,7 +38,7 @@
* @author Michael McFadyen
* @since 2.0.0
* @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)
public final class WebMvcTags {
Expand Down
Expand Up @@ -28,7 +28,7 @@
* @author Andy Wilkinson
* @since 2.3.0
* @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)
public interface WebMvcTagsContributor {
Expand Down
Expand Up @@ -28,7 +28,7 @@
* @author Andy Wilkinson
* @since 2.0.0
* @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)
public interface WebMvcTagsProvider {
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-dependencies/build.gradle
Expand Up @@ -1357,7 +1357,7 @@ bom {
]
}
}
library("Spring Framework", "6.0.0-RC4") {
library("Spring Framework", "6.0.0-SNAPSHOT") {
group("org.springframework") {
imports = [
"spring-framework-bom"
Expand Down

0 comments on commit 932f7d7

Please sign in to comment.