Skip to content

Commit

Permalink
[Elastic Agent] Set status Failed if configuration applying fails (#2…
Browse files Browse the repository at this point in the history
…3537) (#23601)

* Set status to Failed if configuration applying fails.

* Add changelog.

* Don't cleanup paths on crash, as it will be restart. Fix ownership.

(cherry picked from commit e0881de)
  • Loading branch information
blakerouse authored Jan 21, 2021
1 parent aa57166 commit e5001fe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 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 @@ -35,6 +35,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

Expand Down
13 changes: 8 additions & 5 deletions x-pack/elastic-agent/pkg/core/monitoring/beats/beats_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}

Expand Down
3 changes: 0 additions & 3 deletions x-pack/elastic-agent/pkg/core/plugin/process/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion x-pack/libbeat/management/fleet/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit e5001fe

Please sign in to comment.