From d1b675baf3f3b9d88158f71930ee94324572e5dd Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Tue, 9 Mar 2021 10:35:32 -0500 Subject: [PATCH] [Elastic Agent] Improve Endpoint installation logging (#24429) (#24439) * Improve logging of exec_file_step. * Add --log stderr to endpoint. * Add changelog. (cherry picked from commit 8efc24cf6606bb9c5372bafe1858e5b1f6019905) --- x-pack/elastic-agent/.gitignore | 3 +- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + x-pack/elastic-agent/magefile.go | 5 +- .../pkg/agent/program/supported.go | 2 +- .../pkg/agent/transpiler/steps.go | 17 ++++- .../pkg/agent/transpiler/steps_test.go | 66 +++++++++++++++++++ .../tests/exec-1.0-darwin-x86_64/main.go | 35 ++++++++++ x-pack/elastic-agent/spec/endpoint.yml | 6 ++ 8 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 x-pack/elastic-agent/pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/main.go diff --git a/x-pack/elastic-agent/.gitignore b/x-pack/elastic-agent/.gitignore index 22e2de50947..81ce70aa69b 100644 --- a/x-pack/elastic-agent/.gitignore +++ b/x-pack/elastic-agent/.gitignore @@ -4,5 +4,6 @@ elastic-agent elastic-agent.dev.yml pkg/agent/operation/tests/scripts/short--1.0.yml pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86/configurable +pkg/agent/operation/tests/scripts/servicable-1.0-darwin-x86/configurable +pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/exec pkg/agent/application/fleet.yml -pkg/core/plugin/operation/tests/scripts/configurable/1.0/configurable diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index 82c49d1f4fb..b0d7b003b6d 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -42,6 +42,7 @@ - Select default agent policy if no enrollment token provided. {pull}23973[23973] - Fix bad substitution of API key. {pull}24036[24036] - Fix docker enrollment issue related to Fleet Server change. {pull}24155[24155] +- Improve log on failure of Endpoint Security installation. {pull}24429[24429] ==== New features diff --git a/x-pack/elastic-agent/magefile.go b/x-pack/elastic-agent/magefile.go index 4d61d4b80ee..25235fef6d3 100644 --- a/x-pack/elastic-agent/magefile.go +++ b/x-pack/elastic-agent/magefile.go @@ -192,16 +192,19 @@ func (Build) Clean() { // TestBinaries build the required binaries for the test suite. func (Build) TestBinaries() error { p := filepath.Join("pkg", "agent", "operation", "tests", "scripts") - + p2 := filepath.Join("pkg", "agent", "transpiler", "tests") configurableName := "configurable" serviceableName := "serviceable" + execName := "exec" if runtime.GOOS == "windows" { configurableName += ".exe" serviceableName += ".exe" + execName += ".exe" } return combineErr( RunGo("build", "-o", filepath.Join(p, "configurable-1.0-darwin-x86_64", configurableName), filepath.Join(p, "configurable-1.0-darwin-x86_64", "main.go")), RunGo("build", "-o", filepath.Join(p, "serviceable-1.0-darwin-x86_64", serviceableName), filepath.Join(p, "serviceable-1.0-darwin-x86_64", "main.go")), + RunGo("build", "-o", filepath.Join(p2, "exec-1.0-darwin-x86_64", execName), filepath.Join(p2, "exec-1.0-darwin-x86_64", "main.go")), ) } diff --git a/x-pack/elastic-agent/pkg/agent/program/supported.go b/x-pack/elastic-agent/pkg/agent/program/supported.go index 85522517c16..cd72ed55bd1 100644 --- a/x-pack/elastic-agent/pkg/agent/program/supported.go +++ b/x-pack/elastic-agent/pkg/agent/program/supported.go @@ -24,7 +24,7 @@ func init() { // spec/heartbeat.yml // spec/metricbeat.yml // spec/packetbeat.yml - unpacked := packer.MustUnpack("eJzMeluXorq69v33M+bttw8cylqLPca6EGsRQIuaYhcJuSOJAhrQ1YKKe+z/vkfCQUCrq7vnHD33RQ2tGHJ48x6e5wn//dvxsKb/GR2yfz+uv57WX/+jyvhv//UbyawCf9nHy8D0FoHHaY45jQ9bApfPDrDOZKVeMXI1jJx5iFwlgjgJ9Ye/5fS6j2HlFP7KOToztwjhJMFaUG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m6Oz6GlgcajBdYDnZTACw62PdHlC65G/zldamz1xLcyf0Ul7732PLjvStX6tljsmFL9ODx7p2IMaUv/iqqolqTxjWWNkjqjuej51zzLEGPLdsW+1mh/tYxSJOW5rQ1cnv+eKeTDuJzXA+7+2Gqzl0Pr7z1wju5U9V6DnWPw9QOQ9eK3+31ONS+xxGZOoPGTb1T0W9QbsTahBZQD0ZhJQFYKDMdBjhV9P9A2gJ/vc9P0q0KtQaqnaNVr9FNDLJBJ2396qz28AvWHfD4Ee/wjoVQyO4A+Z1C9RL1lzVq1Cc72slns1qS+t07/dVVb/JFbzL8FeKsf+33/7vwAAAP//VFro5w==") SupportedMap = make(map[string]Spec) for f, v := range unpacked { diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/steps.go b/x-pack/elastic-agent/pkg/agent/transpiler/steps.go index 3d52ccacb34..7f9d0d9fd7f 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/steps.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/steps.go @@ -253,10 +253,21 @@ func (r *ExecFileStep) Execute(ctx context.Context, rootDir string) error { } if err != nil { exitErr, ok := err.(*exec.ExitError) - if ok && exitErr.Stderr != nil && len(exitErr.Stderr) > 0 { - return fmt.Errorf("operation 'Exec' failed: %s", string(exitErr.Stderr)) + if ok && exitErr.Stderr != nil { + errStr := strings.TrimSpace(string(exitErr.Stderr)) + if len(errStr) > 0 { + return fmt.Errorf("operation 'Exec' failed (return code: %d): %s", exitErr.ExitCode(), errStr) + } + } + exitCode := 1 + if ok { + exitCode = exitErr.ExitCode() + } + outStr := strings.TrimSpace(string(output)) + if len(outStr) == 0 { + outStr = "(command had no output)" } - return fmt.Errorf("operation 'Exec' failed: %s", string(output)) + return fmt.Errorf("operation 'Exec' failed (return code: %d): %s", exitCode, outStr) } return nil } diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/steps_test.go b/x-pack/elastic-agent/pkg/agent/transpiler/steps_test.go index d618b1e1993..7a14e63c00d 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/steps_test.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/steps_test.go @@ -5,7 +5,9 @@ package transpiler import ( + "context" "fmt" + "os" "runtime" "testing" @@ -69,3 +71,67 @@ func TestIsSubpath(t *testing.T) { }) } } + +func TestExecFile_Success(t *testing.T) { + pwd, err := os.Getwd() + if err != nil { + panic(err) + } + binaryPath := "tests/exec-1.0-darwin-x86_64/exec" + step := ExecFile(10, binaryPath, "-output=stdout", "-exitcode=0") + err = step.Execute(context.Background(), pwd) + if err != nil { + t.Fatal("command should not have errored") + } +} + +func TestExecFile_StdErr(t *testing.T) { + pwd, err := os.Getwd() + if err != nil { + panic(err) + } + binaryPath := "tests/exec-1.0-darwin-x86_64/exec" + step := ExecFile(10, binaryPath, "-output=stderr", "-exitcode=15") + err = step.Execute(context.Background(), pwd) + if err == nil { + t.Fatal("command should have errored") + } + errMsg := "operation 'Exec' failed (return code: 15): message written to stderr" + if err.Error() != errMsg { + t.Fatalf("got unexpected error: %s", err) + } +} + +func TestExecFile_StdOut(t *testing.T) { + pwd, err := os.Getwd() + if err != nil { + panic(err) + } + binaryPath := "tests/exec-1.0-darwin-x86_64/exec" + step := ExecFile(10, binaryPath, "-output=stdout", "-exitcode=16") + err = step.Execute(context.Background(), pwd) + if err == nil { + t.Fatal("command should have errored") + } + errMsg := "operation 'Exec' failed (return code: 16): message written to stdout" + if err.Error() != errMsg { + t.Fatalf("got unexpected error: %s", err) + } +} + +func TestExecFile_NoOutput(t *testing.T) { + pwd, err := os.Getwd() + if err != nil { + panic(err) + } + binaryPath := "tests/exec-1.0-darwin-x86_64/exec" + step := ExecFile(10, binaryPath, "-no-output", "-exitcode=17") + err = step.Execute(context.Background(), pwd) + if err == nil { + t.Fatal("command should have errored") + } + errMsg := "operation 'Exec' failed (return code: 17): (command had no output)" + if err.Error() != errMsg { + t.Fatalf("got unexpected error: %s", err) + } +} diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/main.go b/x-pack/elastic-agent/pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/main.go new file mode 100644 index 00000000000..be043c53ac9 --- /dev/null +++ b/x-pack/elastic-agent/pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/main.go @@ -0,0 +1,35 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "flag" + "fmt" + "io" + "os" +) + +func main() { + noOutput := flag.Bool("no-output", false, "disable output") + output := flag.String("output", "stderr", "output destination") + exitcode := flag.Int("exitcode", 0, "exit code") + flag.Parse() + + if *noOutput { + os.Exit(*exitcode) + } + + var dest io.Writer + if *output == "stdout" { + dest = os.Stdout + } else if *output == "stderr" { + dest = os.Stderr + } else { + panic("unknown destination") + } + + fmt.Fprintf(dest, "message written to %s", *output) + os.Exit(*exitcode) +} diff --git a/x-pack/elastic-agent/spec/endpoint.yml b/x-pack/elastic-agent/spec/endpoint.yml index 7265ba2e693..b45a3d35648 100644 --- a/x-pack/elastic-agent/spec/endpoint.yml +++ b/x-pack/elastic-agent/spec/endpoint.yml @@ -11,12 +11,16 @@ check_install: path: "endpoint-security" args: - "verify" + - "--log" + - "stderr" timeout: 30 post_install: - exec_file: path: "endpoint-security" args: - "install" + - "--log" + - "stderr" - "--upgrade" - "--resources" - "endpoint-security-resources.zip" @@ -26,6 +30,8 @@ pre_uninstall: path: "endpoint-security" args: - "uninstall" + - "--log" + - "stderr" timeout: 600 rules: - fix_stream: {}