-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[service/proctelemetry] Offer to override the HOST_PROC environment v…
…ariable with a programmatic value (#7998) Reprising #7434 **Description:** While debugging the below error in k8s env ```` Error: failed to register process metrics: process does not exist 2023/03/23 03:44:47 main.go:115: application run finished with error: failed to register process metrics: process does not exist ```` I have noticed that the metric server is calling GOPSUTIL while the HOST_PROC variable is set , this causes gopsutil `PidExistsWithContext ` to retrieve the process from the host instead from the container ```` func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) { if pid <= 0 { return false, fmt.Errorf("invalid pid %v", pid) } proc, err := os.FindProcess(int(pid)) if err != nil { return false, err } if isMount(common.HostProc()) { // if /<HOST_PROC>/proc exists and is mounted, check if /<HOST_PROC>/proc/<PID> folder exists _, err := os.Stat(common.HostProc(strconv.Itoa(int(pid)))) if os.IsNotExist(err) { return false, nil } return err == nil, err } ```` This PR unsets and resets the host_proc variable and introduces an option to allow the use of host_proc if for whatever reason they need to **Link to tracking Issue:** Fixes #7435 **Testing:** unit tests --------- Signed-off-by: Dani Louca <[email protected]> Co-authored-by: Dani Louca <[email protected]> Co-authored-by: Alex Boten <[email protected]>
- Loading branch information
1 parent
5b47503
commit 55902b6
Showing
2 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
service/internal/proctelemetry/process_telemetry_linux_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
package proctelemetry | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opencensus.io/metric" | ||
"go.opentelemetry.io/otel/metric/noop" | ||
) | ||
|
||
func TestOCProcessTelemetryWithHostProc(t *testing.T) { | ||
ocRegistry := metric.NewRegistry() | ||
// Make the sure the environment variable value is not used. | ||
t.Setenv("HOST_PROC", "foo/bar") | ||
|
||
require.NoError(t, RegisterProcessMetrics(ocRegistry, noop.NewMeterProvider(), false, 0, WithHostProc("/proc"))) | ||
|
||
// Check that the metrics are actually filled. | ||
time.Sleep(200 * time.Millisecond) | ||
|
||
metrics := ocRegistry.Read() | ||
|
||
for _, metricName := range expectedMetrics { | ||
m := findMetric(metrics, metricName) | ||
require.NotNil(t, m) | ||
require.Len(t, m.TimeSeries, 1) | ||
ts := m.TimeSeries[0] | ||
assert.Len(t, ts.LabelValues, 0) | ||
require.Len(t, ts.Points, 1) | ||
|
||
var value float64 | ||
if metricName == "process/uptime" || metricName == "process/cpu_seconds" { | ||
value = ts.Points[0].Value.(float64) | ||
} else { | ||
value = float64(ts.Points[0].Value.(int64)) | ||
} | ||
|
||
if metricName == "process/uptime" || metricName == "process/cpu_seconds" { | ||
// This likely will still be zero when running the test. | ||
assert.GreaterOrEqual(t, value, float64(0), metricName) | ||
continue | ||
} | ||
assert.Greater(t, value, float64(0), metricName) | ||
} | ||
} |