Skip to content

Commit

Permalink
spotlessApply
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca committed Jun 27, 2023
1 parent 1e12301 commit 758a23f
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class DirectCamelTest {

@RegisterExtension
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

private static ConfigurableApplicationContext server;

@BeforeAll
Expand Down Expand Up @@ -49,15 +50,15 @@ public void simpleDirectToSingleService() {
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("input")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://input"),
span -> span.hasName("receiver")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://receiver")
)
);
span ->
span.hasName("input")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://input"),
span ->
span.hasName("receiver")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://receiver")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MulticastDirectCamelTest {

@RegisterExtension
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

private static ConfigurableApplicationContext server;

@BeforeAll
Expand All @@ -48,19 +49,20 @@ public void parallelMulticastToTwoChildServices() {
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactlyInAnyOrder(
span -> span.hasName("input")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://input"),
span -> span.hasName("first")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://first"),
span -> span.hasName("second")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://second")
)
);
span ->
span.hasName("input")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://input"),
span ->
span.hasName("first")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://first"),
span ->
span.hasName("second")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://second")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class RestCamelTest extends RetryOnAddressAlreadyInUse {

@RegisterExtension
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

private static ConfigurableApplicationContext server;

private static Integer port;
Expand Down Expand Up @@ -60,71 +61,70 @@ public void restComponentServerAndClientCallWithJettyBackend() {

// run client and server in separate threads to simulate "real" rest client/server call
new Thread(
() -> template.sendBodyAndHeaders(
"direct:start",
null,
ImmutableMap.of("module", "firstModule", "unitId", "unitOne")
)
).start();
() ->
template.sendBodyAndHeaders(
"direct:start",
null,
ImmutableMap.of("module", "firstModule", "unitId", "unitOne")))
.start();

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("start")
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("camel.uri"), "direct://start")
),
span -> span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParentSpanId(trace.getSpan(0).getSpanId())
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("camel.uri"),
"rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L)
),
span -> span.hasName("GET /api/{module}/unit/{unitId}")
.hasKind(SpanKind.SERVER)
.hasParentSpanId(trace.getSpan(1).getSpanId())
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_SCHEME, "http"),
equalTo(SemanticAttributes.HTTP_TARGET, "/api/firstModule/unit/unitOne"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_ROUTE, "/api/{module}/unit/{unitId}"),
equalTo(AttributeKey.stringKey("net.protocol.name"), "http"),
equalTo(AttributeKey.stringKey("net.protocol.version"), "1.1"),
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
equalTo(SemanticAttributes.NET_HOST_PORT, Long.valueOf(port)),
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"),
satisfies(
SemanticAttributes.USER_AGENT_ORIGINAL,
val -> val.isInstanceOf(String.class)
),
satisfies(
SemanticAttributes.NET_SOCK_PEER_PORT,
val -> val.isInstanceOf(Long.class)
)
),
span -> span.hasName("GET /api/{module}/unit/{unitId}")
.hasKind(SpanKind.INTERNAL)
.hasParentSpanId(trace.getSpan(2).getSpanId())
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_URL,
"http://localhost:" + port + "/api/firstModule/unit/unitOne"),
satisfies(
AttributeKey.stringKey("camel.uri"),
val -> val.isInstanceOf(String.class)
)
),
span -> span.hasName("moduleUnit")
.hasKind(SpanKind.INTERNAL)
.hasParentSpanId(trace.getSpan(3).getSpanId())
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://moduleUnit")
)
);
span ->
span.hasName("start")
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("camel.uri"), "direct://start")),
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParentSpanId(trace.getSpan(0).getSpanId())
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("camel.uri"),
"rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L)),
span ->
span.hasName("GET /api/{module}/unit/{unitId}")
.hasKind(SpanKind.SERVER)
.hasParentSpanId(trace.getSpan(1).getSpanId())
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_SCHEME, "http"),
equalTo(
SemanticAttributes.HTTP_TARGET, "/api/firstModule/unit/unitOne"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_ROUTE, "/api/{module}/unit/{unitId}"),
equalTo(AttributeKey.stringKey("net.protocol.name"), "http"),
equalTo(AttributeKey.stringKey("net.protocol.version"), "1.1"),
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
equalTo(SemanticAttributes.NET_HOST_PORT, Long.valueOf(port)),
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"),
satisfies(
SemanticAttributes.USER_AGENT_ORIGINAL,
val -> val.isInstanceOf(String.class)),
satisfies(
SemanticAttributes.NET_SOCK_PEER_PORT,
val -> val.isInstanceOf(Long.class))),
span ->
span.hasName("GET /api/{module}/unit/{unitId}")
.hasKind(SpanKind.INTERNAL)
.hasParentSpanId(trace.getSpan(2).getSpanId())
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(
SemanticAttributes.HTTP_URL,
"http://localhost:" + port + "/api/firstModule/unit/unitOne"),
satisfies(
AttributeKey.stringKey("camel.uri"),
val -> val.isInstanceOf(String.class))),
span ->
span.hasName("moduleUnit")
.hasKind(SpanKind.INTERNAL)
.hasParentSpanId(trace.getSpan(3).getSpanId())
.hasAttribute(AttributeKey.stringKey("camel.uri"), "direct://moduleUnit")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ public void configure() throws Exception {
.port("{{restServer.port}}")
.producerComponent("http");

rest("/api")
.get("/{module}/unit/{unitId}")
.to("direct:moduleUnit");
rest("/api").get("/{module}/unit/{unitId}").to("direct:moduleUnit");

from("direct:moduleUnit")
.transform().simple("${header.unitId} of ${header.module}");
from("direct:moduleUnit").transform().simple("${header.unitId} of ${header.module}");

// producer - client route
from("direct:start")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apachecamel;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class RetryOnAddressAlreadyInUse {
private static final Logger logger = LoggerFactory.getLogger(RetryOnAddressAlreadyInUse.class);
Expand All @@ -14,7 +19,9 @@ static void withRetryOnAddressAlreadyInUse(Runnable closure, int numRetries) {
try {
closure.run();
} catch (Throwable t) {
if (numRetries == 0 || t.getMessage() == null || !t.getMessage().contains("Address already in use")) {
if (numRetries == 0
|| t.getMessage() == null
|| !t.getMessage().contains("Address already in use")) {
throw t;
}
logger.debug("retrying due to bind exception: {}", t.getMessage(), t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -13,6 +14,7 @@
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand All @@ -23,9 +25,6 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import java.io.IOException;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

public class SingleServiceCamelTest extends RetryOnAddressAlreadyInUse {

Expand Down Expand Up @@ -63,25 +62,25 @@ public static void cleanupSpec() {
public void singleCamelServiceSpan() throws IOException {
String requestUrl = "http://localhost:" + port + "/camelService";

Request request = new Request.Builder()
.url(requestUrl)
.post(RequestBody.create("testContent", MediaType.parse("text/plain")))
.build();
Request request =
new Request.Builder()
.url(requestUrl)
.post(RequestBody.create("testContent", MediaType.parse("text/plain")))
.build();

client.newCall(request).execute();

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("POST /camelService")
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
equalTo(SemanticAttributes.HTTP_URL, requestUrl),
equalTo(AttributeKey.stringKey("camel.uri"),
requestUrl.replace("localhost", "0.0.0.0"))
)
)
);
span ->
span.hasName("POST /camelService")
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
equalTo(SemanticAttributes.HTTP_URL, requestUrl),
equalTo(
AttributeKey.stringKey("camel.uri"),
requestUrl.replace("localhost", "0.0.0.0")))));
}
}
Loading

0 comments on commit 758a23f

Please sign in to comment.