From e0881de6b633920138c799b7b5703a745eedac83 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Wed, 20 Jan 2021 16:18:23 -0500 Subject: [PATCH] [Elastic Agent] Set status Failed if configuration applying fails (#23537) * Set status to Failed if configuration applying fails. * Add changelog. * Don't cleanup paths on crash, as it will be restart. Fix ownership. --- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + .../pkg/core/monitoring/beats/beats_monitor.go | 13 ++++++++----- .../elastic-agent/pkg/core/plugin/process/status.go | 3 --- x-pack/libbeat/management/fleet/manager.go | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index a68ae2d19ca..569341de1b4 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -36,6 +36,7 @@ - Fixed fetching DBus service PID {pull}23496[23496] - Fix issue of missing log messages from filebeat monitor {pull}23514[23514] - Increase checkin grace period to 30 seconds {pull}23568[23568] +- Fix libbeat from reporting back degraded on config update {pull}23537[23537] ==== New features diff --git a/x-pack/elastic-agent/pkg/core/monitoring/beats/beats_monitor.go b/x-pack/elastic-agent/pkg/core/monitoring/beats/beats_monitor.go index 19298aef69c..5944afa4f0c 100644 --- a/x-pack/elastic-agent/pkg/core/monitoring/beats/beats_monitor.go +++ b/x-pack/elastic-agent/pkg/core/monitoring/beats/beats_monitor.go @@ -144,7 +144,12 @@ func (b *Monitor) Cleanup(spec program.Spec, pipelineID string) error { // Prepare executes steps in order for monitoring to work correctly func (b *Monitor) Prepare(spec program.Spec, pipelineID string, uid, gid int) error { - takeOwnership := b.ownLoggingPath(spec) + if !b.ownLoggingPath(spec) { + // spec file passes a log path; so its up to the application to ensure the + // path exists and the write permissions are set so Elastic Agent can read it + return nil + } + drops := []string{b.generateLoggingPath(spec, pipelineID)} if drop := b.monitoringDrop(spec, pipelineID); drop != "" { drops = append(drops, drop) @@ -167,10 +172,8 @@ func (b *Monitor) Prepare(spec program.Spec, pipelineID string, uid, gid int) er } } - if takeOwnership { - if err := changeOwner(drop, uid, gid); err != nil { - return err - } + if err := changeOwner(drop, uid, gid); err != nil { + return err } } diff --git a/x-pack/elastic-agent/pkg/core/plugin/process/status.go b/x-pack/elastic-agent/pkg/core/plugin/process/status.go index eac8f2bc53e..473ae9a70c7 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/process/status.go +++ b/x-pack/elastic-agent/pkg/core/plugin/process/status.go @@ -35,9 +35,6 @@ func (a *Application) OnStatusChange(s *server.ApplicationState, status proto.St return } - // it was a crash, cleanup anything required - go a.cleanUp() - // kill the process if a.state.ProcessInfo != nil { _ = a.state.ProcessInfo.Process.Kill() diff --git a/x-pack/libbeat/management/fleet/manager.go b/x-pack/libbeat/management/fleet/manager.go index dc0185a04ac..8aec0af1800 100644 --- a/x-pack/libbeat/management/fleet/manager.go +++ b/x-pack/libbeat/management/fleet/manager.go @@ -169,7 +169,7 @@ func (cm *Manager) OnConfig(s string) { if errs := cm.apply(blocks); !errs.IsEmpty() { // `cm.apply` already logs the errors; currently allow beat to run degraded - cm.UpdateStatus(management.Degraded, errs.Error()) + cm.UpdateStatus(management.Failed, errs.Error()) return }