Skip to content
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

[Elastic-Agent] Do not use unversioned home with watcher binary path #25423

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- Reduce log level for listener cleanup to debug {pull}25274[25274]
- Delay the restart of application when a status report of failure is given {pull}25339[25339]
- Don't log when upgrade capability doesn't apply {pull}25386[25386]
- Fixed issue when unversioned home is set and invoked watcher failing with ENOENT {issue}25371[25371]

==== New features

Expand Down
11 changes: 6 additions & 5 deletions x-pack/elastic-agent/pkg/agent/application/paths/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Home() string {
if unversionedHome {
return topPath
}
return versionedHome(topPath)
return VersionedHome(topPath)
}

// IsVersionHome returns true if the Home path is versioned based on build.
Expand Down Expand Up @@ -134,6 +134,11 @@ func SetLogs(path string) {
logsPath = path
}

// VersionedHome returns a versioned path based on a TopPath and used commit.
func VersionedHome(base string) string {
return filepath.Join(base, "data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
}

// initialTop returns the initial top-level path for the binary
//
// When nested in top-level/data/elastic-agent-${hash}/ the result is top-level/.
Expand Down Expand Up @@ -163,7 +168,3 @@ func insideData(exePath string) bool {
expectedPath := filepath.Join("data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
return strings.HasSuffix(exePath, expectedPath)
}

func versionedHome(base string) string {
return filepath.Join(base, "data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func InvokeWatcher(log *logger.Logger) error {
return nil
}

cmd := invokeCmd()
versionedHome := paths.VersionedHome(paths.Top())
cmd := invokeCmd(versionedHome)
defer func() {
if cmd.Process != nil {
log.Debugf("releasing watcher %v", cmd.Process.Pid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ func (p *noopPidProvider) Name() string { return "noop" }

func (p *noopPidProvider) PID(ctx context.Context) (int, error) { return 0, nil }

func invokeCmd() *exec.Cmd {
homeExePath := filepath.Join(paths.Home(), agentName)
func invokeCmd(topPath string) *exec.Cmd {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw the name topPath in the past? What does it exactly mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the structure we have topPath is the top of agent directory structure e.g. /etc/Elastic/Agent
we also use a homePath which points to a home of a certain agent version e.g /etc/Elastic/Agent/data/elastic-agent-abc123/

homeExePath := filepath.Join(topPath, agentName)

cmd := exec.Command(homeExePath, watcherSubcommand,
"--path.config", paths.Config(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (p *darwinPidProvider) piderFromCmd(ctx context.Context, name string, args
}
}

func invokeCmd() *exec.Cmd {
homeExePath := filepath.Join(paths.Home(), agentName)
func invokeCmd(topPath string) *exec.Cmd {
homeExePath := filepath.Join(topPath, agentName)

cmd := exec.Command(homeExePath, watcherSubcommand,
"--path.config", paths.Config(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (p *pidProvider) PID(ctx context.Context) (int, error) {
return int(status.ProcessId), nil
}

func invokeCmd() *exec.Cmd {
homeExePath := filepath.Join(paths.Home(), agentName)
func invokeCmd(topPath string) *exec.Cmd {
homeExePath := filepath.Join(topPath, agentName)

cmd := exec.Command(homeExePath, watcherSubcommand,
"--path.config", paths.Config(),
Expand Down