Skip to content

Commit

Permalink
[processor/resourcedetection] Make detect no-op for non-EKS environme…
Browse files Browse the repository at this point in the history
…nts.
  • Loading branch information
jefchien committed Sep 3, 2024
1 parent 13f78ca commit 69a9a32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal
cfg := dcfg.(Config)
utils, err := newK8sDetectorUtils()
if err != nil {
return nil, err
set.Logger.Debug("Unable to setup K8s detector", zap.Error(err))
}
return &detector{
utils: utils,
Expand All @@ -78,6 +78,10 @@ func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal

// Detect returns a Resource describing the Amazon EKS environment being run in.
func (d *detector) Detect(ctx context.Context) (resource pcommon.Resource, schemaURL string, err error) {
// Error is already logged in the constructor
if d.utils == nil {
return pcommon.NewResource(), "", nil
}
// Check if running on EKS.
isEKS, err := isEKS(ctx, d.utils)
if !isEKS {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/processor/processortest"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
"go.uber.org/zap"
Expand Down Expand Up @@ -43,8 +44,13 @@ func (detectorUtils *MockDetectorUtils) getClusterNameTagFromReservations(_ []*e
func TestNewDetector(t *testing.T) {
dcfg := CreateDefaultConfig()
detector, err := NewDetector(processortest.NewNopSettings(), dcfg)
assert.Error(t, err)
assert.Nil(t, detector)
assert.NoError(t, err)
assert.NotNil(t, detector)
// no-op
gotResource, gotSchema, gotErr := detector.Detect(context.Background())
assert.NoError(t, gotErr)
assert.Equal(t, pcommon.NewResource(), gotResource)
assert.Empty(t, gotSchema)
}

// Tests EKS resource detector running in EKS environment
Expand Down

0 comments on commit 69a9a32

Please sign in to comment.