Skip to content

Commit

Permalink
feat: Upgrade OpAMP to v0.9.0 (#1289)
Browse files Browse the repository at this point in the history
* Upgrade OpAMP library dependency to the latest commit

* move capabilities to a constant

* pr feedback
  • Loading branch information
andykellr authored Oct 24, 2023
1 parent 40f7ac5 commit 570d2d6
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 112 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/observiq/bindplane-agent/receiver/routereceiver v1.38.0
github.com/observiq/bindplane-agent/receiver/sapnetweaverreceiver v1.38.0
github.com/oklog/ulid/v2 v2.1.0
github.com/open-telemetry/opamp-go v0.2.0
github.com/open-telemetry/opamp-go v0.9.0
github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector v0.87.0
github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector v0.87.0
github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector v0.87.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/open-telemetry/opamp-go v0.2.0 h1:dV7wTkG5XNiorU62N1CJPr3f5dM0PGEtUUBtvK+LEG0=
github.com/open-telemetry/opamp-go v0.2.0/go.mod h1:IMdeuHGVc5CjKSu5/oNV0o+UmiXuahoHvoZ4GOmAI9M=
github.com/open-telemetry/opamp-go v0.9.0 h1:S6Mwn8uxYjcttE6ZJ6AXoiOuryU67zjKysz3xRfYL9k=
github.com/open-telemetry/opamp-go v0.9.0/go.mod h1:Pfmm5EdWqZCG0dZAJjAinlra3yEpqK5StCblxpbEp6Q=
github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector v0.87.0 h1:0NxGzKHiUFcs8f9o7jpZ9aNuhDBiWXarc0LZK3Z8+j0=
github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector v0.87.0/go.mod h1:ZdIA9LzHiqy+XMN6Fyhwy50TdQd23O3ej7Y1FrU5kdI=
github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector v0.87.0 h1:ArBXfq0KQ89DV9th/MU/snH205Uh6jFCnIiwd/wKp+s=
Expand Down
14 changes: 14 additions & 0 deletions opamp/mocks/mock_opamp_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions opamp/mocks/mock_packages_state_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 20 additions & 12 deletions opamp/observiq/observiq_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ var (
ErrUnsupportedURL = errors.New("unsupported URL")
)

const capabilities = protobufs.AgentCapabilities_AgentCapabilities_ReportsStatus |
protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages |
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses |
protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig |
protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig |
protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig

// Ensure interface is satisfied
var _ opamp.Client = (*Client)(nil)

Expand Down Expand Up @@ -211,6 +218,7 @@ func (c *Client) Connect(ctx context.Context) error {
// SaveRemoteConfigStatusFunc
},
PackagesStateProvider: c.packagesStateProvider,
Capabilities: capabilities,
}

// Start the embedded collector
Expand Down Expand Up @@ -259,7 +267,7 @@ func (c *Client) onConnectHandler() {

collectorPkgStatus := pkgStatuses.Packages[packagestate.CollectorPackageName]
// If we were not installing before the connection, nothing else to do
if collectorPkgStatus.Status != protobufs.PackageStatus_Installing {
if collectorPkgStatus.Status != protobufs.PackageStatusEnum_PackageStatusEnum_Installing {
return
}

Expand Down Expand Up @@ -318,14 +326,14 @@ func (c *Client) onRemoteConfigHandler(ctx context.Context, remoteConfig *protob
changed, err := c.configManager.ApplyConfigChanges(remoteConfig)
remoteCfgStatus := &protobufs.RemoteConfigStatus{
LastRemoteConfigHash: remoteConfig.GetConfigHash(),
Status: protobufs.RemoteConfigStatus_APPLIED,
Status: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLIED,
}

// If we received and error apply it to the config
if err != nil {
c.logger.Error("Failed applying remote config", zap.Error(err))

remoteCfgStatus.Status = protobufs.RemoteConfigStatus_FAILED
remoteCfgStatus.Status = protobufs.RemoteConfigStatuses_RemoteConfigStatuses_FAILED
remoteCfgStatus.ErrorMessage = fmt.Sprintf("Failed to apply config changes: %s", err.Error())
}

Expand Down Expand Up @@ -397,7 +405,7 @@ func (c *Client) onPackagesAvailableHandler(availablePkgs *protobufs.PackagesAva
}

// Start update if applicable
if curPkgStatuses.Packages[packagestate.CollectorPackageName].Status == protobufs.PackageStatus_Installing {
if curPkgStatuses.Packages[packagestate.CollectorPackageName].Status == protobufs.PackageStatusEnum_PackageStatusEnum_Installing {
collectorDownloadableFile := availablePkgs.GetPackages()[packagestate.CollectorPackageName].GetFile()
c.startCollectorPackageInstall(curPkgStatuses, collectorDownloadableFile)
}
Expand All @@ -423,7 +431,7 @@ func (c *Client) buildInitialPackageStatus(pkgName string, availablePkg *protobu
Name: pkgName,
ServerOfferedVersion: availablePkg.GetVersion(),
ServerOfferedHash: availablePkg.GetHash(),
Status: protobufs.PackageStatus_InstallFailed,
Status: protobufs.PackageStatusEnum_PackageStatusEnum_InstallFailed,
ErrorMessage: "Package not supported",
}
}
Expand All @@ -439,7 +447,7 @@ func (c *Client) buildInitialCollectorPackageStatus(pkgName string, availablePkg
AgentHasVersion: version.Version(),
ServerOfferedVersion: availablePkg.GetVersion(),
ServerOfferedHash: availablePkg.GetHash(),
Status: protobufs.PackageStatus_Installed,
Status: protobufs.PackageStatusEnum_PackageStatusEnum_Installed,
}

// If the new version is the same as the current version we are already installed
Expand Down Expand Up @@ -470,7 +478,7 @@ func (c *Client) buildInitialCollectorPackageStatus(pkgName string, availablePkg
c.logger.Info("Packaged update failed because no new version detected",
zap.String("package", pkgName))
initPkgStatus.ErrorMessage = "Packaged update failed because no new version detected"
initPkgStatus.Status = protobufs.PackageStatus_InstallFailed
initPkgStatus.Status = protobufs.PackageStatusEnum_PackageStatusEnum_InstallFailed

return initPkgStatus
}
Expand All @@ -480,12 +488,12 @@ func (c *Client) buildInitialCollectorPackageStatus(pkgName string, availablePkg
c.logger.Info("Packaged update failed because no downloadable file detected",
zap.String("package", pkgName))
initPkgStatus.ErrorMessage = "Packaged update failed because no downloadable file detected"
initPkgStatus.Status = protobufs.PackageStatus_InstallFailed
initPkgStatus.Status = protobufs.PackageStatusEnum_PackageStatusEnum_InstallFailed

return initPkgStatus
}

initPkgStatus.Status = protobufs.PackageStatus_Installing
initPkgStatus.Status = protobufs.PackageStatusEnum_PackageStatusEnum_Installing

return initPkgStatus
}
Expand Down Expand Up @@ -538,7 +546,7 @@ func (c *Client) tryToFailPackageInstall(errMsg string, sendStatusNow bool) {

collectorPackageStatus := pkgStatuses.Packages[packagestate.CollectorPackageName]
// If we were not installing before the connection, nothing else to do
if collectorPackageStatus.Status != protobufs.PackageStatus_Installing {
if collectorPackageStatus.Status != protobufs.PackageStatusEnum_PackageStatusEnum_Installing {
return
}

Expand All @@ -561,7 +569,7 @@ func (c *Client) failPackageInstall(pkgStatuses *protobufs.PackageStatuses, errM
return
}

collectorPkgStatus.Status = protobufs.PackageStatus_InstallFailed
collectorPkgStatus.Status = protobufs.PackageStatusEnum_PackageStatusEnum_InstallFailed
if collectorPkgStatus.ErrorMessage == "" {
collectorPkgStatus.ErrorMessage = errMsg
}
Expand Down Expand Up @@ -599,7 +607,7 @@ func (c *Client) finishPackageInstall(pkgStatuses *protobufs.PackageStatuses) {
return
}

collectorPkgStatus.Status = protobufs.PackageStatus_Installed
collectorPkgStatus.Status = protobufs.PackageStatusEnum_PackageStatusEnum_Installed
collectorPkgStatus.AgentHasVersion = version.Version()
collectorPkgStatus.AgentHasHash = collectorPkgStatus.ServerOfferedHash

Expand Down
Loading

0 comments on commit 570d2d6

Please sign in to comment.