Skip to content

Commit 95c30f2

Browse files
authored
Opamp client implementation (#2021)
1 parent 2859205 commit 95c30f2

34 files changed

+2217
-58
lines changed

dependencyManagement/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
api(enforcedPlatform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${otelInstrumentationVersion}"))
1818
api(enforcedPlatform("com.fasterxml.jackson:jackson-bom:2.19.2"))
1919
api(enforcedPlatform("com.google.protobuf:protobuf-bom:4.31.1"))
20+
api(enforcedPlatform("com.squareup.okhttp3:okhttp-bom:5.1.0"))
2021

2122
constraints {
2223
api("io.opentelemetry.semconv:opentelemetry-semconv:${semconvVersion}")
@@ -44,7 +45,6 @@ dependencies {
4445

4546
api("com.google.code.findbugs:annotations:3.0.1u2")
4647
api("com.google.code.findbugs:jsr305:3.0.2")
47-
api("com.squareup.okhttp3:okhttp:5.1.0")
4848
api("com.uber.nullaway:nullaway:0.12.7")
4949
api("org.assertj:assertj-core:3.27.3")
5050
api("org.awaitility:awaitility:4.3.0")
@@ -58,5 +58,6 @@ dependencies {
5858
api("tools.profiler:async-profiler:4.0")
5959
api("com.blogspot.mydailyjava:weak-lock-free:0.18")
6060
api("org.agrona:agrona:1.22.0")
61+
api("com.github.f4b6a3:uuid-creator:6.0.0")
6162
}
6263
}

opamp-client/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ otelJava.moduleName.set("io.opentelemetry.contrib.opamp.client")
1313

1414
dependencies {
1515
implementation("com.squareup.okhttp3:okhttp")
16+
implementation("com.github.f4b6a3:uuid-creator")
1617
annotationProcessor("com.google.auto.value:auto-value")
1718
compileOnly("com.google.auto.value:auto-value-annotations")
1819
testImplementation("org.mockito:mockito-inline")
1920
testImplementation("com.google.protobuf:protobuf-java-util")
21+
testImplementation("com.squareup.okhttp3:mockwebserver3")
22+
testImplementation("com.squareup.okhttp3:mockwebserver3-junit5")
2023
}
2124

2225
val opampProtos = tasks.register<DownloadOpampProtos>("opampProtoDownload", download)

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/OpampClient.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
package io.opentelemetry.opamp.client.internal;
77

88
import io.opentelemetry.opamp.client.internal.response.MessageData;
9+
import javax.annotation.Nullable;
910
import opamp.proto.AgentDescription;
1011
import opamp.proto.RemoteConfigStatus;
1112
import opamp.proto.ServerErrorResponse;
1213

1314
public interface OpampClient {
1415

16+
static OpampClientBuilder builder() {
17+
return new OpampClientBuilder();
18+
}
19+
1520
/**
1621
* Starts the client and begin attempts to connect to the Server. Once connection is established
1722
* the client will attempt to maintain it by reconnecting if the connection is lost. All failed
18-
* connection attempts will be reported via {@link Callbacks#onConnectFailed(OpampClient,
19-
* Throwable)} callback.
23+
* connection attempts will be reported via {@link Callbacks#onConnectFailed(Throwable)} callback.
2024
*
2125
* <p>This method does not wait until the connection to the Server is established and will likely
2226
* return before the connection attempts are even made.
@@ -40,7 +44,7 @@ public interface OpampClient {
4044
* the Server. When called after {@link #start(Callbacks)}, the attributes will be included in the
4145
* next outgoing status report. This is typically used by Agents which allow their
4246
* AgentDescription to change dynamically while the OpAMPClient is started. May be also called
43-
* from {@link Callbacks#onMessage(OpampClient, MessageData)}.
47+
* from {@link Callbacks#onMessage(MessageData)}.
4448
*
4549
* @param agentDescription The new agent description.
4650
*/
@@ -59,31 +63,27 @@ interface Callbacks {
5963
* {@link #start(Callbacks)} is called and every time a connection is established to the Server.
6064
* For WebSocket clients this is called after the handshake is completed without any error. For
6165
* HTTP clients this is called for any request if the response status is OK.
62-
*
63-
* @param client The relevant {@link OpampClient} instance.
6466
*/
65-
void onConnect(OpampClient client);
67+
void onConnect();
6668

6769
/**
6870
* Called when the connection to the Server cannot be established. May be called after {@link
6971
* #start(Callbacks)} is called and tries to connect to the Server. May also be called if the
7072
* connection is lost and reconnection attempt fails.
7173
*
72-
* @param client The relevant {@link OpampClient} instance.
7374
* @param throwable The exception.
7475
*/
75-
void onConnectFailed(OpampClient client, Throwable throwable);
76+
void onConnectFailed(@Nullable Throwable throwable);
7677

7778
/**
7879
* Called when the Server reports an error in response to some previously sent request. Useful
7980
* for logging purposes. The Agent should not attempt to process the error by reconnecting or
8081
* retrying previous operations. The client handles the ErrorResponse_UNAVAILABLE case
8182
* internally by performing retries as necessary.
8283
*
83-
* @param client The relevant {@link OpampClient} instance.
8484
* @param errorResponse The error returned by the Server.
8585
*/
86-
void onErrorResponse(OpampClient client, ServerErrorResponse errorResponse);
86+
void onErrorResponse(ServerErrorResponse errorResponse);
8787

8888
/**
8989
* Called when the Agent receives a message that needs processing. See {@link MessageData}
@@ -94,9 +94,8 @@ interface Callbacks {
9494
* onMessage returns. This is advisable if processing can take a long time. In that case
9595
* returning quickly is preferable to avoid blocking the {@link OpampClient}.
9696
*
97-
* @param client The relevant {@link OpampClient} instance.
9897
* @param messageData The server response data that needs processing.
9998
*/
100-
void onMessage(OpampClient client, MessageData messageData);
99+
void onMessage(MessageData messageData);
101100
}
102101
}

0 commit comments

Comments
 (0)