inputs/diskio: honour HOST_MOUNT_PREFIX / HOST_DEV#18732
Closed
SAY-5 wants to merge 1 commit intoinfluxdata:masterfrom
Closed
inputs/diskio: honour HOST_MOUNT_PREFIX / HOST_DEV#18732SAY-5 wants to merge 1 commit intoinfluxdata:masterfrom
SAY-5 wants to merge 1 commit intoinfluxdata:masterfrom
Conversation
Reported as influxdata#18671. When telegraf runs inside a container and the host devices are mounted under /hostfs, diskio still hard-codes /dev, /sys, and /run/udev when it reads: /dev/<name> (Stat) /run/udev/data/bMAJOR:MINOR (os.Stat) /dev/.udev/db/block:<name> (os.Stat) /sys/class/block/<name> (os.Open uevent) /dev/<name> (EvalSymlinks in resolveName) /sys/block/<name>/wwid (os.ReadFile) so every device shows up in logs as "no such file or directory", even though telegraf is otherwise configured with HOST_PROC, HOST_SYS, HOST_ETC, HOST_RUN, HOST_DEV and HOST_MOUNT_PREFIX like every other input plugin documents. Add GetDevPath() and GetRunPath() helpers in internal/env.go that mirror the existing GetProcPath() / GetSysPath() pattern: prefer HOST_DEV / HOST_RUN, fall back to HOST_MOUNT_PREFIX/<subdir>, fall back to the real paths on bare metal. GetSysPath() gets the same HOST_MOUNT_PREFIX fallback. Switch diskio_linux.go to build every filesystem-access path via filepath.Join through these helpers. The two places that construct tag strings destined for metrics (DEVLINKS, DEVNAME) keep their "/dev/..." format, since those values are identifiers, not filesystem paths. No configuration changes required; plugins that already set HOST_MOUNT_PREFIX just start working. Fixes influxdata#18671 Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Member
Contributor
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
Contributor
Author
Member
|
Sorry if I sounded rude! Thanks for caring about this project! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18671.
Problem
When telegraf runs inside a container with
HOST_MOUNT_PREFIX=/hostfs(and friends), the[[inputs.diskio]]plugin still hard-codes/dev/,/sys/, and/run/udev/:The paths that needed updating are:
/dev/<name>(unix.Stat check)/run/udev/data/b<major>:<minor>(udev data)/dev/.udev/db/block:<name>(non-systemd fallback)/sys/class/block/<name>(sys block entry)/dev/<name>(EvalSymlinks inresolveName)/sys/block/<name>/wwid(wwid reader)Fix
Two changes:
internal/env.go: addGetDevPath()andGetRunPath()helpers that mirror the existingGetProcPath()/GetSysPath()pattern. Each prefers its explicit env var (HOST_DEV,HOST_RUN), falls back toHOST_MOUNT_PREFIX/<subdir>so a singleHOST_MOUNT_PREFIX=/hostfscovers/proc,/sys,/dev,/run, and falls back to the real paths on bare metal.GetSysPath()also gets theHOST_MOUNT_PREFIXfallback so it matches the others.plugins/inputs/diskio/diskio_linux.go: switch every filesystem-access path to build viafilepath.Join(internal.GetDevPath(), ...)/internal.GetSysPath()/internal.GetRunPath(). The two places that construct tag strings destined for metrics (DEVLINKS,DEVNAME) keep their"/dev/..."format because those are identifiers, not filesystem paths.No configuration changes required; existing containers that already set
HOST_MOUNT_PREFIXsimply start working.Signed off per DCO.