Skip to content

Commit 90219fd

Browse files
[internal/aws/proxy] Migrate from AWS SDK v1 to v2 (#47244)
Migrates internal/aws/proxy from AWS SDK Go v1 to v2. #### Link to tracking issue Fixes #40461 Related: #37728 #### Testing - TestHandlerSignerErrorsOut: PASS - Full internal/aws/proxy test suite: PASS - All 4 affected modules (internal/aws/proxy, internal/aws/awsutil, extension/awsproxy, receiver/awsxrayreceiver): build PASS, tests PASS #### Documentation No documentation changes needed — test-only fix. --------- Co-authored-by: Seongpil Choi <seongpil0948@gmail.com>
1 parent 7d140d1 commit 90219fd

14 files changed

Lines changed: 821 additions & 637 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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. receiver/filelog)
7+
component: internal/aws
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Migrate internal AWS proxy module from AWS SDK Go v1 to v2
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: [40461, 37728]
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+
This removes the dependency on the deprecated `github.com/aws/aws-sdk-go` (v1)
20+
and migrates to `github.com/aws/aws-sdk-go-v2`.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [api]

extension/awsproxy/go.mod

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ require (
1919
)
2020

2121
require (
22-
github.com/aws/aws-sdk-go v1.55.8 // indirect
22+
github.com/aws/aws-sdk-go-v2 v1.41.5 // indirect
23+
github.com/aws/aws-sdk-go-v2/config v1.32.14 // indirect
24+
github.com/aws/aws-sdk-go-v2/credentials v1.19.14 // indirect
25+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 // indirect
26+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 // indirect
27+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 // indirect
28+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect
29+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect
30+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 // indirect
31+
github.com/aws/aws-sdk-go-v2/service/signin v1.0.9 // indirect
32+
github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 // indirect
33+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19 // indirect
34+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.10 // indirect
35+
github.com/aws/smithy-go v1.24.2 // indirect
2336
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2437
github.com/davecgh/go-spew v1.1.1 // indirect
2538
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250903184740-5d135037bd4d // indirect
@@ -31,7 +44,6 @@ require (
3144
github.com/google/go-tpm v0.9.8 // indirect
3245
github.com/google/uuid v1.6.0 // indirect
3346
github.com/hashicorp/go-version v1.9.0 // indirect
34-
github.com/jmespath/go-jmespath v0.4.0 // indirect
3547
github.com/json-iterator/go v1.1.12 // indirect
3648
github.com/knadh/koanf/maps v0.1.2 // indirect
3749
github.com/knadh/koanf/providers/confmap v1.0.0 // indirect
@@ -40,6 +52,7 @@ require (
4052
github.com/mitchellh/reflectwalk v1.0.2 // indirect
4153
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4254
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
55+
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.150.0 // indirect
4356
github.com/pmezard/go-difflib v1.0.0 // indirect
4457
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
4558
go.opentelemetry.io/collector/config/configopaque v1.56.0 // indirect
@@ -54,15 +67,19 @@ require (
5467
go.opentelemetry.io/otel/trace v1.43.0 // indirect
5568
go.uber.org/multierr v1.11.0 // indirect
5669
go.yaml.in/yaml/v3 v3.0.4 // indirect
57-
golang.org/x/crypto v0.48.0 // indirect
58-
golang.org/x/sys v0.42.0 // indirect
70+
golang.org/x/crypto v0.50.0 // indirect
71+
golang.org/x/net v0.53.0 // indirect
72+
golang.org/x/sys v0.43.0 // indirect
73+
golang.org/x/text v0.36.0 // indirect
5974
gopkg.in/yaml.v3 v3.0.1 // indirect
6075
)
6176

6277
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common
6378

6479
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy => ./../../internal/aws/proxy
6580

81+
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil => ../../internal/aws/awsutil
82+
6683
retract (
6784
v0.76.2
6885
v0.76.1

extension/awsproxy/go.sum

Lines changed: 36 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/aws/awsutil/conn.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func newHTTPClient(logger *zap.Logger, maxIdle, requestTimeout int, noVerify boo
3131
InsecureSkipVerify: noVerify,
3232
}
3333

34-
proxyFunc, err := getProxyFunc(proxyAddress)
34+
proxyFunc, err := GetProxyFunc(proxyAddress)
3535
if err != nil {
3636
logger.Error("unable to obtain proxy URL", zap.Error(err))
3737
return nil, err
@@ -56,11 +56,10 @@ func newHTTPClient(logger *zap.Logger, maxIdle, requestTimeout int, noVerify boo
5656
return http, err
5757
}
5858

59-
// getProxyFunc returns an appropriate proxy function for http.Transport.
60-
// When no explicit proxyAddress is configured, it delegates to
61-
// http.ProxyFromEnvironment which correctly respects NO_PROXY.
62-
// When an explicit proxyAddress is configured, it uses http.ProxyURL.
63-
func getProxyFunc(proxyAddress string) (func(*http.Request) (*url.URL, error), error) {
59+
// GetProxyFunc returns a proxy function for use in http.Transport.
60+
// When an explicit proxy address is configured, it returns http.ProxyURL.
61+
// Otherwise, it returns http.ProxyFromEnvironment which respects NO_PROXY.
62+
func GetProxyFunc(proxyAddress string) (func(*http.Request) (*url.URL, error), error) {
6463
if proxyAddress == "" {
6564
return http.ProxyFromEnvironment, nil
6665
}

internal/aws/awsutil/conn_test.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,29 +213,11 @@ func TestProxyIsUsedForNonExcludedHosts(t *testing.T) {
213213
transport, ok := client.Transport.(*http.Transport)
214214
require.True(t, ok)
215215

216-
req, err := http.NewRequest(http.MethodGet, "https://example.com/something", http.NoBody)
217-
require.NoError(t, err)
218-
219-
proxyURL, err := transport.Proxy(req)
220-
assert.NoError(t, err)
221-
assert.NotNil(t, proxyURL)
222-
assert.Equal(t, "http://mitmproxy:8080", proxyURL.String())
223-
}
224-
225-
func TestExplicitProxyAddressStillWorks(t *testing.T) {
226-
t.Setenv("HTTPS_PROXY", "http://env.proxy:8080")
227-
logger := zap.NewNop()
228-
client, err := newHTTPClient(logger, 8, 30, false, "http://explicit.proxy:9090")
229-
require.NoError(t, err)
230-
231-
transport, ok := client.Transport.(*http.Transport)
232-
require.True(t, ok)
233-
234216
req, err := http.NewRequest(http.MethodGet, "https://example.com/", http.NoBody)
235217
require.NoError(t, err)
236218

237219
proxyURL, err := transport.Proxy(req)
238220
assert.NoError(t, err)
239-
assert.NotNil(t, proxyURL)
240-
assert.Equal(t, "http://explicit.proxy:9090", proxyURL.String())
221+
assert.NotNil(t, proxyURL, "Proxy should be used for hosts NOT in NO_PROXY")
222+
assert.Equal(t, "http://mitmproxy:8080", proxyURL.String())
241223
}

0 commit comments

Comments
 (0)