From d85c854f9e9852699d2d0e0a91c9521b8b1fed38 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 7 Nov 2024 07:42:37 +0100 Subject: [PATCH] [azure-eventhub] Update input v1 status on start, failure, and stop (#41469) (#41547) 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 882c854681a71613516d14cbebb2398db16523ff) Co-authored-by: Maurizio Branca --- CHANGELOG.next.asciidoc | 1 + x-pack/filebeat/input/azureeventhub/v1_input.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 497dd79ded18..182ac0e2d42e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -175,6 +175,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Journald input now can read events from all boots {issue}41083[41083] {pull}41244[41244] - Fix double encoding of client_secret in the Entity Analytics input's Azure Active Directory provider {pull}41393[41393] - Fix errors in SQS host resolution in the `aws-s3` input when using custom (non-AWS) endpoints. {pull}41504[41504] +- The azure-eventhub input now correctly reports its status to the Elastic Agent on fatal errors {pull}41469[41469] *Heartbeat* diff --git a/x-pack/filebeat/input/azureeventhub/v1_input.go b/x-pack/filebeat/input/azureeventhub/v1_input.go index 4736bc3f15a3..c7d97d8603fa 100644 --- a/x-pack/filebeat/input/azureeventhub/v1_input.go +++ b/x-pack/filebeat/input/azureeventhub/v1_input.go @@ -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" ) @@ -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() @@ -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) } @@ -98,6 +104,8 @@ 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 } @@ -105,9 +113,11 @@ func (in *eventHubInputV1) Run( 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 }