Skip to content

Commit 5944792

Browse files
authored
[processor/resourcedetection] Make detect no-op for non-EKS environments. (#230)
1 parent 76facad commit 5944792

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

processor/resourcedetectionprocessor/internal/aws/eks/detector.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal
6666
cfg := dcfg.(Config)
6767
utils, err := newK8sDetectorUtils()
6868
if err != nil {
69-
return nil, err
69+
set.Logger.Debug("Unable to setup K8s detector", zap.Error(err))
7070
}
7171
return &detector{
7272
utils: utils,
@@ -78,6 +78,10 @@ func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal
7878

7979
// Detect returns a Resource describing the Amazon EKS environment being run in.
8080
func (d *detector) Detect(ctx context.Context) (resource pcommon.Resource, schemaURL string, err error) {
81+
// Error is already logged in the constructor
82+
if d.utils == nil {
83+
return pcommon.NewResource(), "", nil
84+
}
8185
// Check if running on EKS.
8286
isEKS, err := isEKS(ctx, d.utils)
8387
if !isEKS {

processor/resourcedetectionprocessor/internal/aws/eks/detector_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/mock"
1313
"github.com/stretchr/testify/require"
14+
"go.opentelemetry.io/collector/pdata/pcommon"
1415
"go.opentelemetry.io/collector/processor/processortest"
1516
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
1617
"go.uber.org/zap"
@@ -43,8 +44,13 @@ func (detectorUtils *MockDetectorUtils) getClusterNameTagFromReservations(_ []*e
4344
func TestNewDetector(t *testing.T) {
4445
dcfg := CreateDefaultConfig()
4546
detector, err := NewDetector(processortest.NewNopSettings(), dcfg)
46-
assert.Error(t, err)
47-
assert.Nil(t, detector)
47+
assert.NoError(t, err)
48+
assert.NotNil(t, detector)
49+
// no-op
50+
gotResource, gotSchema, gotErr := detector.Detect(context.Background())
51+
assert.NoError(t, gotErr)
52+
assert.Equal(t, pcommon.NewResource(), gotResource)
53+
assert.Empty(t, gotSchema)
4854
}
4955

5056
// Tests EKS resource detector running in EKS environment

0 commit comments

Comments
 (0)