Skip to content

Commit

Permalink
[receiver/awscontainerinsight] Add HOST_PROC env var support (open-te…
Browse files Browse the repository at this point in the history
…lemetry#37694)

#### Description
Add support to HOST_PROC env var support. At this point I'm not sure if
the default should be changed or not, but, with the env var one can at
least experiment with the receiver on different images.

#### Link to tracking issue
Fixes open-telemetry#35862

#### Testing
Added respective unit test.

#### Documentation
Changelog
  • Loading branch information
pjanotti authored Feb 13, 2025
1 parent 7710208 commit 19a5f29
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
change_type: enhancement

component: awscontainerinsightreceiver

note: Add support for HOST_PROC environment variable in AWS Container Insight Receiver.

issues: [35862]

subtext:

change_logs: [user]
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ func newNodeCapacity(logger *zap.Logger, options ...nodeCapacityOption) (nodeCap
opt(nc)
}

if _, err := nc.osLstat(hostProc); os.IsNotExist(err) {
actualHostProc, ok := os.LookupEnv(string(common.HostProcEnvKey))
if !ok {
actualHostProc = hostProc
}

if _, err := nc.osLstat(actualHostProc); os.IsNotExist(err) {
return nil, err
}
envMap := common.EnvMap{common.HostProcEnvKey: hostProc}
envMap := common.EnvMap{common.HostProcEnvKey: actualHostProc}
ctx := context.WithValue(context.Background(), common.EnvKey, envMap)

nc.parseCPU(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"testing"

"github.com/shirou/gopsutil/v4/common"
"github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/mem"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -71,3 +72,19 @@ func TestNodeCapacity(t *testing.T) {
assert.Equal(t, int64(1024), nc.getMemoryCapacity())
assert.Equal(t, int64(2), nc.getNumCores())
}

func TestNodeCapacity_ReadsHostProcEnvVar(t *testing.T) {
const customHostProc = "/custom/host/proc"
t.Setenv(string(common.HostProcEnvKey), customHostProc)

lstatOption := func(nc *nodeCapacity) {
nc.osLstat = func(name string) (os.FileInfo, error) {
assert.Equal(t, customHostProc, name)
return nil, nil
}
}

nc, err := newNodeCapacity(zap.NewNop(), lstatOption)
assert.NoError(t, err)
assert.NotNil(t, nc)
}

0 comments on commit 19a5f29

Please sign in to comment.