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

Add beat/process config to elastic agent diagnostics collect #29902

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 @@ -157,3 +157,4 @@
- Allow pprof endpoints for elastic-agent or beats if enabled. {pull}28983[28983] {pull}29155[29155]
- Add --fleet-server-es-ca-trusted-fingerprint flag to allow agent/fleet-server to work with elasticsearch clusters using self signed certs. {pull}29128[29128]
- Discover changes in Kubernetes nodes metadata as soon as they happen. {pull}23139[23139]
- Add results of inspect output command into archive produced by diagnostics collect. {pull}29902[29902]
40 changes: 40 additions & 0 deletions x-pack/elastic-agent/pkg/agent/cmd/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/client"
Expand All @@ -47,6 +48,7 @@ type DiagnosticsInfo struct {
type AgentConfig struct {
ConfigLocal *configuration.Configuration
ConfigRendered map[string]interface{}
AppConfig map[string]interface{} // map of processName_rk:config
}

func newDiagnosticsCommand(s []string, streams *cli.IOStreams) *cobra.Command {
Expand Down Expand Up @@ -361,6 +363,35 @@ func gatherConfig() (AgentConfig, error) {
}
cfg.ConfigRendered = mapCFG

// Gather vars to render process config
isStandalone, err := isStandalone(renderedCFG)
if err != nil {
return AgentConfig{}, err
}

agentInfo, err := info.NewAgentInfo(false)
if err != nil {
return AgentConfig{}, err
}

log, err := newErrorLogger()
if err != nil {
return AgentConfig{}, err
}

// Get process config - uses same approach as inspect output command.
// Does not contact server process to request configs.
pMap, err := getProgramsFromConfig(log, agentInfo, renderedCFG, isStandalone)
if err != nil {
return AgentConfig{}, err
}
cfg.AppConfig = make(map[string]interface{}, 0)
for rk, programs := range pMap {
for _, p := range programs {
cfg.AppConfig[p.Identifier()+"_"+rk] = p.Configuration()
}
}

return cfg, nil
}

Expand Down Expand Up @@ -419,6 +450,15 @@ func createZip(fileName, outputFormat string, diag DiagnosticsInfo, cfg AgentCon
if err := writeFile(zf, outputFormat, cfg.ConfigRendered); err != nil {
return closeHandlers(err, zw, f)
}
for name, appCfg := range cfg.AppConfig {
zf, err := zw.Create("config/" + name + "." + outputFormat)
if err != nil {
return closeHandlers(err, zw, f)
}
if err := writeFile(zf, outputFormat, appCfg); err != nil {
return closeHandlers(err, zw, f)
}
}

if err := zipLogs(zw); err != nil {
return closeHandlers(err, zw, f)
Expand Down