-
Notifications
You must be signed in to change notification settings - Fork 86
Make it possible to set capabilities #366
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
adcb1be
cf4a028
21667d9
3f61b9c
4b81c39
a130307
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
ErrReportsEffectiveConfigNotSet = errors.New("ReportsEffectiveConfig capability is not set") | ||
ErrReportsRemoteConfigNotSet = errors.New("ReportsRemoteConfig capability is not set") | ||
ErrPackagesStateProviderNotSet = errors.New("PackagesStateProvider must be set") | ||
ErrCapabilitiesNotSet = errors.New("Capabilities is not set") | ||
ErrAcceptsPackagesNotSet = errors.New("AcceptsPackages and ReportsPackageStatuses must be set") | ||
ErrAvailableComponentsMissing = errors.New("AvailableComponents is nil") | ||
|
||
|
@@ -97,13 +98,18 @@ | |
if c.isStarted { | ||
return errAlreadyStarted | ||
} | ||
capabilities := settings.Capabilities | ||
|
||
// According to OpAMP spec this capability MUST be set, since all Agents MUST report status. | ||
capabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsStatus | ||
if err := c.ClientSyncedState.SetCapabilities(&capabilities); err != nil { | ||
return err | ||
// Deprecated: Use client.SetCapabilities() instead. | ||
if settings.Capabilities != 0 { | ||
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. @tigrannajaryan this technically could be a breaking change if someone isn't setting any capabilities, should I just default to setting reports status here and then in the future we remove this? 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 think we should emit a warning in the log if SetCapabilities is not called before Start. Later, we can make it an error. Then finally some time after that we remove Settings.Capabilities field. In any of these 3 states, ReportsStatus should always be automatically added, regardless of how the Capabilities are set (via Settings or via method call). 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. @tigrannajaryan i do make sure reportsstatus is always set (I do the add in this method as well in the clientcommon setcapabilities), but I'll add in a log right now. 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. @tigrannajaryan should be all good now. PTAL 🙇 |
||
capabilities := settings.Capabilities | ||
// According to OpAMP spec this capability MUST be set, since all Agents MUST report status. | ||
capabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsStatus | ||
if err := c.ClientSyncedState.SetCapabilities(&capabilities); err != nil { | ||
return err | ||
} | ||
} | ||
if c.ClientSyncedState.Capabilities() == 0 { | ||
return ErrCapabilitiesNotSet | ||
} | ||
|
||
if c.ClientSyncedState.AgentDescription() == nil { | ||
return ErrAgentDescriptionMissing | ||
|
@@ -111,7 +117,7 @@ | |
|
||
// Prepare package statuses. | ||
c.PackagesStateProvider = settings.PackagesStateProvider | ||
if err := c.validateCapabilities(capabilities); err != nil { | ||
if err := c.validateCapabilities(c.ClientSyncedState.Capabilities()); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -129,8 +135,8 @@ | |
|
||
var packageStatuses *protobufs.PackageStatuses | ||
if c.PackagesStateProvider != nil && | ||
c.hasCapability(protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages) && | ||
c.hasCapability(protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses) { | ||
// Set package status from the value previously saved in the PackagesStateProvider. | ||
var err error | ||
packageStatuses, err = settings.PackagesStateProvider.LastReportedStatuses() | ||
|
@@ -519,8 +525,8 @@ | |
if err := c.ClientSyncedState.SetCapabilities(capabilities); err != nil { | ||
return err | ||
} | ||
// send the new customCapabilities to the Server | ||
c.sender.NextMessage().Update( | ||
func(msg *protobufs.AgentToServer) { | ||
msg.Capabilities = uint64(c.ClientSyncedState.Capabilities()) | ||
}, | ||
|
@@ -528,8 +534,8 @@ | |
c.sender.ScheduleSend() | ||
return nil | ||
} | ||
|
||
// QUESTION: DO we want this? | ||
// SetPackagesStateProvider allows the confgiguration of the packages state provider after start. | ||
// func (c *ClientCommon) SetPackagesStateProvider(packagesStateProvider types.PackagesStateProvider) error { | ||
// c.PackageSyncMutex.Lock() | ||
|
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.
i had to ignore the error here because a later test depended on the checks happening in the start client