From a16a2a3cb7e413c993cb247a121e4fb4c03c43a8 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Mon, 20 Apr 2020 17:16:05 +0200 Subject: [PATCH] [Agent] Fixed injected log path to monitoring beat (#17833) [Agent] Fixed injected log path to monitoring beat (#17833) --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + x-pack/elastic-agent/_meta/common.p2.yml | 2 +- x-pack/elastic-agent/_meta/common.reference.p2.yml | 2 +- x-pack/elastic-agent/_meta/elastic-agent.docker.yml | 2 +- x-pack/elastic-agent/_meta/elastic-agent.yml | 2 +- x-pack/elastic-agent/elastic-agent.docker.yml | 2 +- x-pack/elastic-agent/elastic-agent.reference.yml | 2 +- x-pack/elastic-agent/elastic-agent.yml | 2 +- x-pack/elastic-agent/pkg/agent/operation/monitoring.go | 4 ++++ .../core/plugin/app/monitoring/beats/beats_monitor.go | 10 +++++++--- .../pkg/core/plugin/app/monitoring/beats/monitoring.go | 5 ----- 11 files changed, 19 insertions(+), 15 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index aa84ada1acf4..45ddd69a275c 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -22,6 +22,7 @@ - Fix issues when running `mage package` for all the platforms. {pull}17767[17767] - Remove the kbn-version on each request to the Kibana API. {pull}17764[17764] - Fixed process spawning on Windows {pull}17751[17751] +- Fixed injected log path to monitoring beat {pull}17833[17833] ==== New features diff --git a/x-pack/elastic-agent/_meta/common.p2.yml b/x-pack/elastic-agent/_meta/common.p2.yml index 0ff0776250e4..651f02282dd9 100644 --- a/x-pack/elastic-agent/_meta/common.p2.yml +++ b/x-pack/elastic-agent/_meta/common.p2.yml @@ -112,7 +112,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/_meta/common.reference.p2.yml b/x-pack/elastic-agent/_meta/common.reference.p2.yml index b27d681bfb9a..eaa97536e0bd 100644 --- a/x-pack/elastic-agent/_meta/common.reference.p2.yml +++ b/x-pack/elastic-agent/_meta/common.reference.p2.yml @@ -112,7 +112,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/_meta/elastic-agent.docker.yml b/x-pack/elastic-agent/_meta/elastic-agent.docker.yml index 07dec01f4a10..dbf7931b6906 100644 --- a/x-pack/elastic-agent/_meta/elastic-agent.docker.yml +++ b/x-pack/elastic-agent/_meta/elastic-agent.docker.yml @@ -86,7 +86,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/_meta/elastic-agent.yml b/x-pack/elastic-agent/_meta/elastic-agent.yml index e0f7acc636de..12fbfabc3fec 100644 --- a/x-pack/elastic-agent/_meta/elastic-agent.yml +++ b/x-pack/elastic-agent/_meta/elastic-agent.yml @@ -87,7 +87,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/elastic-agent.docker.yml b/x-pack/elastic-agent/elastic-agent.docker.yml index 07dec01f4a10..dbf7931b6906 100644 --- a/x-pack/elastic-agent/elastic-agent.docker.yml +++ b/x-pack/elastic-agent/elastic-agent.docker.yml @@ -86,7 +86,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/elastic-agent.reference.yml b/x-pack/elastic-agent/elastic-agent.reference.yml index 7b1ee5cca989..2fb40550bc73 100644 --- a/x-pack/elastic-agent/elastic-agent.reference.yml +++ b/x-pack/elastic-agent/elastic-agent.reference.yml @@ -117,7 +117,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/elastic-agent.yml b/x-pack/elastic-agent/elastic-agent.yml index a5fd150155bd..24331ef7f9fa 100644 --- a/x-pack/elastic-agent/elastic-agent.yml +++ b/x-pack/elastic-agent/elastic-agent.yml @@ -117,7 +117,7 @@ retry: # Default is false exponential: false -monitoring: +settings.monitoring: # enabled turns on monitoring of running processes enabled: false # enables log monitoring diff --git a/x-pack/elastic-agent/pkg/agent/operation/monitoring.go b/x-pack/elastic-agent/pkg/agent/operation/monitoring.go index 8157bf9e876d..85b6bb2a8651 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/monitoring.go +++ b/x-pack/elastic-agent/pkg/agent/operation/monitoring.go @@ -225,6 +225,8 @@ func (o *Operator) getMonitoringFilebeatConfig(output interface{}) (map[string]i }, } + o.logger.Debugf("monitoring configuration generated for filebeat: %v", result) + return result, true } @@ -250,6 +252,8 @@ func (o *Operator) getMonitoringMetricbeatConfig(output interface{}) (map[string }, } + o.logger.Debugf("monitoring configuration generated for metricbeat: %v", result) + return result, true } diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go index eda80bf1ffe2..8c245960a0a5 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go @@ -24,6 +24,7 @@ type Monitor struct { process string monitoringEndpoint string loggingPath string + loggingFile string monitorLogs bool monitorMetrics bool @@ -31,13 +32,15 @@ type Monitor struct { // NewMonitor creates a beats monitor. func NewMonitor(process, pipelineID string, downloadConfig *artifact.Config, monitorLogs, monitorMetrics bool) *Monitor { - var monitoringEndpoint, loggingPath string + var monitoringEndpoint, loggingPath, loggingFile string if monitorMetrics { monitoringEndpoint = getMonitoringEndpoint(process, downloadConfig.OS(), pipelineID) } if monitorLogs { - loggingPath = getLoggingFileDirectory(downloadConfig.InstallPath, downloadConfig.OS(), pipelineID) + operatingSystem := downloadConfig.OS() + loggingFile = getLoggingFile(process, operatingSystem, downloadConfig.InstallPath, pipelineID) + loggingPath = filepath.Dir(loggingFile) } return &Monitor{ @@ -45,6 +48,7 @@ func NewMonitor(process, pipelineID string, downloadConfig *artifact.Config, mon process: process, monitoringEndpoint: monitoringEndpoint, loggingPath: loggingPath, + loggingFile: loggingFile, monitorLogs: monitorLogs, monitorMetrics: monitorMetrics, } @@ -125,7 +129,7 @@ func (b *Monitor) LogPath() string { return "" } - return b.loggingPath + return b.loggingFile } // MetricsPath describes a location where application exposes metrics diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go index a69581b3ff95..c551f5ef18cf 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go @@ -6,7 +6,6 @@ package beats import ( "fmt" - "path/filepath" ) const ( @@ -36,7 +35,3 @@ func getLoggingFile(program, operatingSystem, installPath, pipelineID string) st return fmt.Sprintf(logFileFormat, pipelineID, program) } - -func getLoggingFileDirectory(installPath, operatingSystem, pipelineID string) string { - return filepath.Base(getLoggingFile("program", operatingSystem, installPath, pipelineID)) -}