Skip to content

Commit

Permalink
refactor: run spotless apply to fix violations
Browse files Browse the repository at this point in the history
  • Loading branch information
123liuziming committed Oct 6, 2023
1 parent bbd5d11 commit 239978f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

public final class GatewaySingletons {

private GatewaySingletons() {

}
private GatewaySingletons() {}

public static HttpServerRouteGetter<ServerWebExchange> httpRouteGetter() {
return (context, exchange) -> ServerWebExchangeHelper.extractServerRoute(exchange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class HandleAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(
@Advice.Argument(0) ServerWebExchange exchange) {
public static void methodEnter(@Advice.Argument(0) ServerWebExchange exchange) {
Context context = Context.current();
// Update route info for server span.
HttpServerRoute.update(
context, HttpServerRouteSource.NESTED_CONTROLLER, GatewaySingletons.httpRouteGetter(),
context,
HttpServerRouteSource.NESTED_CONTROLLER,
GatewaySingletons.httpRouteGetter(),
exchange);
// Record route info in current span, should be webflux's span.
ServerWebExchangeHelper.extractAttributes(exchange, context);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@

public final class ServerWebExchangeHelper {

/**
* Route info key.
*/
/** Route info key. */
public static final String ROUTE_INFO_ATTRIBUTES = "ROUTE_INFO";


private ServerWebExchangeHelper() {

}
private ServerWebExchangeHelper() {}

public static void extractAttributes(ServerWebExchange exchange, Context context) {
// Record route info
Expand All @@ -34,13 +29,11 @@ public static void extractAttributes(ServerWebExchange exchange, Context context
}
}


public static String extractServerRoute(ServerWebExchange exchange) {
Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
if (route != null) {
return "Route@" + route.getId();
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package io.opentelemetry.javaagent.instrumentation.spring.gateway;/*
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.spring.gateway; /*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
Expand All @@ -20,16 +29,12 @@
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(SpringExtension.class)
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = {
GatewayTestApplication.class,
GatewayRouteMappingTest.ForceNettyAutoConfiguration.class
GatewayTestApplication.class,
GatewayRouteMappingTest.ForceNettyAutoConfiguration.class
})
public class GatewayRouteMappingTest {

Expand Down Expand Up @@ -61,16 +66,17 @@ void gatewayRouteMappingTest() {
AggregatedHttpResponse response = client.post("/gateway/echo", requestBody).aggregate().join();
assertThat(response.status().code()).isEqualTo(200);
assertThat(response.contentUtf8()).isEqualTo(requestBody);
testing.waitAndAssertTraces(trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasAttribute(
equalTo(SemanticAttributes.HTTP_ROUTE, expectRoute)),
span -> span.hasAttributesSatisfying(
satisfies(AttributeKey.stringKey(ServerWebExchangeHelper.ROUTE_INFO_ATTRIBUTES),
s -> s.contains("id='path_route'")),
satisfies(AttributeKey.stringKey(ServerWebExchangeHelper.ROUTE_INFO_ATTRIBUTES),
s -> s.contains("uri=h1c://mock.response")
)
)));
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasAttribute(equalTo(SemanticAttributes.HTTP_ROUTE, expectRoute)),
span ->
span.hasAttributesSatisfying(
satisfies(
AttributeKey.stringKey(ServerWebExchangeHelper.ROUTE_INFO_ATTRIBUTES),
s -> s.contains("id='path_route'")),
satisfies(
AttributeKey.stringKey(ServerWebExchangeHelper.ROUTE_INFO_ATTRIBUTES),
s -> s.contains("uri=h1c://mock.response")))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@ public class GatewayTestApplication {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
// A simple echo gateway.
return builder.routes()
.route("path_route", r -> r.path("/gateway/**").filters(f -> f.filter(
(exchange, chain) -> exchange.getResponse().writeWith(exchange.getRequest().getBody()))).uri("h1c://mock.response"))
return builder
.routes()
.route(
"path_route",
r ->
r.path("/gateway/**")
.filters(
f ->
f.filter(
(exchange, chain) ->
exchange
.getResponse()
.writeWith(exchange.getRequest().getBody())))
.uri("h1c://mock.response"))
.build();
}
}

0 comments on commit 239978f

Please sign in to comment.