Skip to content

Commit b0b3fd7

Browse files
lucian-ioanmergify[bot]
authored andcommitted
[AWS Health] Improve error message reporting (#45408)
* parse error message * remove comment * fix CI * add changelog entry (cherry picked from commit 1637c55)
1 parent a629a31 commit b0b3fd7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403]
7474
- Add check for http error codes in the Metricbeat's Prometheus query submodule {pull}44493[44493]
7575
- Sanitize error messages in Fetch method of SQL module {pull}44577[44577]
7676
- Add VPN metrics to meraki module {pull}44851[44851]
77+
- Improve error messages in AWS Health {pull}45408[45408]
7778

7879
*Osquerybeat*
7980

x-pack/metricbeat/module/aws/awshealth/awshealth.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ package awshealth
77
import (
88
"context"
99
"crypto/fips140"
10+
"errors"
1011
"fmt"
1112
"time"
1213

1314
awssdk "github.com/aws/aws-sdk-go-v2/aws"
1415
"github.com/aws/aws-sdk-go-v2/service/health"
1516
"github.com/aws/aws-sdk-go-v2/service/health/types"
17+
"github.com/aws/smithy-go"
1618

1719
"github.com/elastic/beats/v7/libbeat/common/cfgwarn"
1820
"github.com/elastic/beats/v7/metricbeat/mb"
@@ -126,7 +128,7 @@ func (m *MetricSet) Fetch(ctx context.Context, report mb.ReporterV2) error {
126128
config.AWSConfig.FIPSEnabled = true
127129
}
128130

129-
awsConfig := m.MetricSet.AwsConfig.Copy()
131+
awsConfig := m.AwsConfig.Copy()
130132

131133
health_client := health.NewFromConfig(awsConfig, func(o *health.Options) {
132134
if config.AWSConfig.FIPSEnabled {
@@ -200,7 +202,13 @@ func (m *MetricSet) getEventDetails(
200202
// Perform actions for the current page
201203
currentPage, err := dePage.NextPage(ctx)
202204
if err != nil {
203-
m.Logger().Errorf("[AWS Health] DescribeEvents failed with : %w", err)
205+
var opErr *smithy.OperationError
206+
if errors.As(err, &opErr) {
207+
m.Logger().Errorf("[AWS Health] DescribeEvents failed with: Operation=%s, UnderlyingError=%v",
208+
opErr.Operation(), opErr.Err)
209+
} else {
210+
m.Logger().Errorf("[AWS Health] DescribeEvents failed with: %w", err)
211+
}
204212
break
205213
}
206214
deEvents = currentPage.Events
@@ -227,7 +235,13 @@ func (m *MetricSet) getEventDetails(
227235
Locale: &locale,
228236
})
229237
if err != nil {
230-
m.Logger().Errorf("[AWS Health] DescribeEventDetails failed with : %w", err)
238+
var opErr *smithy.OperationError
239+
if errors.As(err, &opErr) {
240+
m.Logger().Errorf("[AWS Health] DescribeEventDetails failed with: Operation=%s, UnderlyingError=%v",
241+
opErr.Operation(), opErr.Err)
242+
} else {
243+
m.Logger().Errorf("[AWS Health] DescribeEventDetails failed with: %w", err)
244+
}
231245
break
232246
}
233247
// Fetch event description for the current page of events

0 commit comments

Comments
 (0)