-
Notifications
You must be signed in to change notification settings - Fork 159
Opamp client api #1835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opamp client api #1835
Changes from 5 commits
9304779
578e121
c8df521
543470f
0362083
aa82372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.opamp.client.internal; | ||
|
||
import io.opentelemetry.opamp.client.internal.response.MessageData; | ||
import opamp.proto.AgentDescription; | ||
import opamp.proto.RemoteConfigStatus; | ||
import opamp.proto.ServerErrorResponse; | ||
|
||
public interface OpampClient { | ||
|
||
/** | ||
* Starts the client and begin attempts to connect to the Server. Once connection is established | ||
* the client will attempt to maintain it by reconnecting if the connection is lost. All failed | ||
* connection attempts will be reported via {@link Callbacks#onConnectFailed(OpampClient, | ||
* Throwable)} callback. | ||
* | ||
* <p>This method does not wait until the connection to the Server is established and will likely | ||
* return before the connection attempts are even made. | ||
* | ||
* <p>This method may be called only once. | ||
* | ||
* @param callbacks The Callback to which the Client will notify about any Server requests and | ||
* responses. | ||
*/ | ||
void start(Callbacks callbacks); | ||
tigrannajaryan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Stops the client. May be called only after {@link #start(Callbacks)}. May be called only once. | ||
* After this call returns successfully it is guaranteed that no callbacks will be called. Once | ||
* stopped, the client cannot be started again. | ||
*/ | ||
void stop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you consider implementing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't so far. The namings I used are based on the Go client ones, although we can change them to something that works better for Java if needed. I must admit that naming is hard for me because I tend to overthink it, so for example if we go with Before making the changes, I wanted to check with you if there's a use case you have in mind that benefits from using AutoCloseable, apart from try-with-resources? Since the client most likely will be a long-running operation, it's not clear to me that a try-with-resources use case will be a common usage for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming is hard for everybody, I guess we can revisit this later. While it is true that perhaps using try-with-resources with the opamp client is not going to be a common use case to me the |
||
|
||
/** | ||
* Sets attributes of the Agent. The attributes will be included in the next status report sent to | ||
* the Server. When called after {@link #start(Callbacks)}, the attributes will be included in the | ||
* next outgoing status report. This is typically used by Agents which allow their | ||
* AgentDescription to change dynamically while the OpAMPClient is started. May be also called | ||
* from {@link Callbacks#onMessage(OpampClient, MessageData)}. | ||
* | ||
* @param agentDescription The new agent description. | ||
*/ | ||
void setAgentDescription(AgentDescription agentDescription); | ||
|
||
/** | ||
* Sets the current remote config status which will be sent in the next agent to server request. | ||
* | ||
* @param remoteConfigStatus The new remote config status. | ||
*/ | ||
void setRemoteConfigStatus(RemoteConfigStatus remoteConfigStatus); | ||
|
||
interface Callbacks { | ||
/** | ||
* Called when the connection is successfully established to the Server. May be called after | ||
* {@link #start(Callbacks)} is called and every time a connection is established to the Server. | ||
* For WebSocket clients this is called after the handshake is completed without any error. For | ||
* HTTP clients this is called for any request if the response status is OK. | ||
* | ||
* @param client The relevant {@link OpampClient} instance. | ||
*/ | ||
void onConnect(OpampClient client); | ||
|
||
/** | ||
* Called when the connection to the Server cannot be established. May be called after {@link | ||
* #start(Callbacks)} is called and tries to connect to the Server. May also be called if the | ||
* connection is lost and reconnection attempt fails. | ||
* | ||
* @param client The relevant {@link OpampClient} instance. | ||
* @param throwable The exception. | ||
*/ | ||
void onConnectFailed(OpampClient client, Throwable throwable); | ||
|
||
/** | ||
* Called when the Server reports an error in response to some previously sent request. Useful | ||
* for logging purposes. The Agent should not attempt to process the error by reconnecting or | ||
* retrying previous operations. The client handles the ErrorResponse_UNAVAILABLE case | ||
* internally by performing retries as necessary. | ||
* | ||
* @param client The relevant {@link OpampClient} instance. | ||
* @param errorResponse The error returned by the Server. | ||
*/ | ||
void onErrorResponse(OpampClient client, ServerErrorResponse errorResponse); | ||
|
||
/** | ||
* Called when the Agent receives a message that needs processing. See {@link MessageData} | ||
* definition for the data that may be available for processing. During onMessage execution the | ||
* {@link OpampClient} functions that change the status of the client may be called, e.g. if | ||
* RemoteConfig is processed then {@link #setRemoteConfigStatus(opamp.proto.RemoteConfigStatus)} | ||
* should be called to reflect the processing result. These functions may also be called after | ||
* onMessage returns. This is advisable if processing can take a long time. In that case | ||
* returning quickly is preferable to avoid blocking the {@link OpampClient}. | ||
* | ||
* @param client The relevant {@link OpampClient} instance. | ||
* @param messageData The server response data that needs processing. | ||
*/ | ||
void onMessage(OpampClient client, MessageData messageData); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.opamp.client.internal.response; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import io.opentelemetry.opamp.client.internal.OpampClient; | ||
import javax.annotation.Nullable; | ||
import opamp.proto.AgentRemoteConfig; | ||
|
||
/** | ||
* Data class provided in {@link OpampClient.Callbacks#onMessage(OpampClient, MessageData)} with | ||
* Server's provided status changes. | ||
*/ | ||
@AutoValue | ||
public abstract class MessageData { | ||
@Nullable | ||
public abstract AgentRemoteConfig getRemoteConfig(); | ||
|
||
public static Builder builder() { | ||
return new AutoValue_MessageData.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder setRemoteConfig(AgentRemoteConfig remoteConfig); | ||
|
||
public abstract MessageData build(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you shouldn't need to set the source/target version since
otel.java-conventions
already defaults to 8There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I wasn't aware of it. I just removed them.