Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension/awsmiddleware] Add AWS middleware extension interface #116

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ exporter/tencentcloudlogserviceexporter/ @open-telemetry/collect
exporter/zipkinexporter/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @astencel-sumo @crobert-1

extension/asapauthextension/ @open-telemetry/collector-contrib-approvers @jamesmoessis @MovieStoreGuy
extension/awsmiddleware @open-telemetry/collector-contrib-approvers @jefchien
adam-mateen marked this conversation as resolved.
Show resolved Hide resolved
extension/awsproxy/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @mxiamxia
extension/basicauthextension/ @open-telemetry/collector-contrib-approvers @jpkrohling @svrakitin @frzifus
extension/bearertokenauthextension/ @open-telemetry/collector-contrib-approvers @jpkrohling @pavankrish123 @frzifus
Expand Down
24 changes: 12 additions & 12 deletions exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,22 +1456,22 @@ func TestGroupedMetricToCWMeasurementsWithFilters(t *testing.T) {
MetricNameSelectors: []string{"metric(1|3)"},
},
}, []cWMeasurement{
{
Namespace: namespace,
Dimensions: [][]string{{}},
Metrics: []map[string]string{
{
"Name": "metric1",
"Unit": "Count",
},
{
"Name": "metric3",
"Unit": "Seconds",
{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't previously formatted, which was breaking the linting validation.

Namespace: namespace,
Dimensions: [][]string{{}},
Metrics: []map[string]string{
{
"Name": "metric1",
"Unit": "Count",
},
{
"Name": "metric3",
"Unit": "Seconds",
},
},
},
},
},
},
{
"label matchers",
[]*MetricDeclaration{
Expand Down
1 change: 1 addition & 0 deletions extension/awsmiddleware/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
27 changes: 27 additions & 0 deletions extension/awsmiddleware/config.go
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"
)

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)
}
67 changes: 67 additions & 0 deletions extension/awsmiddleware/config_test.go
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)
}
})
}
}
6 changes: 6 additions & 0 deletions extension/awsmiddleware/doc.go
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"
51 changes: 51 additions & 0 deletions extension/awsmiddleware/go.mod
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
)
Loading
Loading