Fix latest dep builds (#6603)

* Fix latest dep builds

* fix couchbase 3.2 too

* codenarc

* fix jedis 4.0 tests

* fix restlet 2.0 tests

* fix armeria tests

* Update instrumentation/couchbase/couchbase-3.2/javaagent/src/test/groovy/CouchbaseClient32Test.groovy

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
Mateusz Rzeszutek 2022-09-14 06:41:13 +02:00 committed by GitHub
parent d5c6453636
commit ba854d122a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 20 deletions

View File

@ -18,3 +18,9 @@ dependencies {
testImplementation(project(":instrumentation:armeria-1.3:testing"))
}
tasks {
test {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}
}

View File

@ -8,3 +8,9 @@ dependencies {
testImplementation(project(":instrumentation:armeria-1.3:testing"))
}
tasks {
test {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}
}

View File

@ -100,6 +100,12 @@ public abstract class AbstractArmeriaHttpClientTest extends AbstractHttpClientTe
// armeria requests can't be reused
options.disableTestReusedRequest();
options.enableTestReadTimeout();
// TODO armeria 1.19 changed how the HttpResponse#aggregate() method works, and callbacks no
// longer execute in parent context
if (Boolean.getBoolean("testLatestDeps")) {
options.disableTestCallback();
}
}
@Test

View File

@ -37,16 +37,16 @@ class CouchbaseSpanUtil {
"$SemanticAttributes.NET_TRANSPORT" { it == null || it == IP_TCP }
// Because of caching, not all requests hit the server so these attributes may be absent
"net.sock.peer.addr" { it == "127.0.0.1" || it == null }
"net.sock.peer.name" { it == "localhost" || it == null }
"net.sock.peer.port" { it == null || Number }
"net.sock.peer.name" { it == "localhost" || it == "127.0.0.1" || it == null }
"net.sock.peer.port" { it == null || it instanceof Number }
// Because of caching, not all requests hit the server so this tag may be absent
"couchbase.local.address" { it == null || String }
"couchbase.local.address" { it == null || it instanceof String }
// Not all couchbase operations have operation id. Notably, 'ViewQuery's do not
// We assign a spanName of 'Bucket.query' and this is shared with n1ql queries
// that do have operation ids
"couchbase.operation_id" { it == null || String }
"couchbase.operation_id" { it == null || it instanceof String }
}
}
}

View File

@ -38,6 +38,7 @@ dependencies {
tasks {
test {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].getService())
}
}

View File

@ -17,6 +17,8 @@ import spock.lang.Shared
import java.time.Duration
import static io.opentelemetry.api.trace.StatusCode.ERROR
// Couchbase instrumentation is owned upstream so we don't assert on the contents of the spans, only
// that the instrumentation is properly registered by the agent, meaning some spans were generated.
class CouchbaseClient32Test extends AgentInstrumentationSpecification {
@ -61,6 +63,10 @@ class CouchbaseClient32Test extends AgentInstrumentationSpecification {
trace(0, 2) {
span(0) {
name(~/.*get/)
if (Boolean.getBoolean("testLatestDeps")) {
// this is the correct behavior
status ERROR
}
}
span(1) {
name(~/.*dispatch_to_server/)

View File

@ -53,7 +53,7 @@ class Jedis40ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION" "SET"
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
"net.sock.peer.addr" "127.0.0.1"
"net.sock.peer.name" "localhost"
"net.sock.peer.name" { it == "localhost" || it == "127.0.0.1" }
"net.sock.peer.port" port
}
}
@ -80,7 +80,7 @@ class Jedis40ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION" "SET"
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
"net.sock.peer.addr" "127.0.0.1"
"net.sock.peer.name" "localhost"
"net.sock.peer.name" { it == "localhost" || it == "127.0.0.1" }
"net.sock.peer.port" port
}
}
@ -95,7 +95,7 @@ class Jedis40ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION" "GET"
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
"net.sock.peer.addr" "127.0.0.1"
"net.sock.peer.name" "localhost"
"net.sock.peer.name" { it == "localhost" || it == "127.0.0.1" }
"net.sock.peer.port" port
}
}
@ -122,7 +122,7 @@ class Jedis40ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION" "SET"
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
"net.sock.peer.addr" "127.0.0.1"
"net.sock.peer.name" "localhost"
"net.sock.peer.name" { it == "localhost" || it == "127.0.0.1" }
"net.sock.peer.port" port
}
}
@ -137,7 +137,7 @@ class Jedis40ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION" "RANDOMKEY"
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
"net.sock.peer.addr" "127.0.0.1"
"net.sock.peer.name" "localhost"
"net.sock.peer.name" { it == "localhost" || it == "127.0.0.1" }
"net.sock.peer.port" port
}
}

View File

@ -5,15 +5,75 @@
package io.opentelemetry.instrumentation.restlet.v2_0.internal;
import static java.lang.invoke.MethodType.methodType;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import javax.annotation.Nullable;
import org.restlet.Request;
import org.restlet.engine.http.HttpRequest;
import org.restlet.engine.http.ServerCall;
final class RestletNetAttributesGetter implements NetServerAttributesGetter<Request> {
private static final Class<?> HTTP_REQUEST_CLASS;
private static final MethodHandle GET_HTTP_CALL;
private static final MethodHandle GET_HOST_DOMAIN;
private static final MethodHandle GET_SERVER_PORT;
private static final MethodHandle GET_SERVER_ADDRESS;
static {
Class<?> httpRequestClass = null;
Class<?> serverCallClass = null;
MethodHandle getHttpCall = null;
MethodHandle getHostDomain = null;
MethodHandle getServerPort = null;
MethodHandle getServerAddress = null;
try {
httpRequestClass = Class.forName("org.restlet.engine.http.HttpRequest");
} catch (ClassNotFoundException e) {
// moved to another package in version 2.4
try {
httpRequestClass = Class.forName("org.restlet.engine.adapter.HttpRequest");
} catch (ClassNotFoundException ex) {
// ignored
}
}
try {
serverCallClass = Class.forName("org.restlet.engine.http.ServerCall");
} catch (ClassNotFoundException e) {
// moved to another package in version 2.4
try {
serverCallClass = Class.forName("org.restlet.engine.adapter.ServerCall");
} catch (ClassNotFoundException ex) {
// ignored
}
}
if (httpRequestClass != null && serverCallClass != null) {
try {
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
getHttpCall =
lookup.findVirtual(httpRequestClass, "getHttpCall", methodType(serverCallClass));
getHostDomain =
lookup.findVirtual(serverCallClass, "getHostDomain", methodType(String.class));
getServerPort = lookup.findVirtual(serverCallClass, "getServerPort", methodType(int.class));
getServerAddress =
lookup.findVirtual(serverCallClass, "getServerAddress", methodType(String.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
// ignored
}
}
HTTP_REQUEST_CLASS = httpRequestClass;
GET_HTTP_CALL = getHttpCall;
GET_HOST_DOMAIN = getHostDomain;
GET_SERVER_PORT = getServerPort;
GET_SERVER_ADDRESS = getServerAddress;
}
@Override
public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
@ -22,15 +82,35 @@ final class RestletNetAttributesGetter implements NetServerAttributesGetter<Requ
@Nullable
@Override
public String hostName(Request request) {
ServerCall call = serverCall(request);
return call == null ? null : call.getHostDomain();
if (GET_HOST_DOMAIN == null) {
return null;
}
Object call = serverCall(request);
if (call == null) {
return null;
}
try {
return (String) GET_HOST_DOMAIN.invoke(call);
} catch (Throwable e) {
return null;
}
}
@Nullable
@Override
public Integer hostPort(Request request) {
ServerCall call = serverCall(request);
return call == null ? null : call.getServerPort();
if (GET_SERVER_PORT == null) {
return null;
}
Object call = serverCall(request);
if (call == null) {
return null;
}
try {
return (int) GET_SERVER_PORT.invoke(call);
} catch (Throwable e) {
return null;
}
}
@Override
@ -47,14 +127,31 @@ final class RestletNetAttributesGetter implements NetServerAttributesGetter<Requ
@Nullable
@Override
public String sockHostAddr(Request request) {
ServerCall call = serverCall(request);
return call == null ? null : call.getServerAddress();
if (GET_SERVER_ADDRESS == null) {
return null;
}
Object call = serverCall(request);
if (call == null) {
return null;
}
try {
return (String) GET_SERVER_ADDRESS.invoke(call);
} catch (Throwable e) {
return null;
}
}
@Nullable
private static ServerCall serverCall(Request request) {
if (request instanceof HttpRequest) {
return ((HttpRequest) request).getHttpCall();
private static Object serverCall(Request request) {
if (GET_HTTP_CALL == null || HTTP_REQUEST_CLASS == null) {
return null;
}
if (HTTP_REQUEST_CLASS.isInstance(request)) {
try {
return GET_HTTP_CALL.invoke(request);
} catch (Throwable e) {
return null;
}
}
return null;
}