From 52124943a3aa8062c71b86628d70d21f9cee71aa Mon Sep 17 00:00:00 2001 From: Maurizio Branca Date: Mon, 28 Oct 2024 23:22:47 +0100 Subject: [PATCH 1/3] Update input v1 status on start, failure, and stop When I update the input to the Input API v2, I missed the opportunity to report the input status back to the Elastic Agent. --- x-pack/filebeat/input/azureeventhub/v1_input.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/filebeat/input/azureeventhub/v1_input.go b/x-pack/filebeat/input/azureeventhub/v1_input.go index 4736bc3f15a..5ad9a957f9e 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,6 +69,9 @@ 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 { @@ -105,9 +109,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.Stopped, "") return nil } From c6317790b7fd8d48cc56b16acf039020e4e2aa07 Mon Sep 17 00:00:00 2001 From: Maurizio Branca Date: Wed, 6 Nov 2024 23:22:45 +0100 Subject: [PATCH 2/3] Update status in all input lifecycle phases Now also cover the following phases: - pipeline creation - sanitizers creation - input setup --- x-pack/filebeat/input/azureeventhub/v1_input.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/filebeat/input/azureeventhub/v1_input.go b/x-pack/filebeat/input/azureeventhub/v1_input.go index 5ad9a957f9e..c7d97d8603f 100644 --- a/x-pack/filebeat/input/azureeventhub/v1_input.go +++ b/x-pack/filebeat/input/azureeventhub/v1_input.go @@ -75,6 +75,7 @@ func (in *eventHubInputV1) Run( // 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() @@ -86,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) } @@ -102,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 } @@ -113,7 +117,7 @@ func (in *eventHubInputV1) Run( return err } - inputContext.UpdateStatus(status.Stopped, "") + inputContext.UpdateStatus(status.Stopping, "") return nil } From 3fa45d2acf537a2bd2e9e57fecbfe33b17d68eda Mon Sep 17 00:00:00 2001 From: Maurizio Branca Date: Wed, 6 Nov 2024 23:58:02 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 05345fb5ec0..9264f45233b 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -173,6 +173,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*