Skip to content

Commit

Permalink
Merge branch 'main' into influxdb-operation
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Jun 12, 2024
2 parents 2dd66b4 + 4c8091b commit 1d13eb2
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 11 deletions.
24 changes: 24 additions & 0 deletions instrumentation/okhttp/okhttp-3.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,27 @@ dependencies {

testImplementation(project(":instrumentation:okhttp:okhttp-3.0:testing"))
}

val testLatestDeps = findProperty("testLatestDeps") as Boolean

testing {
suites {
val http2Test by registering(JvmTestSuite::class) {
dependencies {
if (testLatestDeps) {
implementation("com.squareup.okhttp3:okhttp:+")
compileOnly("com.google.android:annotations:4.1.1.4")
} else {
implementation("com.squareup.okhttp3:okhttp:3.11.0")
}
implementation(project(":instrumentation:okhttp:okhttp-3.0:testing"))
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.okhttp.v3_0;

import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.okhttp.v3_0.AbstractOkHttp3Test;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.junit.jupiter.api.extension.RegisterExtension;

class OkHttp3Http2Test extends AbstractOkHttp3Test {

@RegisterExtension
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent();

@Override
public Call.Factory createCallFactory(OkHttpClient.Builder clientBuilder) {
clientBuilder.protocols(singletonList(Protocol.H2_PRIOR_KNOWLEDGE));
return clientBuilder.build();
}

@Override
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
super.configure(optionsBuilder);

// https does not work with H2_PRIOR_KNOWLEDGE
optionsBuilder.disableTestHttps();
optionsBuilder.setHttpProtocolVersion(uri -> "2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.okhttp.v3_0;

import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.instrumentation.okhttp.v3_0.AbstractOkHttp3Test;
Expand All @@ -13,16 +14,18 @@
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class OkHttp3Test extends AbstractOkHttp3Test {
class OkHttp3Test extends AbstractOkHttp3Test {

@RegisterExtension
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent();

@Override
public Call.Factory createCallFactory(OkHttpClient.Builder clientBuilder) {
clientBuilder.protocols(singletonList(Protocol.HTTP_1_1));
return clientBuilder.build();
}

Expand Down
25 changes: 25 additions & 0 deletions instrumentation/okhttp/okhttp-3.0/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,28 @@ dependencies {

testImplementation(project(":instrumentation:okhttp:okhttp-3.0:testing"))
}

val testLatestDeps = findProperty("testLatestDeps") as Boolean

testing {
suites {
val http2Test by registering(JvmTestSuite::class) {
dependencies {
implementation(project())
if (testLatestDeps) {
implementation("com.squareup.okhttp3:okhttp:+")
compileOnly("com.google.android:annotations:4.1.1.4")
} else {
implementation("com.squareup.okhttp3:okhttp:3.11.0")
}
implementation(project(":instrumentation:okhttp:okhttp-3.0:testing"))
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.okhttp.v3_0;

import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.junit.jupiter.api.extension.RegisterExtension;

class OkHttp3Http2Test extends AbstractOkHttp3Test {

@RegisterExtension
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary();

@Override
public Call.Factory createCallFactory(OkHttpClient.Builder clientBuilder) {
clientBuilder.protocols(singletonList(Protocol.H2_PRIOR_KNOWLEDGE));
return OkHttpTelemetry.builder(testing.getOpenTelemetry())
.setCapturedRequestHeaders(singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER))
.setCapturedResponseHeaders(singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER))
.build()
.newCallFactory(clientBuilder.build());
}

@Override
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
super.configure(optionsBuilder);

// https does not work with H2_PRIOR_KNOWLEDGE
optionsBuilder.disableTestHttps();
optionsBuilder.setHttpProtocolVersion(uri -> "2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public String getNetworkProtocolName(Request request, @Nullable Response respons
case SPDY_3:
return "spdy";
}
// added in 3.11.0
if ("H2_PRIOR_KNOWLEDGE".equals(response.protocol().name())) {
return "http";
}
return null;
}

Expand All @@ -77,6 +81,10 @@ public String getNetworkProtocolVersion(Request request, @Nullable Response resp
case SPDY_3:
return "3.1";
}
// added in 3.11.0
if ("H2_PRIOR_KNOWLEDGE".equals(response.protocol().name())) {
return "2";
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@

package io.opentelemetry.instrumentation.okhttp.v3_0;

import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import java.util.Collections;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.junit.jupiter.api.extension.RegisterExtension;

public class OkHttp3Test extends AbstractOkHttp3Test {
class OkHttp3Test extends AbstractOkHttp3Test {

@RegisterExtension
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary();

@Override
public Call.Factory createCallFactory(OkHttpClient.Builder clientBuilder) {
clientBuilder.protocols(singletonList(Protocol.HTTP_1_1));
return OkHttpTelemetry.builder(testing.getOpenTelemetry())
.setCapturedRequestHeaders(
Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER))
.setCapturedResponseHeaders(
Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER))
.setCapturedRequestHeaders(singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER))
.setCapturedResponseHeaders(singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER))
.build()
.newCallFactory(clientBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.instrumentation.okhttp.v3_0;

import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -27,7 +26,6 @@
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
Expand All @@ -45,8 +43,7 @@ public abstract class AbstractOkHttp3Test extends AbstractHttpClientTest<Request
protected OkHttpClient.Builder getClientBuilder(boolean withReadTimeout) {
OkHttpClient.Builder builder =
new OkHttpClient.Builder()
.connectTimeout(CONNECTION_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS)
.protocols(singletonList(Protocol.HTTP_1_1));
.connectTimeout(CONNECTION_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
if (withReadTimeout) {
builder
// don't want retries on time outs
Expand Down Expand Up @@ -125,6 +122,7 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
// response)
if ("http://localhost:61/".equals(uri.toString())
|| "https://192.0.2.1/".equals(uri.toString())
|| "http://192.0.2.1/".equals(uri.toString())
|| resolveAddress("/read-timeout").toString().equals(uri.toString())) {
attributes.remove(NetworkAttributes.NETWORK_PROTOCOL_VERSION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.testcontainers.containers.output.Slf4jLogConsumer
import org.testcontainers.containers.wait.strategy.Wait
import org.testcontainers.utility.DockerImageName
import org.testcontainers.utility.MountableFile
import spock.lang.Ignore
import spock.lang.IgnoreIf
import spock.lang.Specification

Expand All @@ -24,6 +25,12 @@ import static io.opentelemetry.smoketest.TestContainerManager.useWindowsContaine
// java.lang.invoke.CallSite
// This test verifies that such jvm does not crash with opentelemetry agent
@IgnoreIf({ useWindowsContainers() })
// com.github.dockerjava.api.exception.DockerClientException: Could not pull image: [DEPRECATION NOTICE]
// Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default
// and will be removed in an upcoming release. Suggest the author of docker.io/azul/zulu-openjdk:8u31
// to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information
// at https://docs.docker.com/go/deprecated-image-specs/
@Ignore
class CrashEarlyJdk8Test extends Specification {
private static final Logger logger = LoggerFactory.getLogger(CrashEarlyJdk8Test)

Expand Down

0 comments on commit 1d13eb2

Please sign in to comment.