Skip to content

Commit

Permalink
[cmd/opampsupervisor]: Configure the ppid option in the opamp exten…
Browse files Browse the repository at this point in the history
…sion (#32875)

**Description:** <Describe what has changed.>
* Configures the PPID of the opamp extension in the supervisor. This
allows the collector to detect if the supervisor exits and shut itself
down.

**Link to tracking Issue:** Closes #32189

**Testing:** <Describe what testing was performed and which tests were
added.>
* Manually tested by starting the supervisor, then kill -9'ing the
supervisor. The collector previously would have still been running, but
now shuts itself down. Doing this you can also see the following log:
```
2024-05-06T14:52:31.010-0400	error	[email protected]/collector.go:278	Asynchronous error received, terminating process	{"error": "collector was orphaned, process with pid 38908 does not exist"}
```

**Documentation:** <Describe the documentation added.>
Added `orphan_detection_interval` to the spec as a configurable option

---------

Co-authored-by: Tiffany Hrabusa <[email protected]>
Co-authored-by: Andrzej Stencel <[email protected]>
  • Loading branch information
3 people authored May 16, 2024
1 parent d78d7bb commit e783923
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .chloggen/feat_opamp-supervisor-specify-ppid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: cmd/opampsupervisor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The OpAMP supervisor now configures the `ppid` parameter of the opamp extension, which allows the collector to shut down if the supervisor is no longer running.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32189]
3 changes: 3 additions & 0 deletions cmd/opampsupervisor/specification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ agent:
# Path to Collector executable. Required.
executable: /opt/otelcol/bin/otelcol

# The interval on which the Collector checks to see if it's been orphaned.
orphan_detection_interval: 5s

# Extra command line flags to pass to the Collector executable.
args:

Expand Down
6 changes: 4 additions & 2 deletions cmd/opampsupervisor/supervisor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"runtime"
"time"

"go.opentelemetry.io/collector/config/configtls"
)
Expand Down Expand Up @@ -66,8 +67,9 @@ type OpAMPServer struct {
}

type Agent struct {
Executable string
Description AgentDescription `mapstructure:"description"`
Executable string
OrphanDetectionInterval time.Duration `mapstructure:"orphan_detection_interval"`
Description AgentDescription `mapstructure:"description"`
}

type AgentDescription struct {
Expand Down
11 changes: 9 additions & 2 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,16 @@ func (s *Supervisor) getBootstrapInfo() (err error) {

var cfg bytes.Buffer

orphanPollInterval := 5 * time.Second
if s.config.Agent != nil && s.config.Agent.OrphanDetectionInterval > 0 {
orphanPollInterval = s.config.Agent.OrphanDetectionInterval
}

err = s.bootstrapTemplate.Execute(&cfg, map[string]any{
"InstanceUid": s.persistentState.InstanceID.String(),
"SupervisorPort": supervisorPort,
"InstanceUid": s.persistentState.InstanceID.String(),
"SupervisorPort": supervisorPort,
"PID": os.Getpid(),
"PPIDPollInterval": orphanPollInterval,
})
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/opampsupervisor/supervisor/templates/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extensions:
endpoint: "ws://localhost:{{.SupervisorPort}}/v1/opamp"
tls:
insecure: true
ppid: {{.PID}}
ppid_poll_interval: {{.PPIDPollInterval}}

service:
pipelines:
Expand Down

0 comments on commit e783923

Please sign in to comment.