From b0b3fd7e4d1949ef8ada11d225cf35898b253157 Mon Sep 17 00:00:00 2001 From: Lucian Ioan <59661554+lucian-ioan@users.noreply.github.com> Date: Sat, 19 Jul 2025 10:04:18 +0300 Subject: [PATCH] [AWS Health] Improve error message reporting (#45408) * parse error message * remove comment * fix CI * add changelog entry (cherry picked from commit 1637c556c6ec508b10b18015d801de711bdb6ed8) --- CHANGELOG.next.asciidoc | 1 + .../module/aws/awshealth/awshealth.go | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 6c014e7c9995..c14c34fb4a58 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -74,6 +74,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403] - Add check for http error codes in the Metricbeat's Prometheus query submodule {pull}44493[44493] - Sanitize error messages in Fetch method of SQL module {pull}44577[44577] - Add VPN metrics to meraki module {pull}44851[44851] +- Improve error messages in AWS Health {pull}45408[45408] *Osquerybeat* diff --git a/x-pack/metricbeat/module/aws/awshealth/awshealth.go b/x-pack/metricbeat/module/aws/awshealth/awshealth.go index ee6fd42d9022..892039e53dd0 100644 --- a/x-pack/metricbeat/module/aws/awshealth/awshealth.go +++ b/x-pack/metricbeat/module/aws/awshealth/awshealth.go @@ -7,12 +7,14 @@ package awshealth import ( "context" "crypto/fips140" + "errors" "fmt" "time" awssdk "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/health" "github.com/aws/aws-sdk-go-v2/service/health/types" + "github.com/aws/smithy-go" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" "github.com/elastic/beats/v7/metricbeat/mb" @@ -126,7 +128,7 @@ func (m *MetricSet) Fetch(ctx context.Context, report mb.ReporterV2) error { config.AWSConfig.FIPSEnabled = true } - awsConfig := m.MetricSet.AwsConfig.Copy() + awsConfig := m.AwsConfig.Copy() health_client := health.NewFromConfig(awsConfig, func(o *health.Options) { if config.AWSConfig.FIPSEnabled { @@ -200,7 +202,13 @@ func (m *MetricSet) getEventDetails( // Perform actions for the current page currentPage, err := dePage.NextPage(ctx) if err != nil { - m.Logger().Errorf("[AWS Health] DescribeEvents failed with : %w", err) + var opErr *smithy.OperationError + if errors.As(err, &opErr) { + m.Logger().Errorf("[AWS Health] DescribeEvents failed with: Operation=%s, UnderlyingError=%v", + opErr.Operation(), opErr.Err) + } else { + m.Logger().Errorf("[AWS Health] DescribeEvents failed with: %w", err) + } break } deEvents = currentPage.Events @@ -227,7 +235,13 @@ func (m *MetricSet) getEventDetails( Locale: &locale, }) if err != nil { - m.Logger().Errorf("[AWS Health] DescribeEventDetails failed with : %w", err) + var opErr *smithy.OperationError + if errors.As(err, &opErr) { + m.Logger().Errorf("[AWS Health] DescribeEventDetails failed with: Operation=%s, UnderlyingError=%v", + opErr.Operation(), opErr.Err) + } else { + m.Logger().Errorf("[AWS Health] DescribeEventDetails failed with: %w", err) + } break } // Fetch event description for the current page of events