Skip to content

Commit

Permalink
Remove OnOpampConnectionSettingsAccepted callback (#266)
Browse files Browse the repository at this point in the history
Contributes to #261

I intentionally left undefined the blocking vs nonblocking
requirement for the callback. I suggest that we refine this
after we make implementations and settle on a particular
behavior.

A continuation of this PR is needed that implements steps 4 and 5
of the flow described here:
#261
  • Loading branch information
tigrannajaryan authored Mar 25, 2024
1 parent 8d40419 commit c319cfa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
5 changes: 2 additions & 3 deletions client/internal/receivedprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ func (r *receivedProcessor) rcvOpampConnectionSettings(ctx context.Context, sett

if r.hasCapability(protobufs.AgentCapabilities_AgentCapabilities_AcceptsOpAMPConnectionSettings) {
err := r.callbacks.OnOpampConnectionSettings(ctx, settings.Opamp)
if err == nil {
// TODO: verify connection using new settings.
r.callbacks.OnOpampConnectionSettingsAccepted(ctx, settings.Opamp)
if err != nil {
r.logger.Errorf(ctx, "Failed to process OpAMPConnectionSettings: %v", err)
}
} else {
r.logger.Debugf(ctx, "Ignoring Opamp, agent does not have AcceptsOpAMPConnectionSettings capability")
Expand Down
29 changes: 3 additions & 26 deletions client/types/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,9 @@ type Callbacks interface {
// authorization headers or TLS certificate, potentially also a different
// OpAMP destination to work with.
//
// The Agent should process the offer and return an error if the Agent does not
// want to accept the settings (e.g. if the TSL certificate in the settings
// cannot be verified).
//
// If OnOpampConnectionSettings returns nil and then the caller will
// attempt to reconnect to the OpAMP Server using the new settings.
// If the connection fails the settings will be rejected and an error will
// be reported to the Server. If the connection succeeds the new settings
// will be used by the client from that moment on.
// The Agent should process the offer by reconnecting the client using the new
// settings or return an error if the Agent does not want to accept the settings
// (e.g. if the TSL certificate in the settings cannot be verified).
//
// Only one OnOpampConnectionSettings call can be active at any time.
// See OnRemoteConfig for the behavior.
Expand All @@ -98,12 +92,6 @@ type Callbacks interface {
settings *protobufs.OpAMPConnectionSettings,
) error

// OnOpampConnectionSettingsAccepted will be called after the settings are
// verified and accepted (OnOpampConnectionSettingsOffer and connection using
// new settings succeeds). The Agent should store the settings and use them
// in the future. Old connection settings should be forgotten.
OnOpampConnectionSettingsAccepted(ctx context.Context, settings *protobufs.OpAMPConnectionSettings)

// For all methods that accept a context parameter the caller may cancel the
// context if processing takes too long. In that case the method should return
// as soon as possible with an error.
Expand Down Expand Up @@ -137,10 +125,6 @@ type CallbacksStruct struct {
ctx context.Context,
settings *protobufs.OpAMPConnectionSettings,
) error
OnOpampConnectionSettingsAcceptedFunc func(
ctx context.Context,
settings *protobufs.OpAMPConnectionSettings,
)

OnCommandFunc func(ctx context.Context, command *protobufs.ServerToAgentCommand) error

Expand Down Expand Up @@ -203,13 +187,6 @@ func (c CallbacksStruct) OnOpampConnectionSettings(
return nil
}

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

// OnCommand implements Callbacks.OnCommand.
func (c CallbacksStruct) OnCommand(ctx context.Context, command *protobufs.ServerToAgentCommand) error {
if c.OnCommandFunc != nil {
Expand Down

0 comments on commit c319cfa

Please sign in to comment.