forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/opamp]: Add mechanism to detect whether the collector has …
…been orphaned (open-telemetry#32564) **Description:** <Describe what has changed.> * Allows the process to monitor a passed in ppid, which should be the parent process ID for the collector. When the parent process ID exits, the extension emits a fatal error event, which triggers a collector shutdown. **Link to tracking Issue:** This is part of open-telemetry#32189 - It does not resolve this issue because the supervisor still needs changes to pass the its PID in. **Testing:** Added some unit tests. I've manually tested it on my macbook with this PR: observIQ#4715 (running supervisor, kill -9 the supervisor, and take a look at the agent logs to see it shut down). I've tried testing this out on Windows, but the supervisor doesn't get past bootstrapping (the Commander's Stop function does not work on windows), so I wasn't able to fully test it. **Documentation:** Added new parameter to README
- Loading branch information
1 parent
95749ce
commit 4d7aba9
Showing
13 changed files
with
254 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: opampextension | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add a new `ppid` parameter that can be used to enable orphan detection for the supervisor. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [32189] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package opampextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/shirou/gopsutil/v3/process" | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
// monitorPPID polls for the existence of ppid. | ||
// If the specified ppid no longer exists, a fatal error event is reported via the passed in reportStatus function. | ||
func monitorPPID(ctx context.Context, interval time.Duration, ppid int32, reportStatus func(*component.StatusEvent)) { | ||
for { | ||
exists, err := process.PidExistsWithContext(ctx, ppid) | ||
if err != nil { | ||
statusErr := fmt.Errorf("collector was orphaned, failed to find process with pid %d: %w", ppid, err) | ||
status := component.NewFatalErrorEvent(statusErr) | ||
reportStatus(status) | ||
return | ||
} | ||
|
||
if !exists { | ||
statusErr := fmt.Errorf("collector was orphaned, process with pid %d does not exist", ppid) | ||
status := component.NewFatalErrorEvent(statusErr) | ||
reportStatus(status) | ||
return | ||
} | ||
|
||
select { | ||
case <-time.After(interval): // OK; Poll again to make sure PID exists | ||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
} |
Oops, something went wrong.