Skip to content

Commit

Permalink
[Ingest Manager] Change monitoring defaults for agent (elastic#18927) (
Browse files Browse the repository at this point in the history
…elastic#18968)

[Ingest Manager] Change monitoring defaults for agent (elastic#18927)
  • Loading branch information
michalpristas authored Jun 4, 2020
1 parent 218e16c commit d068c98
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 52 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@
- Pick up version from libbeat {pull}18350[18350]
- Use shorter hash for application differentiator {pull}18770[18770]
- When not port are specified and the https is used fallback to 443 {pull}18844[18844]
- Change monitoring defaults for agent {pull}18927[18927]
- Agent verifies packages before using them {pull}18876[18876]
14 changes: 7 additions & 7 deletions x-pack/elastic-agent/_meta/config/common.p2.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ datasources:
- metricset: filesystem
dataset: system.filesystem

settings.monitoring:
# enabled turns on monitoring of running processes
enabled: true
# enables log monitoring
logs: true
# enables metrics monitoring
metrics: true
# settings.monitoring:
# # enabled turns on monitoring of running processes
# enabled: true
# # enables log monitoring
# logs: true
# # enables metrics monitoring
# metrics: true

# management:
# # Mode of management, the Elastic Agent support two modes of operation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ outputs:
ca_sha256: "7lHLiyp4J8m9kw38SJ7SURJP4bXRZv/BNxyyXkCcE/M="

settings.monitoring:
use_output: monitoring
# enabled turns on monitoring of running processes
enabled: true
# enables log monitoring
logs: true
# enables metrics monitoring
metrics: true

# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
Expand Down
14 changes: 7 additions & 7 deletions x-pack/elastic-agent/elastic-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ datasources:
- metricset: filesystem
dataset: system.filesystem

settings.monitoring:
# enabled turns on monitoring of running processes
enabled: true
# enables log monitoring
logs: true
# enables metrics monitoring
metrics: true
# settings.monitoring:
# # enabled turns on monitoring of running processes
# enabled: true
# # enables log monitoring
# logs: true
# # enables metrics monitoring
# metrics: true

# management:
# # Mode of management, the Elastic Agent support two modes of operation:
Expand Down
68 changes: 38 additions & 30 deletions x-pack/elastic-agent/pkg/agent/application/monitoring_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
outputKey = "output"

enabledKey = "settings.monitoring.enabled"
logsKey = "settings.monitoring.logs"
metricsKey = "settings.monitoring.metrics"
outputsKey = "outputs"
elasticsearchKey = "elasticsearch"
typeKey = "type"
Expand All @@ -35,42 +37,48 @@ func injectMonitoring(outputGroup string, rootAst *transpiler.AST, programsToRun
},
}

var config map[string]interface{}
config := make(map[string]interface{})
// if monitoring is not specified use default one where everything is enabled
if _, found := transpiler.Lookup(rootAst, monitoringKey); !found {
config = make(map[string]interface{})
config[enabledKey] = false
} else {
// get monitoring output name to be used
monitoringOutputName := defaultOutputName
useOutputNode, found := transpiler.Lookup(rootAst, monitoringUseOutputKey)
if found {

monitoringOutputNameKey, ok := useOutputNode.Value().(*transpiler.StrVal)
if !ok {
return programsToRun, nil
}

monitoringOutputName = monitoringOutputNameKey.String()
}
monitoringNode := transpiler.NewDict([]transpiler.Node{
transpiler.NewKey("enabled", transpiler.NewBoolVal(true)),
transpiler.NewKey("logs", transpiler.NewBoolVal(true)),
transpiler.NewKey("metrics", transpiler.NewBoolVal(true)),
transpiler.NewKey("use_output", transpiler.NewStrVal("default")),
})

ast := rootAst.Clone()
if err := getMonitoringRule(monitoringOutputName).Apply(ast); err != nil {
return programsToRun, err
}
transpiler.Insert(rootAst, transpiler.NewKey("monitoring", monitoringNode), "settings")
}

config, err = ast.Map()
if err != nil {
return programsToRun, err
// get monitoring output name to be used
monitoringOutputName := defaultOutputName
useOutputNode, found := transpiler.Lookup(rootAst, monitoringUseOutputKey)
if found {
monitoringOutputNameKey, ok := useOutputNode.Value().(*transpiler.StrVal)
if !ok {
return programsToRun, nil
}

programList := make([]string, 0, len(programsToRun))
for _, p := range programsToRun {
programList = append(programList, p.Spec.Cmd)
}
// making program list part of the config
// so it will get regenerated with every change
config[programsKey] = programList
monitoringOutputName = monitoringOutputNameKey.String()
}

ast := rootAst.Clone()
if err := getMonitoringRule(monitoringOutputName).Apply(ast); err != nil {
return programsToRun, err
}

config, err = ast.Map()
if err != nil {
return programsToRun, err
}

programList := make([]string, 0, len(programsToRun))
for _, p := range programsToRun {
programList = append(programList, p.Spec.Cmd)
}
// making program list part of the config
// so it will get regenerated with every change
config[programsKey] = programList

monitoringProgram.Config, err = transpiler.NewAST(config)
if err != nil {
Expand Down
Loading

0 comments on commit d068c98

Please sign in to comment.