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.
- Loading branch information
Showing
8 changed files
with
710 additions
and
0 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
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,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package awsmiddleware | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
type Config struct { | ||
// MiddlewareID is the extension to use to configure the Middleware. | ||
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 _ MiddlewareExtension = (*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,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.