Skip to content

Commit 48a52d0

Browse files
atoulmezeck-ops
authored andcommitted
[processor/resourcedetection] offer to configure the AWS SDK (open-telemetry#37451)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description In some cases, you might need to change the behavior of the AWS metadata client from the [standard retryer](https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-retries-timeouts.html) By default, the client retries 3 times with a max backoff delay of 20s. We offer a limited set of options to override those defaults specifically, such that you can set the client to retry 10 times, for up to 5 minutes, for example: ```yaml processors: resourcedetection/ec2: detectors: ["ec2"] ec2: max_attempts: 10 max_backoff: 5m ``` <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Relates to open-telemetry#35936 <!--Describe what testing was performed and which tests were added.--> #### Testing No testing was performed.
1 parent 8fd81b0 commit 48a52d0

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: resourcedetectionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Expose additional configuration parameters for the AWS metadata client used by the EC2 detector
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35936]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
In some cases, you might need to change the behavior of the AWS metadata client from the [standard retryer](https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-retries-timeouts.html)
20+
21+
By default, the client retries 3 times with a max backoff delay of 20s.
22+
23+
We offer a limited set of options to override those defaults specifically, such that you can set the client to retry 10 times, for up to 5 minutes, for example:
24+
```yaml
25+
processors:
26+
resourcedetection/ec2:
27+
detectors: ["ec2"]
28+
ec2:
29+
max_attempts: 10
30+
max_backoff: 5m
31+
```
32+
33+
# If your change doesn't affect end users or the exported elements of any package,
34+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
35+
# Optional: The change log or logs in which this entry should be included.
36+
# e.g. '[user]' or '[user, api]'
37+
# Include 'user' if the change is relevant to end users.
38+
# Include 'api' if there is a change to a library API.
39+
# Default: '[user]'
40+
change_logs: []

processor/resourcedetectionprocessor/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,20 @@ If you are using a proxy server on your EC2 instance, it's important that you ex
248248

249249
If the instance is part of AWS ParallelCluster and the detector is failing to connect to the metadata server, check the iptable and make sure the chain `PARALLELCLUSTER_IMDS` contains a rule that allows OTEL user to access `169.254.169.254/32`
250250

251+
In some cases, you might need to change the behavior of the AWS metadata client from the [standard retryer](https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-retries-timeouts.html)
252+
253+
By default, the client retries 3 times with a max backoff delay of 20s.
254+
255+
We offer a limited set of options to override those defaults specifically, such that you can set the client to retry 10 times, for up to 5 minutes, for example:
256+
```yaml
257+
processors:
258+
resourcedetection/ec2:
259+
detectors: ["ec2"]
260+
ec2:
261+
max_attempts: 10
262+
max_backoff: 5m
263+
```
264+
251265
### Amazon ECS
252266

253267
Queries the [Task Metadata Endpoint](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html) (TMDE) to record information about the current ECS Task. Only TMDE V4 and V3 are supported.

processor/resourcedetectionprocessor/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func TestLoadConfig(t *testing.T) {
4343
ec2Config.EC2Config = ec2.Config{
4444
Tags: []string{"^tag1$", "^tag2$"},
4545
ResourceAttributes: ec2.CreateDefaultConfig().ResourceAttributes,
46+
MaxAttempts: 3,
47+
MaxBackoff: 20 * time.Second,
4648
}
4749

4850
systemConfig := detectorCreateDefaultConfig()

processor/resourcedetectionprocessor/internal/aws/ec2/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
package ec2 // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ec2"
55

66
import (
7+
"time"
8+
9+
"github.com/aws/aws-sdk-go-v2/aws/retry"
10+
711
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ec2/internal/metadata"
812
)
913

@@ -13,11 +17,15 @@ type Config struct {
1317
// to add as resource attributes to processed data
1418
Tags []string `mapstructure:"tags"`
1519
ResourceAttributes metadata.ResourceAttributesConfig `mapstructure:"resource_attributes"`
20+
MaxAttempts int `mapstructure:"max_attempts"`
21+
MaxBackoff time.Duration `mapstructure:"max_backoff"`
1622
}
1723

1824
func CreateDefaultConfig() Config {
1925
return Config{
2026
Tags: []string{},
2127
ResourceAttributes: metadata.DefaultResourceAttributesConfig(),
28+
MaxAttempts: retry.DefaultMaxAttempts,
29+
MaxBackoff: retry.DefaultMaxBackoff,
2230
}
2331
}

processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"regexp"
1111

1212
"github.com/aws/aws-sdk-go-v2/aws"
13+
"github.com/aws/aws-sdk-go-v2/aws/retry"
1314
"github.com/aws/aws-sdk-go-v2/config"
1415
"github.com/aws/aws-sdk-go-v2/service/ec2"
1516
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
@@ -60,6 +61,12 @@ type Detector struct {
6061
func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal.Detector, error) {
6162
cfg := dcfg.(Config)
6263
awsConfig, err := config.LoadDefaultConfig(context.Background())
64+
awsConfig.Retryer = func() aws.Retryer {
65+
return retry.NewStandard(func(options *retry.StandardOptions) {
66+
options.MaxAttempts = cfg.MaxAttempts
67+
options.MaxBackoff = cfg.MaxBackoff
68+
})
69+
}
6370
if err != nil {
6471
return nil, err
6572
}

0 commit comments

Comments
 (0)