Skip to content

Commit

Permalink
[8.15](backport #41469) [azure-eventhub] Update input v1 status on st…
Browse files Browse the repository at this point in the history
…art, failure, and stop (#41545)

* [azure-eventhub] Update input v1 status on start, failure, and stop (#41469)

Update the Elastic Agent status by calling `inputContext.UpdateStatus(status.Failed, err.Error())` during the main input lifecycle phases (set up and run). If any setup, startup, and run steps fail, the input reports the fatal issue before shutting down.

Without reporting the fatal error, the input logs the error and stops, but users continue to see it as "healthy" in Fleet, causing confusion and making troubleshooting much harder.

(cherry picked from commit 882c854)

* Drop unintentional changelog entries

---------

Co-authored-by: Maurizio Branca <maurizio.branca@elastic.co>
  • Loading branch information
mergify[bot] and zmoog authored Nov 7, 2024
1 parent aef85fe commit bb01339
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Log bad handshake details when websocket connection fails {pull}41300[41300]
- Improve modification time handling for entities and entity deletion logic in the Active Directory entityanalytics input. {pull}41179[41179]
- Fix double encoding of client_secret in the Entity Analytics input's Azure Active Directory provider {pull}41393[41393]
- The azure-eventhub input now correctly reports its status to the Elastic Agent on fatal errors {pull}41469[41469]

*Heartbeat*

Expand Down
10 changes: 10 additions & 0 deletions x-pack/filebeat/input/azureeventhub/v1_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
v2 "github.com/elastic/beats/v7/filebeat/input/v2"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common/acker"
"github.com/elastic/beats/v7/libbeat/management/status"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"
)
Expand Down Expand Up @@ -68,9 +69,13 @@ func (in *eventHubInputV1) Run(
) error {
var err error

// Update the status to starting
inputContext.UpdateStatus(status.Starting, "")

// Create pipelineClient for publishing events.
in.pipelineClient, err = createPipelineClient(pipeline)
if err != nil {
inputContext.UpdateStatus(status.Failed, err.Error())
return fmt.Errorf("failed to create pipeline pipelineClient: %w", err)
}
defer in.pipelineClient.Close()
Expand All @@ -82,6 +87,7 @@ func (in *eventHubInputV1) Run(
// Set up new and legacy sanitizers, if any.
sanitizers, err := newSanitizers(in.config.Sanitizers, in.config.LegacySanitizeOptions)
if err != nil {
inputContext.UpdateStatus(status.Failed, err.Error())
return fmt.Errorf("failed to create sanitizers: %w", err)
}

Expand All @@ -98,16 +104,20 @@ func (in *eventHubInputV1) Run(
// in preparation for the main run loop.
err = in.setup(ctx)
if err != nil {
in.log.Errorw("error setting up input", "error", err)
inputContext.UpdateStatus(status.Failed, err.Error())
return err
}

// Start the main run loop
err = in.run(ctx)
if err != nil {
in.log.Errorw("error running input", "error", err)
inputContext.UpdateStatus(status.Failed, err.Error())
return err
}

inputContext.UpdateStatus(status.Stopping, "")
return nil
}

Expand Down

0 comments on commit bb01339

Please sign in to comment.