From 7190dc358bd1abadd9f9c39a8432080294621662 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Fri, 27 Sep 2024 12:09:53 +0200 Subject: [PATCH 01/11] [extensions/opamp] enable ReportsHealth capability Signed-off-by: Florian Bacher --- extension/opampextension/config.go | 5 ++++ extension/opampextension/factory.go | 1 + extension/opampextension/opamp_agent.go | 32 ++++++++++++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/extension/opampextension/config.go b/extension/opampextension/config.go index 202bfdbb6d8a..3b9cbbed619c 100644 --- a/extension/opampextension/config.go +++ b/extension/opampextension/config.go @@ -53,6 +53,8 @@ type AgentDescription struct { type Capabilities struct { // ReportsEffectiveConfig enables the OpAMP ReportsEffectiveConfig Capability. (default: true) ReportsEffectiveConfig bool `mapstructure:"reports_effective_config"` + // ReportsHealth enables the OpAMP ReportsHealth Capability. (default: true) + ReportsHealth bool `mapstructure:"reports_health"` } func (caps Capabilities) toAgentCapabilities() protobufs.AgentCapabilities { @@ -62,6 +64,9 @@ func (caps Capabilities) toAgentCapabilities() protobufs.AgentCapabilities { if caps.ReportsEffectiveConfig { agentCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig } + if caps.ReportsHealth { + agentCapabilities |= protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth + } return agentCapabilities } diff --git a/extension/opampextension/factory.go b/extension/opampextension/factory.go index ea4ea23a22d6..868c3bc85c65 100644 --- a/extension/opampextension/factory.go +++ b/extension/opampextension/factory.go @@ -27,6 +27,7 @@ func createDefaultConfig() component.Config { Server: &OpAMPServer{}, Capabilities: Capabilities{ ReportsEffectiveConfig: true, + ReportsHealth: true, }, PPIDPollInterval: 5 * time.Second, } diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index c481c2cc396e..a466be6488f1 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -7,13 +7,6 @@ import ( "context" "errors" "fmt" - "net/http" - "os" - "runtime" - "sort" - "strings" - "sync" - "github.com/google/uuid" "github.com/oklog/ulid/v2" "github.com/open-telemetry/opamp-go/client" @@ -27,6 +20,12 @@ import ( "go.uber.org/zap" "golang.org/x/exp/maps" "gopkg.in/yaml.v3" + "net/http" + "os" + "runtime" + "sort" + "strings" + "sync" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages" ) @@ -112,6 +111,10 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { return err } + if err := o.opampClient.SetHealth(&protobufs.ComponentHealth{Healthy: false}); err != nil { + o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) + } + o.logger.Debug("Starting OpAMP client...") if err := o.opampClient.Start(context.Background(), settings); err != nil { @@ -120,6 +123,10 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { o.logger.Debug("OpAMP client started") + if err := o.opampClient.SetHealth(&protobufs.ComponentHealth{Healthy: true}); err != nil { + o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) + } + return nil } @@ -132,8 +139,17 @@ func (o *opampAgent) Shutdown(ctx context.Context) error { if o.opampClient == nil { return nil } + err := o.opampClient.SetHealth( + &protobufs.ComponentHealth{ + Healthy: false, LastError: "Agent is shut down", + }, + ) + + if err != nil { + o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) + } o.logger.Debug("Stopping OpAMP client...") - err := o.opampClient.Stop(ctx) + err = o.opampClient.Stop(ctx) // Opamp-go considers this an error, but the collector does not. // https://github.com/open-telemetry/opamp-go/issues/255 if err != nil && strings.EqualFold(err.Error(), "cannot stop because not started") { From a79f094bf5fd04fa0802d631ed129744e87bef72 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 10:39:40 +0200 Subject: [PATCH 02/11] adapt unit tests Signed-off-by: Florian Bacher --- extension/opampextension/config_test.go | 2 ++ extension/opampextension/opamp_agent.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/extension/opampextension/config_test.go b/extension/opampextension/config_test.go index bbccff4d91aa..ca0b6e823760 100644 --- a/extension/opampextension/config_test.go +++ b/extension/opampextension/config_test.go @@ -39,6 +39,7 @@ func TestUnmarshalConfig(t *testing.T) { InstanceUID: "01BX5ZZKBKACTAV9WEVGEMMVRZ", Capabilities: Capabilities{ ReportsEffectiveConfig: true, + ReportsHealth: true, }, PPIDPollInterval: 5 * time.Second, }, cfg) @@ -63,6 +64,7 @@ func TestUnmarshalHttpConfig(t *testing.T) { InstanceUID: "01BX5ZZKBKACTAV9WEVGEMMVRZ", Capabilities: Capabilities{ ReportsEffectiveConfig: true, + ReportsHealth: true, }, PPIDPollInterval: 5 * time.Second, }, cfg) diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index a466be6488f1..4934bd6a6525 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -139,15 +139,16 @@ func (o *opampAgent) Shutdown(ctx context.Context) error { if o.opampClient == nil { return nil } + err := o.opampClient.SetHealth( &protobufs.ComponentHealth{ Healthy: false, LastError: "Agent is shut down", }, ) - if err != nil { o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) } + o.logger.Debug("Stopping OpAMP client...") err = o.opampClient.Stop(ctx) // Opamp-go considers this an error, but the collector does not. From 5ae81e742bdae9c754717cae02c47e3f21c492bd Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 10:43:07 +0200 Subject: [PATCH 03/11] add changelog entry Signed-off-by: Florian Bacher --- .chloggen/opamp-extension-reportshealth.yaml | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/opamp-extension-reportshealth.yaml diff --git a/.chloggen/opamp-extension-reportshealth.yaml b/.chloggen/opamp-extension-reportshealth.yaml new file mode 100644 index 000000000000..c58f185a6628 --- /dev/null +++ b/.chloggen/opamp-extension-reportshealth.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: opampextension + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Implement `ReportsHealth` capability in OpAMP extension + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35433] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From aa18e72ec388272776fbb5a241ab744982a1aaba Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 10:53:21 +0200 Subject: [PATCH 04/11] add unit test for conversion to protobuf Capability Signed-off-by: Florian Bacher --- extension/opampextension/config_test.go | 39 ++++++++++++++++++++ extension/opampextension/opamp_agent_test.go | 1 + 2 files changed, 40 insertions(+) diff --git a/extension/opampextension/config_test.go b/extension/opampextension/config_test.go index ca0b6e823760..6b0b9e5acc67 100644 --- a/extension/opampextension/config_test.go +++ b/extension/opampextension/config_test.go @@ -4,6 +4,7 @@ package opampextension import ( + "github.com/open-telemetry/opamp-go/protobufs" "path/filepath" "testing" "time" @@ -288,3 +289,41 @@ func TestConfig_Validate(t *testing.T) { }) } } + +func TestCapabilities_toAgentCapabilities(t *testing.T) { + type fields struct { + ReportsEffectiveConfig bool + ReportsHealth bool + } + tests := []struct { + name string + fields fields + want protobufs.AgentCapabilities + }{ + { + name: "default capabilities", + fields: fields{ + ReportsEffectiveConfig: false, + ReportsHealth: false, + }, + want: protobufs.AgentCapabilities_AgentCapabilities_ReportsStatus, + }, + { + name: "all supported capabilities enabled", + fields: fields{ + ReportsEffectiveConfig: true, + ReportsHealth: true, + }, + want: protobufs.AgentCapabilities_AgentCapabilities_ReportsStatus | protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig | protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + caps := Capabilities{ + ReportsEffectiveConfig: tt.fields.ReportsEffectiveConfig, + ReportsHealth: tt.fields.ReportsHealth, + } + assert.Equalf(t, tt.want, caps.toAgentCapabilities(), "toAgentCapabilities()") + }) + } +} diff --git a/extension/opampextension/opamp_agent_test.go b/extension/opampextension/opamp_agent_test.go index e500b6c800ec..2e02e5ef32c9 100644 --- a/extension/opampextension/opamp_agent_test.go +++ b/extension/opampextension/opamp_agent_test.go @@ -31,6 +31,7 @@ func TestNewOpampAgent(t *testing.T) { assert.Equal(t, "test version", o.agentVersion) assert.NotEmpty(t, o.instanceID.String()) assert.True(t, o.capabilities.ReportsEffectiveConfig) + assert.True(t, o.capabilities.ReportsHealth) assert.Empty(t, o.effectiveConfig) assert.Nil(t, o.agentDescription) } From bbd4f03e179143e4a41b3e1d39ba450773cbed98 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 11:01:03 +0200 Subject: [PATCH 05/11] only report health if capability is enabled Signed-off-by: Florian Bacher --- extension/opampextension/opamp_agent.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index 4934bd6a6525..f55e959909a0 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -111,7 +111,7 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { return err } - if err := o.opampClient.SetHealth(&protobufs.ComponentHealth{Healthy: false}); err != nil { + if err := o.setHealth(&protobufs.ComponentHealth{Healthy: false}); err != nil { o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) } @@ -123,7 +123,7 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { o.logger.Debug("OpAMP client started") - if err := o.opampClient.SetHealth(&protobufs.ComponentHealth{Healthy: true}); err != nil { + if err := o.setHealth(&protobufs.ComponentHealth{Healthy: true}); err != nil { o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) } @@ -140,7 +140,7 @@ func (o *opampAgent) Shutdown(ctx context.Context) error { return nil } - err := o.opampClient.SetHealth( + err := o.setHealth( &protobufs.ComponentHealth{ Healthy: false, LastError: "Agent is shut down", }, @@ -337,3 +337,10 @@ func (o *opampAgent) onMessage(_ context.Context, msg *types.MessageData) { o.customCapabilityRegistry.ProcessMessage(msg.CustomMessage) } } + +func (o *opampAgent) setHealth(ch *protobufs.ComponentHealth) error { + if o.capabilities.ReportsHealth && o.opampClient != nil { + return o.opampClient.SetHealth(ch) + } + return nil +} From f85c3a5b9f4c75c475545caae59934ea292c33cf Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 11:15:58 +0200 Subject: [PATCH 06/11] appease linter Signed-off-by: Florian Bacher --- extension/opampextension/opamp_agent.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index f55e959909a0..7127835291ff 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -7,6 +7,13 @@ import ( "context" "errors" "fmt" + "net/http" + "os" + "runtime" + "sort" + "strings" + "sync" + "github.com/google/uuid" "github.com/oklog/ulid/v2" "github.com/open-telemetry/opamp-go/client" @@ -20,12 +27,6 @@ import ( "go.uber.org/zap" "golang.org/x/exp/maps" "gopkg.in/yaml.v3" - "net/http" - "os" - "runtime" - "sort" - "strings" - "sync" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages" ) From 4233fd6f759c7499667c5da53f4e29d5a3d9535e Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 11:31:15 +0200 Subject: [PATCH 07/11] appease linter Signed-off-by: Florian Bacher --- extension/opampextension/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/opampextension/config_test.go b/extension/opampextension/config_test.go index 6b0b9e5acc67..7f50970f3184 100644 --- a/extension/opampextension/config_test.go +++ b/extension/opampextension/config_test.go @@ -4,11 +4,11 @@ package opampextension import ( - "github.com/open-telemetry/opamp-go/protobufs" "path/filepath" "testing" "time" + "github.com/open-telemetry/opamp-go/protobufs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/config/configopaque" From 44fa2fba6d72cc5e42c98673508a3767ef9b1e63 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 30 Sep 2024 12:32:43 +0200 Subject: [PATCH 08/11] add ReportsHealth capability to the readme Signed-off-by: Florian Bacher --- extension/opampextension/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/extension/opampextension/README.md b/extension/opampextension/README.md index b12f1869d949..7bdf11eb8aec 100644 --- a/extension/opampextension/README.md +++ b/extension/opampextension/README.md @@ -41,6 +41,7 @@ The following settings are optional for both transports: instance UID remains constant across process restarts. - `capabilities`: Keys with boolean true/false values that enable a particular OpAMP capability. - `reports_effective_config`: Whether to enable the OpAMP ReportsEffectiveConfig capability. Default is `true`. + - `reports_health`: Whether to enable the OpAMP ReportsHealth capability. Default is `true`. - `agent_description`: Setting that modifies the agent description reported to the OpAMP server. - `non_identifying_attributes`: A map of key value pairs that will be added to the [non-identifying attributes](https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes) reported to the OpAMP server. If an attribute collides with the default non-identifying attributes that are automatically added, the ones specified here take precedence. - `ppid`: An optional process ID to monitor. When this process is no longer running, the extension will emit a fatal error, causing the collector to exit. This is meant to be set by the Supervisor or some other parent process, and should not be configured manually. From 6d1514f12f3f08ab55eea039a6cbff36ddd02661 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Tue, 8 Oct 2024 13:14:24 +0200 Subject: [PATCH 09/11] use pipeline watcher interface for receiving health information Signed-off-by: Florian Bacher --- extension/opampextension/go.mod | 9 +++++---- extension/opampextension/go.sum | 18 +++++++++-------- extension/opampextension/opamp_agent.go | 26 ++++++++++++------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/extension/opampextension/go.mod b/extension/opampextension/go.mod index 681bf8af6dd2..9b673fc0fce9 100644 --- a/extension/opampextension/go.mod +++ b/extension/opampextension/go.mod @@ -15,6 +15,7 @@ require ( go.opentelemetry.io/collector/config/configtls v1.16.0 go.opentelemetry.io/collector/confmap v1.16.0 go.opentelemetry.io/collector/extension v0.110.0 + go.opentelemetry.io/collector/extension/extensioncapabilities v0.110.0 go.opentelemetry.io/collector/semconv v0.110.0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 @@ -45,9 +46,9 @@ require ( github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/numcpus v0.8.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect - go.opentelemetry.io/collector/config/configtelemetry v0.110.0 // indirect + go.opentelemetry.io/collector/config/configtelemetry v0.111.0 // indirect go.opentelemetry.io/collector/internal/globalsignal v0.110.0 // indirect - go.opentelemetry.io/collector/pdata v1.16.0 // indirect + go.opentelemetry.io/collector/pdata v1.17.0 // indirect go.opentelemetry.io/collector/pipeline v0.110.0 // indirect go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect @@ -58,8 +59,8 @@ require ( golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.17.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/grpc v1.66.2 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + google.golang.org/grpc v1.67.1 // indirect google.golang.org/protobuf v1.34.2 // indirect ) diff --git a/extension/opampextension/go.sum b/extension/opampextension/go.sum index d4fe448ec6f8..d925f1bff456 100644 --- a/extension/opampextension/go.sum +++ b/extension/opampextension/go.sum @@ -73,18 +73,20 @@ go.opentelemetry.io/collector/component/componentstatus v0.110.0 h1:j+Fg88CgxmiC go.opentelemetry.io/collector/component/componentstatus v0.110.0/go.mod h1:UI3vOkwnI6JkRYxuWCrrlJe45ywTdlew426r4Wy4gH4= go.opentelemetry.io/collector/config/configopaque v1.16.0 h1:83cVlPL151kHWrHLUAkdfwvnhp68x0XPxEkSBSfEapE= go.opentelemetry.io/collector/config/configopaque v1.16.0/go.mod h1:6zlLIyOoRpJJ+0bEKrlZOZon3rOp5Jrz9fMdR4twOS4= -go.opentelemetry.io/collector/config/configtelemetry v0.110.0 h1:V8Y/Xv7TJpnNGHLrheRKrMydcKBxWYAZ+dj71Kllyos= -go.opentelemetry.io/collector/config/configtelemetry v0.110.0/go.mod h1:R0MBUxjSMVMIhljuDHWIygzzJWQyZHXXWIgQNxcFwhc= +go.opentelemetry.io/collector/config/configtelemetry v0.111.0 h1:Q3TJRM2A3FIDjIvzWa3uFArsdFN0I/0GzcWynHjC+oY= +go.opentelemetry.io/collector/config/configtelemetry v0.111.0/go.mod h1:R0MBUxjSMVMIhljuDHWIygzzJWQyZHXXWIgQNxcFwhc= go.opentelemetry.io/collector/config/configtls v1.16.0 h1:seh/0Ph5Nkk8mdpG80o8+ExUvzdryB2UftyhnXLxv68= go.opentelemetry.io/collector/config/configtls v1.16.0/go.mod h1:PrIG1ZamLBLdn880ud6FHv5C4/aEEVr+jPnxwdLdKeg= go.opentelemetry.io/collector/confmap v1.16.0 h1:0bWw/XSosX6xoE1sGsaD3glzRtSxanrF4sgib3jAYr4= go.opentelemetry.io/collector/confmap v1.16.0/go.mod h1:GrIZ12P/9DPOuTpe2PIS51a0P/ZM6iKtByVee1Uf3+k= go.opentelemetry.io/collector/extension v0.110.0 h1:AYFk57W25f7xOo3I6pV0rWNWVtOLZsW+lzFCctnvCkU= go.opentelemetry.io/collector/extension v0.110.0/go.mod h1:zD/pw9o83SFyn/DCbBdBcH0eUPyGtYgpMSAOqotFYRc= +go.opentelemetry.io/collector/extension/extensioncapabilities v0.110.0 h1:VVqGHUh1A5ljEoQVeMCMUs1i7oLMKRQRpLCAim4WwpU= +go.opentelemetry.io/collector/extension/extensioncapabilities v0.110.0/go.mod h1:0T/UKqU5t5mUI3CkZfbyzsbEUbmMmmYUswDOsianqGg= go.opentelemetry.io/collector/internal/globalsignal v0.110.0 h1:S6bfFEiek8vJeXAbciWS7W8UR6ZrVJB3ftNyFTMHQaY= go.opentelemetry.io/collector/internal/globalsignal v0.110.0/go.mod h1:GqMXodPWOxK5uqpX8MaMXC2389y2XJTa5nPwf8FYDK8= -go.opentelemetry.io/collector/pdata v1.16.0 h1:g02K8jlRnmQ7TQDuXpdgVL6vIxIVqr5Gbb1qIR27rto= -go.opentelemetry.io/collector/pdata v1.16.0/go.mod h1:YZZJIt2ehxosYf/Y1pbvexjNWsIGNNrzzlCTO9jC1F4= +go.opentelemetry.io/collector/pdata v1.17.0 h1:z8cjjT2FThAehWu5fbF48OnZyK5q8xd1UhC4XszDo0w= +go.opentelemetry.io/collector/pdata v1.17.0/go.mod h1:yZaQ9KZAm/qie96LTygRKxOXMq0/54h8OW7330ycuvQ= go.opentelemetry.io/collector/pipeline v0.110.0 h1:nArQj8lt2R6ajbbmZ0f7JqkzAzvIOSwxsxDEv9HGKHw= go.opentelemetry.io/collector/pipeline v0.110.0/go.mod h1:qWk90kohDYBgI/1Kw4DQaQU82+y9GJY8MDse7H2JTWg= go.opentelemetry.io/collector/semconv v0.110.0 h1:KHQnOHe3gUz0zsxe8ph9kN5OTypCFD4V+06AiBTfeNk= @@ -140,10 +142,10 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= -google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= -google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index 7127835291ff..7cda68cedea4 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/collector/extension/extensioncapabilities" semconv "go.opentelemetry.io/collector/semconv/v1.27.0" "go.uber.org/zap" "golang.org/x/exp/maps" @@ -31,6 +32,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages" ) +var _ extensioncapabilities.PipelineWatcher = (*opampAgent)(nil) + type opampAgent struct { cfg *Config logger *zap.Logger @@ -124,10 +127,6 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { o.logger.Debug("OpAMP client started") - if err := o.setHealth(&protobufs.ComponentHealth{Healthy: true}); err != nil { - o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) - } - return nil } @@ -141,17 +140,8 @@ func (o *opampAgent) Shutdown(ctx context.Context) error { return nil } - err := o.setHealth( - &protobufs.ComponentHealth{ - Healthy: false, LastError: "Agent is shut down", - }, - ) - if err != nil { - o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) - } - o.logger.Debug("Stopping OpAMP client...") - err = o.opampClient.Stop(ctx) + err := o.opampClient.Stop(ctx) // Opamp-go considers this an error, but the collector does not. // https://github.com/open-telemetry/opamp-go/issues/255 if err != nil && strings.EqualFold(err.Error(), "cannot stop because not started") { @@ -172,6 +162,14 @@ func (o *opampAgent) Register(capability string, opts ...opampcustommessages.Cus return o.customCapabilityRegistry.Register(capability, opts...) } +func (o *opampAgent) Ready() error { + return o.setHealth(&protobufs.ComponentHealth{Healthy: true}) +} + +func (o *opampAgent) NotReady() error { + return o.setHealth(&protobufs.ComponentHealth{Healthy: false}) +} + func (o *opampAgent) updateEffectiveConfig(conf *confmap.Conf) { o.eclk.Lock() defer o.eclk.Unlock() From 4f8f5aca2fabd511946715e90aafcc23cf2025a7 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Tue, 8 Oct 2024 13:39:59 +0200 Subject: [PATCH 10/11] resolve merge conflicts Signed-off-by: Florian Bacher --- extension/opampextension/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extension/opampextension/go.sum b/extension/opampextension/go.sum index a2db421b5cd3..ee23f6e0a797 100644 --- a/extension/opampextension/go.sum +++ b/extension/opampextension/go.sum @@ -79,6 +79,8 @@ go.opentelemetry.io/collector/confmap v1.17.0 h1:5UKHtPGtzNGaOGBsJ6aFpvsKElNUXOV go.opentelemetry.io/collector/confmap v1.17.0/go.mod h1:GrIZ12P/9DPOuTpe2PIS51a0P/ZM6iKtByVee1Uf3+k= go.opentelemetry.io/collector/extension v0.111.0 h1:oagGQS3k6Etnm5N5OEkfIWrX4/77t/ZP+B0xfTPUVm8= go.opentelemetry.io/collector/extension v0.111.0/go.mod h1:ELCpDNpS2qb/31Z8pCMmqTkzfnUV3CanQZMwLW+GCMI= +go.opentelemetry.io/collector/extension/extensioncapabilities v0.111.0 h1:Ps2/2TUbAkxgZu1YxSxDweZDLJx5x7CyNKCINZkLFtY= +go.opentelemetry.io/collector/extension/extensioncapabilities v0.111.0/go.mod h1:q4kBSWsOX62hAp7si+Y0Y0ZXWyCpXjiRuWWz7IL/MDI= go.opentelemetry.io/collector/internal/globalsignal v0.111.0 h1:oq0nSD+7K2Q1Fx5d3s6lPRdKZeTL0FEg4sIaR7ZJzIc= go.opentelemetry.io/collector/internal/globalsignal v0.111.0/go.mod h1:GqMXodPWOxK5uqpX8MaMXC2389y2XJTa5nPwf8FYDK8= go.opentelemetry.io/collector/pdata v1.17.0 h1:z8cjjT2FThAehWu5fbF48OnZyK5q8xd1UhC4XszDo0w= From 88ffe2e2266998eff7dc584e21a6e36346b66515 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 9 Oct 2024 07:06:28 +0200 Subject: [PATCH 11/11] do not return error in case of failed SetHealth calls Signed-off-by: Florian Bacher --- extension/opampextension/opamp_agent.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index 7cda68cedea4..0bdb369da99e 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -115,9 +115,7 @@ func (o *opampAgent) Start(ctx context.Context, host component.Host) error { return err } - if err := o.setHealth(&protobufs.ComponentHealth{Healthy: false}); err != nil { - o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) - } + o.setHealth(&protobufs.ComponentHealth{Healthy: false}) o.logger.Debug("Starting OpAMP client...") @@ -163,11 +161,13 @@ func (o *opampAgent) Register(capability string, opts ...opampcustommessages.Cus } func (o *opampAgent) Ready() error { - return o.setHealth(&protobufs.ComponentHealth{Healthy: true}) + o.setHealth(&protobufs.ComponentHealth{Healthy: true}) + return nil } func (o *opampAgent) NotReady() error { - return o.setHealth(&protobufs.ComponentHealth{Healthy: false}) + o.setHealth(&protobufs.ComponentHealth{Healthy: false}) + return nil } func (o *opampAgent) updateEffectiveConfig(conf *confmap.Conf) { @@ -337,9 +337,10 @@ func (o *opampAgent) onMessage(_ context.Context, msg *types.MessageData) { } } -func (o *opampAgent) setHealth(ch *protobufs.ComponentHealth) error { +func (o *opampAgent) setHealth(ch *protobufs.ComponentHealth) { if o.capabilities.ReportsHealth && o.opampClient != nil { - return o.opampClient.SetHealth(ch) + if err := o.opampClient.SetHealth(ch); err != nil { + o.logger.Error("Could not report health to OpAMP server", zap.Error(err)) + } } - return nil }