Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/hostmetrics] fix filesystem scraper root_path support #35991

Closed
wants to merge 1 commit into from

Conversation

povilasv
Copy link
Contributor

@povilasv povilasv commented Oct 25, 2024

Description

Fixes #35990

Looks like filesystem scraper stopped respecting root_path

The issue it seems to be that the default value in this map is wrong:

var gopsutilEnvVars = map[common.EnvKeyType]string{
	common.HostProcEnvKey:    "/proc",
	common.HostSysEnvKey:     "/sys",
	common.HostEtcEnvKey:     "/etc",
	common.HostVarEnvKey:     "/var",
	common.HostRunEnvKey:     "/run",
	common.HostDevEnvKey:     "/dev",
	common.HostProcMountinfo: "",
}

and this function fails to correctly set envvars:

func setGoPsutilEnvVars(rootPath string, env environment) common.EnvMap {
	m := common.EnvMap{}
	if rootPath == "" || rootPath == "/" {
		return m
	}

	for envVarKey, defaultValue := range gopsutilEnvVars {
		_, ok := env.Lookup(string(envVarKey))
		if ok {
			continue // don't override if existing env var is set
		}
		m[envVarKey] = filepath.Join(rootPath, defaultValue)
	}
	return m
}

Gops utils docs:

You can set an alternative location to /proc/N/mountinfo by setting the HOST_PROC_MOUNTINFO environment variable.

Ref: https://github.com/shirou/gopsutil/blob/6be0508aeb80711cfb45a829590fb4b2b9972bba/disk/disk_linux.go#L260-L261

Testing

Tested in local computer

Documentation

@povilasv povilasv marked this pull request as ready for review October 25, 2024 06:21
@povilasv povilasv requested a review from a team as a code owner October 25, 2024 06:21
@povilasv
Copy link
Contributor Author

cc @atoulme

@atoulme
Copy link
Contributor

atoulme commented Oct 25, 2024

We don't set env vars anymore, we use the envMap and pass it as part of context. The function name is misleading.

@atoulme
Copy link
Contributor

atoulme commented Oct 25, 2024

I have provided a solution with #36000 which I believe fixes the issue. Please take a look.

@povilasv povilasv closed this Oct 28, 2024
@povilasv povilasv deleted the hostmetrics branch October 28, 2024 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[receiver/hostmetrics] filesystem scraper doesn't respect root_path
3 participants