From 5dcbb545f0d56239a25876817c6bb0cdc0345ee5 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 16 Dec 2024 20:45:45 +0100 Subject: [PATCH] resolving comments --- cmd/otelcontribcol/go.mod | 2 +- go.mod | 2 +- internal/metadataproviders/aws/ec2/metadata.go | 4 ++-- processor/resourcedetectionprocessor/go.mod | 4 +++- processor/resourcedetectionprocessor/go.sum | 1 + .../resourcedetectionprocessor/internal/aws/ec2/ec2.go | 4 ++-- .../internal/resourcedetection.go | 10 ++++------ .../internal/resourcedetection_test.go | 6 +++--- receiver/awscontainerinsightreceiver/go.mod | 3 ++- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/cmd/otelcontribcol/go.mod b/cmd/otelcontribcol/go.mod index 2b906580717a..c67ec148d683 100644 --- a/cmd/otelcontribcol/go.mod +++ b/cmd/otelcontribcol/go.mod @@ -370,7 +370,7 @@ require ( github.com/alecthomas/participle/v2 v2.1.1 // indirect github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect github.com/aliyun/aliyun-log-go-sdk v0.1.76 // indirect - github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20241204155332-be45e31638de // indirect + github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20240419190856-2f880467f335 // indirect github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws v0.0.0-20240415183253-230331014d2c // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/apache/arrow/go/v15 v15.0.0 // indirect diff --git a/go.mod b/go.mod index efb89260881e..6ef036a1d2e9 100644 --- a/go.mod +++ b/go.mod @@ -329,7 +329,7 @@ require ( github.com/alecthomas/participle/v2 v2.1.1 // indirect github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect github.com/aliyun/aliyun-log-go-sdk v0.1.76 // indirect - github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20241204155332-be45e31638de // indirect + github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20240419190856-2f880467f335 // indirect github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws v0.0.0-20240415183253-230331014d2c // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/apache/arrow/go/v15 v15.0.0 // indirect diff --git a/internal/metadataproviders/aws/ec2/metadata.go b/internal/metadataproviders/aws/ec2/metadata.go index ee7101130669..509069a68d86 100644 --- a/internal/metadataproviders/aws/ec2/metadata.go +++ b/internal/metadataproviders/aws/ec2/metadata.go @@ -16,7 +16,7 @@ import ( type Provider interface { Get(ctx context.Context) (ec2metadata.EC2InstanceIdentityDocument, error) - GetHandlers(ctx context.Context) *request.Handlers + GetHandlers() *request.Handlers Hostname(ctx context.Context) (string, error) InstanceID(ctx context.Context) (string, error) } @@ -62,6 +62,6 @@ func (c *metadataClient) Get(_ context.Context) (ec2metadata.EC2InstanceIdentity return c.metadataFallbackEnable.GetInstanceIdentityDocument() } -func (c *metadataClient) GetHandlers(_ context.Context) *request.Handlers { +func (c *metadataClient) GetHandlers() *request.Handlers { return &c.metadata.Handlers } diff --git a/processor/resourcedetectionprocessor/go.mod b/processor/resourcedetectionprocessor/go.mod index 739a56085011..a151435823d5 100644 --- a/processor/resourcedetectionprocessor/go.mod +++ b/processor/resourcedetectionprocessor/go.mod @@ -5,7 +5,7 @@ go 1.22.5 require ( cloud.google.com/go/compute/metadata v0.3.0 github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.23.0 - github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20241204155332-be45e31638de + github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20240419190856-2f880467f335 github.com/aws/aws-sdk-go v1.53.11 github.com/google/go-cmp v0.6.0 github.com/hashicorp/consul/api v1.29.1 @@ -171,3 +171,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sco replace github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api v0.0.0-20180801171038-322a19404e37 replace github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws => ../../override/aws + +replace github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware => ../../extension/awsmiddleware \ No newline at end of file diff --git a/processor/resourcedetectionprocessor/go.sum b/processor/resourcedetectionprocessor/go.sum index df14bb8d759c..b5ae315416c4 100644 --- a/processor/resourcedetectionprocessor/go.sum +++ b/processor/resourcedetectionprocessor/go.sum @@ -48,6 +48,7 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20240419190856-2f880467f335/go.mod h1:5JOe6ISApVHBIsZuLb8ppaY06ujDcHCxYJE5wCymNoI= github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20241204155332-be45e31638de h1:GC8FheDVk0E2TYsJt9U/Qid68rWQ4bbRBcJxa/cQ5sM= github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20241204155332-be45e31638de/go.mod h1:/RaNSxxO06niapGT00snMdgFfjjjW/kV3TZGX8kHuwM= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= diff --git a/processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go b/processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go index a1e531116dd0..696cdaee32cf 100644 --- a/processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go +++ b/processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go @@ -124,8 +124,8 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem return res, conventions.SchemaURL, nil } -func (d *Detector) ExposeHandlers(ctx context.Context) (handlers *request.Handlers) { - return d.metadataProvider.GetHandlers(ctx) +func (d *Detector) ExposeHandlers() (handlers *request.Handlers) { + return d.metadataProvider.GetHandlers() } func getClientConfig(ctx context.Context, logger *zap.Logger) *http.Client { diff --git a/processor/resourcedetectionprocessor/internal/resourcedetection.go b/processor/resourcedetectionprocessor/internal/resourcedetection.go index 84d6479c8b9d..4d3500026651 100644 --- a/processor/resourcedetectionprocessor/internal/resourcedetection.go +++ b/processor/resourcedetectionprocessor/internal/resourcedetection.go @@ -27,9 +27,8 @@ type Detector interface { Detect(ctx context.Context) (resource pcommon.Resource, schemaURL string, err error) } -type ExposeHandlerDetector interface { - Detector // Embed the existing Detector interface - ExposeHandlers(ctx context.Context) *request.Handlers +type HandlerProvider interface { + ExposeHandlers() *request.Handlers } type DetectorConfig any @@ -126,8 +125,8 @@ func (p *ResourceProvider) Get(ctx context.Context, client *http.Client) (resour func (p *ResourceProvider) ConfigureHandlers(ctx context.Context, host component.Host, middlewareId component.ID) { for _, detector := range p.detectors { - if handlerDetector, ok := detector.(ExposeHandlerDetector); ok { - awsmiddleware.TryConfigure(p.logger, host, middlewareId, awsmiddleware.SDKv1(handlerDetector.ExposeHandlers(ctx))) + if handlerDetector, ok := detector.(HandlerProvider); ok { + awsmiddleware.TryConfigure(p.logger, host, middlewareId, awsmiddleware.SDKv1(handlerDetector.ExposeHandlers())) } } } @@ -212,4 +211,3 @@ func MergeResource(to, from pcommon.Resource, overrideTo bool) { func IsEmptyResource(res pcommon.Resource) bool { return res.Attributes().Len() == 0 } - diff --git a/processor/resourcedetectionprocessor/internal/resourcedetection_test.go b/processor/resourcedetectionprocessor/internal/resourcedetection_test.go index 3fffdefe82aa..57907c97de27 100644 --- a/processor/resourcedetectionprocessor/internal/resourcedetection_test.go +++ b/processor/resourcedetectionprocessor/internal/resourcedetection_test.go @@ -320,7 +320,7 @@ func TestFilterAttributes_NoAttributes(t *testing.T) { assert.Equal(t, len(droppedAttributes), 0) } -// mockDetectorWithHandler is a mock detector that implements ExposeHandlerDetector +// mockDetectorWithHandler is a mock detector that implements HandlerProvider type mockDetectorWithHandler struct { handlersCalled bool } @@ -329,7 +329,7 @@ func (m *mockDetectorWithHandler) Detect(ctx context.Context) (resource pcommon. return pcommon.NewResource(), "", nil } -func (m *mockDetectorWithHandler) ExposeHandlers(ctx context.Context) *request.Handlers { +func (m *mockDetectorWithHandler) ExposeHandlers() *request.Handlers { m.handlersCalled = true return &request.Handlers{} } @@ -352,7 +352,7 @@ type mockHost struct { extensions map[component.ID]component.Component } -// mockDetector is a basic detector that doesn't implement ExposeHandlerDetector +// mockDetector is a basic detector that doesn't implement HandlerProvider type mockDetector struct{} func (m *mockDetector) Detect(ctx context.Context) (resource pcommon.Resource, schemaURL string, err error) { diff --git a/receiver/awscontainerinsightreceiver/go.mod b/receiver/awscontainerinsightreceiver/go.mod index 0e02e072cde8..92bbe044aab7 100644 --- a/receiver/awscontainerinsightreceiver/go.mod +++ b/receiver/awscontainerinsightreceiver/go.mod @@ -4,7 +4,7 @@ go 1.22.5 require ( github.com/Microsoft/hcsshim v0.12.0-rc.3 - github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20241204155332-be45e31638de + github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware v0.0.0-20240419190856-2f880467f335 github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws v0.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go v1.53.11 github.com/go-kit/log v0.2.1 @@ -275,3 +275,4 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/corei replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden +replace github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware => ../../extension/awsmiddleware \ No newline at end of file