Skip to content
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

chore(docs): add docs for public types and functions #167

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"github.com/open-telemetry/opamp-go/protobufs"
)

// OpAMPClient is an interface representing the client side of the OpAMP protocol.
type OpAMPClient interface {

// Start 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
// OnConnectFailed callback.
//
// AgentDescription in settings MUST be set.
// SetAgentDescription() MUST be called before Start().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

//
// Start may immediately return an error if the settings are incorrect (e.g. the
// serverURL is not a valid URL).
Expand Down
13 changes: 13 additions & 0 deletions client/types/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/open-telemetry/opamp-go/protobufs"
)

// MessageData represents a message received from the server and handled by Callbacks.
type MessageData struct {
// RemoteConfig is offered by the Server. The Agent must process it and call
// OpAMPClient.SetRemoteConfigStatus to indicate success or failure. If the
Expand Down Expand Up @@ -38,6 +39,7 @@ type MessageData struct {
AgentIdentification *protobufs.AgentIdentification
}

// Callbacks is an interface for the Client to handle messages from the Server.
type Callbacks interface {
// OnConnect is called when the connection is successfully established to the Server.
// May be called after Start() is called and every time a connection is established to the Server.
Expand Down Expand Up @@ -116,6 +118,8 @@ type Callbacks interface {
OnCommand(command *protobufs.ServerToAgentCommand) error
}

// CallbacksStruct is a struct that implements Callbacks interface and allows
// to override only the methods that are needed. If a method is not overridden then it is a no-op.
type CallbacksStruct struct {
OnConnectFunc func()
OnConnectFailedFunc func(err error)
Expand All @@ -139,43 +143,50 @@ type CallbacksStruct struct {

var _ Callbacks = (*CallbacksStruct)(nil)

// OnConnect implements Callbacks.OnConnect.
func (c CallbacksStruct) OnConnect() {
if c.OnConnectFunc != nil {
c.OnConnectFunc()
}
}

// OnConnectFailed implements Callbacks.OnConnectFailed.
func (c CallbacksStruct) OnConnectFailed(err error) {
if c.OnConnectFailedFunc != nil {
c.OnConnectFailedFunc(err)
}
}

// OnError implements Callbacks.OnError.
func (c CallbacksStruct) OnError(err *protobufs.ServerErrorResponse) {
if c.OnErrorFunc != nil {
c.OnErrorFunc(err)
}
}

// OnMessage implements Callbacks.OnMessage.
func (c CallbacksStruct) OnMessage(ctx context.Context, msg *MessageData) {
if c.OnMessageFunc != nil {
c.OnMessageFunc(ctx, msg)
}
}

// SaveRemoteConfigStatus implements Callbacks.SaveRemoteConfigStatus.
func (c CallbacksStruct) SaveRemoteConfigStatus(ctx context.Context, status *protobufs.RemoteConfigStatus) {
if c.SaveRemoteConfigStatusFunc != nil {
c.SaveRemoteConfigStatusFunc(ctx, status)
}
}

// GetEffectiveConfig implements Callbacks.GetEffectiveConfig.
func (c CallbacksStruct) GetEffectiveConfig(ctx context.Context) (*protobufs.EffectiveConfig, error) {
if c.GetEffectiveConfigFunc != nil {
return c.GetEffectiveConfigFunc(ctx)
}
return nil, nil
}

// OnOpampConnectionSettings implements Callbacks.OnOpampConnectionSettings.
func (c CallbacksStruct) OnOpampConnectionSettings(
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
) error {
Expand All @@ -185,12 +196,14 @@ func (c CallbacksStruct) OnOpampConnectionSettings(
return nil
}

// OnOpampConnectionSettingsAccepted implements Callbacks.OnOpampConnectionSettingsAccepted.
func (c CallbacksStruct) OnOpampConnectionSettingsAccepted(settings *protobufs.OpAMPConnectionSettings) {
if c.OnOpampConnectionSettingsAcceptedFunc != nil {
c.OnOpampConnectionSettingsAcceptedFunc(settings)
}
}

// OnCommand implements Callbacks.OnCommand.
func (c CallbacksStruct) OnCommand(command *protobufs.ServerToAgentCommand) error {
if c.OnCommandFunc != nil {
return c.OnCommandFunc(command)
Expand Down
1 change: 1 addition & 0 deletions client/types/logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package types

// Logger is the logging interface used by the OpAMP Client.
type Logger interface {
Debugf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Expand Down
1 change: 1 addition & 0 deletions client/types/packagessyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PackagesSyncer interface {
Done() <-chan struct{}
}

// PackageState represents the state of a package in the Agent's local storage.
type PackageState struct {
// Exists indicates that the package exists locally. The rest of the fields
// must be ignored if this field is false.
Expand Down
1 change: 1 addition & 0 deletions client/types/startsettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/open-telemetry/opamp-go/protobufs"
)

// StartSettings defines the parameters for starting the OpAMP Client.
type StartSettings struct {
// Connection parameters.

Expand Down