-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add diagnostics collect command to elastic-agent. #28461
Add diagnostics collect command to elastic-agent. #28461
Conversation
Add diagnostics collect command to elastic-agent. This option will create an archieve with information that can help with debugging the elastic-agent. The information includes process metadata (same as the output of elastic-agent diagnostics), config information, the rendered policy, and any local log files.
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
return err | ||
} | ||
|
||
// using Data() + "/logs", for some reason default paths/Logs() is the home dir... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused as to why path.Logs()
returned <path>
instead of <path>/data/logs
(as I expected), anyone have insight into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logPath defaults to topPath which is what you see if no override is provided x-pack/elastic-agent/pkg/agent/application/paths/common.go:L40
if fErr != nil { | ||
return fmt.Errorf("unable to walk log dir: %w", fErr) | ||
} | ||
name := strings.TrimPrefix(path, logPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
in this case gives the name of the directory/file within log/
to write into the archive. For exampledefault/filebeat-json.log
} | ||
zw := zip.NewWriter(f) | ||
|
||
zf, err := zw.Create("meta/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the docs for zip indicate that ending a name with a slash creates a directory.
@@ -147,4 +147,5 @@ | |||
- Support ephemeral containers in Kubernetes dynamic provider. {issue}27020[#27020] {pull}27707[27707] | |||
- Add complete k8s metadata through composable provider. {pull}27691[27691] | |||
- Add diagnostics command to gather beat metadata. {pull}28265[28265] | |||
- Add diagnostics collect command to gather beat metadata, config, policy, and logs and bundle it into an archieve. {pull}28461[28461] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/archieve/archive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, please take a look at these small issues i raised and test on windows to check processing of path separator
return closeHandlers(err, zw, f) | ||
} | ||
|
||
zf, err = zw.Create("meta/elastic-agent-version." + outputFormat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested on windows as well? i'm wondering because of /
vs \
as a path separator.
same thing all over this file
// using Data() + "/logs", for some reason default paths/Logs() is the home dir... | ||
logPath := filepath.Join(paths.Data(), "logs") + string(filepath.Separator) | ||
return filepath.WalkDir(logPath, func(path string, d fs.DirEntry, fErr error) error { | ||
if fErr != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's hande IsNotExist(err) and continue without processing if so. i've had issues with Walk before and this is not serious but can break the process
return nil | ||
} | ||
|
||
lf, err := os.Open(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not closed, better to extract to a func and use defer to close the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, just added closeHandlers to my exit points
|
||
// writeFile writes json or yaml data from the interface to the writer. | ||
func writeFile(w io.Writer, outputFormat string, v interface{}) error { | ||
if outputFormat == "yaml" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not serious at all but we default to yaml when using a command, we could also use json here if specified and default to yaml as well
fix typos, handle file not exist errors, close open file handles for logs after copying, writeFile will default to yaml instead of json behaviour.
I've tested on windows now and found and fixed an issue with the archive file name (Windows does not allow Currently the command runs and creates an archive, however it's not able to collect logs (on Windows). |
Home should point to versioned home directory |
/test |
/package |
Add diagnostics collect command to elastic-agent. Add diagnostics collect command to elastic-agent. This option will create an archieve with information that can help with debugging the elastic-agent. The information includes process metadata (same as the output of elastic-agent diagnostics), config information, the rendered policy, and any local log files. (cherry picked from commit 99ebf3e)
Add diagnostics collect command to elastic-agent. Add diagnostics collect command to elastic-agent. This option will create an archieve with information that can help with debugging the elastic-agent. The information includes process metadata (same as the output of elastic-agent diagnostics), config information, the rendered policy, and any local log files. (cherry picked from commit 99ebf3e) Co-authored-by: Michel Laterman <[email protected]>
Add diagnostics collect command to elastic-agent. Add diagnostics collect command to elastic-agent. This option will create an archieve with information that can help with debugging the elastic-agent. The information includes process metadata (same as the output of elastic-agent diagnostics), config information, the rendered policy, and any local log files.
Add diagnostics collect command to elastic-agent. Add diagnostics collect command to elastic-agent. This option will create an archieve with information that can help with debugging the elastic-agent. The information includes process metadata (same as the output of elastic-agent diagnostics), config information, the rendered policy, and any local log files. (cherry picked from commit 99ebf3e)
What does this PR do?
Add diagnostics collect command to elastic-agent. This option will
create an archive with information that can help with debugging the
elastic-agent. The information includes process metadata (same as the
output of elastic-agent diagnostics), config information, the rendered
policy, and any local log files.
Why is it important?
This command can be used by support to help when debugging issues with the elastic-agent.
Note that it currently DOES NOT redact any credentials, so if it used by a customer, they will need to manually edit the files in the archive to redact credentials.
Contents (config, policies, and metadata) may be written in json or yaml (specified by a flag, default yaml). The archive will have the following structure:
Checklist
I have made corresponding change to the default configuration filesI have added tests that prove my fix is effective or that my feature worksCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
Run the agent normally, then run
elastic-agent diagnostics collect
.Related issues