Skip to content

Commit

Permalink
Add beat/process config to elastic agent diagnostics collect (#29902)
Browse files Browse the repository at this point in the history
* Add beat/process config to elastic agent diagnostics collect

Add the configs that are output from elastic-agent inspect output to the
bundle generated by elastic-agent diagnostics collect. Files are named
as ProcID_RouteKey.

* Apply suggestions from code review

Co-authored-by: Anderson Queiroz <contato@andersonq.eti.br>

Co-authored-by: Anderson Queiroz <contato@andersonq.eti.br>
  • Loading branch information
michel-laterman and AndersonQ authored Jan 20, 2022
1 parent 96e393f commit 53c7c51
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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

0 comments on commit 53c7c51

Please sign in to comment.