forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/awsmiddleware] Change Configure to take in either SDK vers…
…ion (#133)
- Loading branch information
Showing
9 changed files
with
128 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package awsmiddleware | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zaptest/observer" | ||
) | ||
|
||
func TestTryConfigure(t *testing.T) { | ||
testCases := []SDKVersion{SDKv1(&request.Handlers{}), SDKv2(&aws.Config{})} | ||
for _, testCase := range testCases { | ||
id := component.NewID("test") | ||
host := new(MockExtensionsHost) | ||
host.On("GetExtensions").Return(nil).Once() | ||
core, observed := observer.New(zap.DebugLevel) | ||
logger := zap.New(core) | ||
TryConfigure(logger, host, id, testCase) | ||
require.Len(t, observed.FilterLevelExact(zap.ErrorLevel).TakeAll(), 1) | ||
|
||
extensions := map[component.ID]component.Component{} | ||
host.On("GetExtensions").Return(extensions) | ||
handler := new(MockHandler) | ||
handler.On("ID").Return("test") | ||
handler.On("Position").Return(HandlerPosition(-1)) | ||
extension := new(MockMiddlewareExtension) | ||
extension.On("Handlers").Return([]RequestHandler{handler}, nil).Once() | ||
extensions[id] = extension | ||
TryConfigure(logger, host, id, testCase) | ||
require.Len(t, observed.FilterLevelExact(zap.WarnLevel).TakeAll(), 1) | ||
|
||
extension.On("Handlers").Return(nil, nil).Once() | ||
TryConfigure(logger, host, id, testCase) | ||
require.Len(t, observed.FilterLevelExact(zap.DebugLevel).TakeAll(), 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package awsmiddleware | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
) | ||
|
||
type SDKVersion interface { | ||
unused() | ||
} | ||
|
||
type sdkVersion1 struct { | ||
SDKVersion | ||
handlers *request.Handlers | ||
} | ||
|
||
// SDKv1 takes in AWS SDKv1 client request handlers. | ||
func SDKv1(handlers *request.Handlers) SDKVersion { | ||
return sdkVersion1{handlers: handlers} | ||
} | ||
|
||
type sdkVersion2 struct { | ||
SDKVersion | ||
cfg *aws.Config | ||
} | ||
|
||
// SDKv2 takes in an AWS SDKv2 config. | ||
func SDKv2(cfg *aws.Config) SDKVersion { | ||
return sdkVersion2{cfg: cfg} | ||
} |