Divide httpTags and routeTags provider
This commit is contained in:
@@ -29,7 +29,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
|
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayMetricsFilter;
|
import org.springframework.cloud.gateway.filter.GatewayMetricsFilter;
|
||||||
import org.springframework.cloud.gateway.support.tagsprovider.DefaultGatewayTagsProvider;
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayHttpTagsProvider;
|
||||||
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayRouteTagsProvider;
|
||||||
import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider;
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -45,8 +46,13 @@ import org.springframework.web.reactive.DispatcherHandler;
|
|||||||
public class GatewayMetricsAutoConfiguration {
|
public class GatewayMetricsAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GatewayTagsProvider defaultGatewayTagsProvider() {
|
public GatewayTagsProvider gatewayHttpTagsProvider() {
|
||||||
return new DefaultGatewayTagsProvider();
|
return new GatewayHttpTagsProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GatewayTagsProvider gatewayRouteTagsProvider() {
|
||||||
|
return new GatewayRouteTagsProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.gateway.filter;
|
package org.springframework.cloud.gateway.filter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
@@ -27,10 +27,9 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayHttpTagsProvider;
|
||||||
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayRouteTagsProvider;
|
||||||
import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider;
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
@@ -39,8 +38,7 @@ import org.springframework.web.server.ServerWebExchange;
|
|||||||
* @author Tony Clarke
|
* @author Tony Clarke
|
||||||
* @author Ingyu Hwang
|
* @author Ingyu Hwang
|
||||||
*/
|
*/
|
||||||
public class GatewayMetricsFilter
|
public class GatewayMetricsFilter implements GlobalFilter, Ordered {
|
||||||
implements GlobalFilter, Ordered, ApplicationContextAware {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(GatewayMetricsFilter.class);
|
private static final Log log = LogFactory.getLog(GatewayMetricsFilter.class);
|
||||||
|
|
||||||
@@ -48,19 +46,16 @@ public class GatewayMetricsFilter
|
|||||||
|
|
||||||
private GatewayTagsProvider compositeTagsProvider;
|
private GatewayTagsProvider compositeTagsProvider;
|
||||||
|
|
||||||
private AtomicBoolean initialized = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
public GatewayMetricsFilter(MeterRegistry meterRegistry,
|
public GatewayMetricsFilter(MeterRegistry meterRegistry,
|
||||||
List<GatewayTagsProvider> tagsProviders) {
|
List<GatewayTagsProvider> tagsProviders) {
|
||||||
this.meterRegistry = meterRegistry;
|
this.meterRegistry = meterRegistry;
|
||||||
this.compositeTagsProvider = tagsProviders.stream()
|
this.compositeTagsProvider = tagsProviders.stream()
|
||||||
.reduce(exchange -> Tags.empty(), GatewayTagsProvider::and);
|
.reduce(exchange -> Tags.empty(), GatewayTagsProvider::and);
|
||||||
initialized.compareAndSet(false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public GatewayMetricsFilter(MeterRegistry meterRegistry) {
|
public GatewayMetricsFilter(MeterRegistry meterRegistry) {
|
||||||
this.meterRegistry = meterRegistry;
|
this(meterRegistry, Arrays.asList(new GatewayHttpTagsProvider(), new GatewayRouteTagsProvider()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,14 +65,6 @@ public class GatewayMetricsFilter
|
|||||||
return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER + 1;
|
return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
|
||||||
if (initialized.compareAndSet(false, true)) {
|
|
||||||
this.compositeTagsProvider = context.getBean("defaultGatewayTagsProvider",
|
|
||||||
GatewayTagsProvider.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
Sample sample = Timer.start(meterRegistry);
|
Sample sample = Timer.start(meterRegistry);
|
||||||
|
|||||||
@@ -18,23 +18,17 @@ package org.springframework.cloud.gateway.support.tagsprovider;
|
|||||||
|
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
|
|
||||||
import org.springframework.cloud.gateway.route.Route;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
|
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ingyu Hwang
|
* @author Ingyu Hwang
|
||||||
*/
|
*/
|
||||||
public final class GatewayTags {
|
public class GatewayHttpTagsProvider implements GatewayTagsProvider {
|
||||||
|
|
||||||
private GatewayTags() {
|
@Override
|
||||||
throw new AssertionError("Must not instantiate utility class.");
|
public Tags apply(ServerWebExchange exchange) {
|
||||||
}
|
|
||||||
|
|
||||||
public static Tags http(ServerWebExchange exchange) {
|
|
||||||
String outcome = "CUSTOM";
|
String outcome = "CUSTOM";
|
||||||
String status = "CUSTOM";
|
String status = "CUSTOM";
|
||||||
String httpStatusCodeStr = "NA";
|
String httpStatusCodeStr = "NA";
|
||||||
@@ -71,15 +65,4 @@ public final class GatewayTags {
|
|||||||
"httpStatusCode", httpStatusCodeStr, "httpMethod", httpMethod);
|
"httpStatusCode", httpStatusCodeStr, "httpMethod", httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tags route(ServerWebExchange exchange) {
|
|
||||||
Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
|
|
||||||
|
|
||||||
if (route != null) {
|
|
||||||
return Tags.of("routeId", route.getId(),
|
|
||||||
"routeUri", route.getUri().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Tags.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,16 +18,26 @@ package org.springframework.cloud.gateway.support.tagsprovider;
|
|||||||
|
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
|
|
||||||
|
import org.springframework.cloud.gateway.route.Route;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ingyu Hwang
|
* @author Ingyu Hwang
|
||||||
*/
|
*/
|
||||||
public class DefaultGatewayTagsProvider implements GatewayTagsProvider {
|
public class GatewayRouteTagsProvider implements GatewayTagsProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tags apply(ServerWebExchange exchange) {
|
public Tags apply(ServerWebExchange exchange) {
|
||||||
return Tags.concat(GatewayTags.http(exchange), GatewayTags.route(exchange));
|
Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
|
||||||
|
|
||||||
|
if (route != null) {
|
||||||
|
return Tags.of("routeId", route.getId(), "routeUri",
|
||||||
|
route.getUri().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Tags.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,10 +28,10 @@ import org.springframework.boot.SpringBootConfiguration;
|
|||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayMetricsFilter;
|
import org.springframework.cloud.gateway.filter.GatewayMetricsFilter;
|
||||||
import org.springframework.cloud.gateway.support.tagsprovider.DefaultGatewayTagsProvider;
|
|
||||||
import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider;
|
import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@@ -54,8 +54,7 @@ public class GatewayMetricsAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void gatewayMetricsBeansExists() {
|
public void gatewayMetricsBeansExists() {
|
||||||
assertThat(filter).isNotNull();
|
assertThat(filter).isNotNull();
|
||||||
assertThat(tagsProviders).extracting("class")
|
assertThat(tagsProviders).isNotEmpty();
|
||||||
.containsOnlyOnce(DefaultGatewayTagsProvider.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -88,7 +87,7 @@ public class GatewayMetricsAutoConfigurationTests {
|
|||||||
public void gatewayMetricsBeansExists() {
|
public void gatewayMetricsBeansExists() {
|
||||||
assertThat(filter).isNotNull();
|
assertThat(filter).isNotNull();
|
||||||
assertThat(tagsProviders).extracting("class")
|
assertThat(tagsProviders).extracting("class")
|
||||||
.hasSize(2);
|
.contains(CustomTagsProviderConfig.EmptyTagsProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,7 +104,16 @@ public class GatewayMetricsAutoConfigurationTests {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public GatewayTagsProvider emptyTagsProvider() {
|
public GatewayTagsProvider emptyTagsProvider() {
|
||||||
return (exchange) -> Tags.empty();
|
return new EmptyTagsProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class EmptyTagsProvider implements GatewayTagsProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tags apply(ServerWebExchange exchange) {
|
||||||
|
return Tags.empty();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,8 @@
|
|||||||
package org.springframework.cloud.gateway.support.tagsprovider;
|
package org.springframework.cloud.gateway.support.tagsprovider;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.cloud.gateway.route.Route;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
|
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
|
||||||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
|
||||||
@@ -31,43 +28,28 @@ import org.springframework.web.server.ServerWebExchange;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ingyu Hwang
|
* @author Ingyu Hwang
|
||||||
*/
|
*/
|
||||||
public class DefaultGatewayTagsProviderTests {
|
public class GatewayHttpTagsProviderTests {
|
||||||
|
|
||||||
private Route route;
|
private final GatewayHttpTagsProvider tagsProvider = new GatewayHttpTagsProvider();
|
||||||
|
|
||||||
private DefaultGatewayTagsProvider defaultTagsProvider;
|
|
||||||
|
|
||||||
private Tags defaultTags;
|
|
||||||
|
|
||||||
private static final String ROUTE_URI = "http://gatewaytagsprovider.org:80";
|
private static final String ROUTE_URI = "http://gatewaytagsprovider.org:80";
|
||||||
|
|
||||||
@Before
|
private static final Tags DEFAULT_TAGS = Tags.of("outcome", OK.series().name(),
|
||||||
public void setup() {
|
"status", OK.name(), "httpStatusCode", String.valueOf(OK.value()), "httpMethod", "GET");
|
||||||
String routeId = "test-route";
|
|
||||||
HttpStatus ok = HttpStatus.OK;
|
|
||||||
|
|
||||||
route = Route.async().id(routeId).uri(ROUTE_URI).predicate(swe -> true).build();
|
|
||||||
|
|
||||||
defaultTagsProvider = new DefaultGatewayTagsProvider();
|
|
||||||
defaultTags = Tags.of("outcome", ok.series().name(), "status", ok.name(),
|
|
||||||
"httpStatusCode", String.valueOf(ok.value()), "httpMethod", "GET",
|
|
||||||
"routeId", routeId, "routeUri", ROUTE_URI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultProvider() {
|
public void httpTags() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange
|
ServerWebExchange exchange = MockServerWebExchange
|
||||||
.from(MockServerHttpRequest.get(ROUTE_URI).build());
|
.from(MockServerHttpRequest.get(ROUTE_URI).build());
|
||||||
exchange.getAttributes().put(GATEWAY_ROUTE_ATTR, route);
|
exchange.getResponse().setStatusCode(OK);
|
||||||
exchange.getResponse().setStatusCode(HttpStatus.OK);
|
|
||||||
|
|
||||||
Tags tags = defaultTagsProvider.apply(exchange);
|
Tags tags = tagsProvider.apply(exchange);
|
||||||
assertThat(tags).isEqualTo(defaultTags);
|
assertThat(tags).isEqualTo(DEFAULT_TAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -75,7 +57,7 @@ public class DefaultGatewayTagsProviderTests {
|
|||||||
ServerWebExchange exchange = MockServerWebExchange
|
ServerWebExchange exchange = MockServerWebExchange
|
||||||
.from(MockServerHttpRequest.get(ROUTE_URI).build());
|
.from(MockServerHttpRequest.get(ROUTE_URI).build());
|
||||||
|
|
||||||
Tags tags = defaultTagsProvider.apply(exchange);
|
Tags tags = tagsProvider.apply(exchange);
|
||||||
assertThat(tags).isEqualTo(Tags.of("outcome", "CUSTOM", "status", "CUSTOM",
|
assertThat(tags).isEqualTo(Tags.of("outcome", "CUSTOM", "status", "CUSTOM",
|
||||||
"httpStatusCode", "NA", "httpMethod", "GET"));
|
"httpStatusCode", "NA", "httpMethod", "GET"));
|
||||||
}
|
}
|
||||||
@@ -85,15 +67,14 @@ public class DefaultGatewayTagsProviderTests {
|
|||||||
ServerWebExchange mockExchange = mock(ServerWebExchange.class);
|
ServerWebExchange mockExchange = mock(ServerWebExchange.class);
|
||||||
ServerHttpResponseDecorator responseDecorator = new ServerHttpResponseDecorator(
|
ServerHttpResponseDecorator responseDecorator = new ServerHttpResponseDecorator(
|
||||||
new MockServerHttpResponse());
|
new MockServerHttpResponse());
|
||||||
responseDecorator.setStatusCode(HttpStatus.OK);
|
responseDecorator.setStatusCode(OK);
|
||||||
|
|
||||||
when(mockExchange.getRequest())
|
when(mockExchange.getRequest())
|
||||||
.thenReturn(MockServerHttpRequest.get(ROUTE_URI).build());
|
.thenReturn(MockServerHttpRequest.get(ROUTE_URI).build());
|
||||||
when(mockExchange.getResponse()).thenReturn(responseDecorator);
|
when(mockExchange.getResponse()).thenReturn(responseDecorator);
|
||||||
when(mockExchange.getAttribute(GATEWAY_ROUTE_ATTR)).thenReturn(route);
|
|
||||||
|
|
||||||
Tags tags = defaultTagsProvider.apply(mockExchange);
|
Tags tags = tagsProvider.apply(mockExchange);
|
||||||
assertThat(tags).isEqualTo(defaultTags);
|
assertThat(tags).isEqualTo(DEFAULT_TAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.cloud.gateway.support.tagsprovider;
|
||||||
|
|
||||||
|
import io.micrometer.core.instrument.Tags;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.cloud.gateway.route.Route;
|
||||||
|
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.server.MockServerWebExchange;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ingyu Hwang
|
||||||
|
*/
|
||||||
|
public class GatewayRouteTagsProviderTests {
|
||||||
|
|
||||||
|
private final GatewayRouteTagsProvider tagsProvider = new GatewayRouteTagsProvider();
|
||||||
|
|
||||||
|
private static final String ROUTE_URI = "http://gatewaytagsprovider.org:80";
|
||||||
|
|
||||||
|
private static final String ROUTE_ID = "test-route";
|
||||||
|
|
||||||
|
private static final Route ROUTE = Route.async().id(ROUTE_ID).uri(ROUTE_URI)
|
||||||
|
.predicate(swe -> true).build();
|
||||||
|
|
||||||
|
private static final Tags DEFAULT_TAGS = Tags.of("routeId", ROUTE_ID, "routeUri",
|
||||||
|
ROUTE_URI);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void routeTags() {
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange
|
||||||
|
.from(MockServerHttpRequest.get(ROUTE_URI).build());
|
||||||
|
exchange.getAttributes().put(GATEWAY_ROUTE_ATTR, ROUTE);
|
||||||
|
|
||||||
|
Tags tags = tagsProvider.apply(exchange);
|
||||||
|
assertThat(tags).isEqualTo(DEFAULT_TAGS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void emptyRoute() {
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange
|
||||||
|
.from(MockServerHttpRequest.get(ROUTE_URI).build());
|
||||||
|
|
||||||
|
Tags tags = tagsProvider.apply(exchange);
|
||||||
|
assertThat(tags).isEqualTo(Tags.empty());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user