Skip to content

Commit e5c5eda

Browse files
pjanottikhushijain21
authored andcommitted
[receiver/awscontainerinsight] Add HOST_PROC env var support (open-telemetry#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
1 parent cd06cb4 commit e5c5eda

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
change_type: enhancement
2+
3+
component: awscontainerinsightreceiver
4+
5+
note: Add support for HOST_PROC environment variable in AWS Container Insight Receiver.
6+
7+
issues: [35862]
8+
9+
subtext:
10+
11+
change_logs: [user]

receiver/awscontainerinsightreceiver/internal/host/nodeCapacity.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ func newNodeCapacity(logger *zap.Logger, options ...nodeCapacityOption) (nodeCap
4343
opt(nc)
4444
}
4545

46-
if _, err := nc.osLstat(hostProc); os.IsNotExist(err) {
46+
actualHostProc, ok := os.LookupEnv(string(common.HostProcEnvKey))
47+
if !ok {
48+
actualHostProc = hostProc
49+
}
50+
51+
if _, err := nc.osLstat(actualHostProc); os.IsNotExist(err) {
4752
return nil, err
4853
}
49-
envMap := common.EnvMap{common.HostProcEnvKey: hostProc}
54+
envMap := common.EnvMap{common.HostProcEnvKey: actualHostProc}
5055
ctx := context.WithValue(context.Background(), common.EnvKey, envMap)
5156

5257
nc.parseCPU(ctx)

receiver/awscontainerinsightreceiver/internal/host/nodeCapacity_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"testing"
1111

12+
"github.com/shirou/gopsutil/v4/common"
1213
"github.com/shirou/gopsutil/v4/cpu"
1314
"github.com/shirou/gopsutil/v4/mem"
1415
"github.com/stretchr/testify/assert"
@@ -71,3 +72,19 @@ func TestNodeCapacity(t *testing.T) {
7172
assert.Equal(t, int64(1024), nc.getMemoryCapacity())
7273
assert.Equal(t, int64(2), nc.getNumCores())
7374
}
75+
76+
func TestNodeCapacity_ReadsHostProcEnvVar(t *testing.T) {
77+
const customHostProc = "/custom/host/proc"
78+
t.Setenv(string(common.HostProcEnvKey), customHostProc)
79+
80+
lstatOption := func(nc *nodeCapacity) {
81+
nc.osLstat = func(name string) (os.FileInfo, error) {
82+
assert.Equal(t, customHostProc, name)
83+
return nil, nil
84+
}
85+
}
86+
87+
nc, err := newNodeCapacity(zap.NewNop(), lstatOption)
88+
assert.NoError(t, err)
89+
assert.NotNil(t, nc)
90+
}

0 commit comments

Comments
 (0)