-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/awsmiddleware] Add AWS middleware extension interface (ama…
- Loading branch information
Showing
12 changed files
with
844 additions
and
12 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
include ../../Makefile.Common |
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,29 @@ | ||
# AWS Middleware | ||
|
||
An AWS middleware extension provides request and/or response handlers that can be configured on AWS SDK v1/v2 clients. | ||
Other components can configure their AWS SDK clients using the `awsmiddleware.ConfigureSDKv1` and `awsmiddleware.ConfigureSDKv2` functions. | ||
|
||
The `awsmiddleware.Extension` interface extends `component.Extension` by adding the following methods: | ||
``` | ||
RequestHandlers() []RequestHandler | ||
ResponseHandlers() []ResponseHandler | ||
``` | ||
|
||
The `awsmiddleware.RequestHandler` interface contains the following methods: | ||
``` | ||
ID() string | ||
Position() HandlerPosition | ||
HandleRequest(r *http.Request) | ||
``` | ||
|
||
The `awsmiddleware.ResponseHandler` interface contains the following methods: | ||
``` | ||
ID() string | ||
Position() HandlerPosition | ||
HandleResponse(r *http.Response) | ||
``` | ||
|
||
- `ID` uniquely identifies a handler. Middleware will fail if there is clashing | ||
- `Position` determines whether the handler is appended to the front or back of the existing list. Insertion is done | ||
in the order of the handlers provided. | ||
- `HandleRequest/Response` provides a hook to handle the request/response before and after they've been sent. |
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,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package awsmiddleware // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/awsmiddleware" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
// Config defines the configuration for an AWS Middleware extension. | ||
type Config struct { | ||
// MiddlewareID is the ID of the Middleware extension. | ||
MiddlewareID component.ID `mapstructure:"middleware"` | ||
} | ||
|
||
// GetMiddleware retrieves the extension implementing Middleware based on the MiddlewareID. | ||
func (c Config) GetMiddleware(extensions map[component.ID]component.Component) (Middleware, error) { | ||
if ext, found := extensions[c.MiddlewareID]; found { | ||
if mw, ok := ext.(Middleware); ok { | ||
return mw, nil | ||
} | ||
return nil, errNotMiddleware | ||
} | ||
return nil, fmt.Errorf("failed to resolve AWS client handler %q: %w", c.MiddlewareID, errNotFound) | ||
} |
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,67 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package awsmiddleware | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension/extensiontest" | ||
) | ||
|
||
type testMiddlewareExtension struct { | ||
component.StartFunc | ||
component.ShutdownFunc | ||
requestHandlers []RequestHandler | ||
responseHandlers []ResponseHandler | ||
} | ||
|
||
var _ Extension = (*testMiddlewareExtension)(nil) | ||
|
||
func (t *testMiddlewareExtension) RequestHandlers() []RequestHandler { | ||
return t.requestHandlers | ||
} | ||
|
||
func (t *testMiddlewareExtension) ResponseHandlers() []ResponseHandler { | ||
return t.responseHandlers | ||
} | ||
|
||
func TestGetMiddleware(t *testing.T) { | ||
id := component.NewID("test") | ||
cfg := &Config{MiddlewareID: id} | ||
nopExtension, err := extensiontest.NewNopBuilder().Create(context.Background(), extensiontest.NewNopCreateSettings()) | ||
require.Error(t, err) | ||
testCases := map[string]struct { | ||
extensions map[component.ID]component.Component | ||
wantErr error | ||
}{ | ||
"WithNoExtensions": { | ||
extensions: map[component.ID]component.Component{}, | ||
wantErr: errNotFound, | ||
}, | ||
"WithNonMiddlewareExtension": { | ||
extensions: map[component.ID]component.Component{id: nopExtension}, | ||
wantErr: errNotMiddleware, | ||
}, | ||
"WithMiddlewareExtension": { | ||
extensions: map[component.ID]component.Component{id: &testMiddlewareExtension{}}, | ||
}, | ||
} | ||
for name, testCase := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
got, err := cfg.GetMiddleware(testCase.extensions) | ||
if testCase.wantErr != nil { | ||
assert.Error(t, err) | ||
assert.ErrorIs(t, err, testCase.wantErr) | ||
assert.Nil(t, got) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.NotNil(t, got) | ||
} | ||
}) | ||
} | ||
} |
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,6 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package awsmiddleware defines an extension interface providing request and response handlers that can be | ||
// configured on AWS SDK clients. | ||
package awsmiddleware // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/awsmiddleware" |
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,51 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/extension/awsmiddleware | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.45.24 | ||
github.com/aws/aws-sdk-go-v2 v1.21.1 | ||
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.0 | ||
github.com/aws/smithy-go v1.15.0 | ||
github.com/stretchr/testify v1.8.4 | ||
go.opentelemetry.io/collector/component v0.87.0 | ||
go.opentelemetry.io/collector/extension v0.87.0 | ||
) | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.42 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.36 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.36 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/knadh/koanf/maps v0.1.1 // indirect | ||
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect | ||
github.com/knadh/koanf/v2 v2.0.1 // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
go.opentelemetry.io/collector/config/configtelemetry v0.87.0 // indirect | ||
go.opentelemetry.io/collector/confmap v0.87.0 // indirect | ||
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016 // indirect | ||
go.opentelemetry.io/collector/pdata v1.0.0-rcv0016 // indirect | ||
go.opentelemetry.io/otel v1.19.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.19.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.19.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.26.0 // indirect | ||
golang.org/x/net v0.15.0 // indirect | ||
golang.org/x/sys v0.12.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect | ||
google.golang.org/grpc v1.58.2 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.