Skip to content

fix(inputs.diskio): Honor host path environment variables on Linux#18682

Merged
skartikey merged 1 commit intoinfluxdata:masterfrom
WZH8898:fix-diskio-host-paths
Apr 28, 2026
Merged

fix(inputs.diskio): Honor host path environment variables on Linux#18682
skartikey merged 1 commit intoinfluxdata:masterfrom
WZH8898:fix-diskio-host-paths

Conversation

@WZH8898
Copy link
Copy Markdown
Contributor

@WZH8898 WZH8898 commented Apr 9, 2026

Summary

This PR updates inputs.diskio on Linux to honor host path environment variables instead of relying on hard-coded /dev, /run, and /sys paths, addressing issue #18671.

Added support for resolving host paths with the following fallback order:

  • HOST_DEV / HOST_RUN / HOST_SYS
  • HOST_ROOT
  • HOST_MOUNT_PREFIX
  • default /dev, /run, /sys

This PR also fixes the infoCache writeback to store sysBlockPath correctly, updates the /dev fallback in resolveName() to use the resolved host device path, and updates getDeviceWWID() to read from the resolved host sysfs path.

Tests added in this PR cover:

  • HOST_DEV + HOST_RUN
  • HOST_ROOT fallback
  • HOST_MOUNT_PREFIX fallback
  • HOST_SYS handling for WWID lookup

Checklist

  • No AI generated code was used in this PR
  • AI generated code used in this PR follows the InfluxData Policy on AI-Generated Code Contributions

Related issues

resolves #18671

@telegraf-tiger telegraf-tiger Bot added fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Apr 9, 2026
@WZH8898 WZH8898 force-pushed the fix-diskio-host-paths branch from c9ebb0e to cad1114 Compare April 9, 2026 09:47
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @WZH8898! Please find my comments below.

Please also adhere to our PR title schema which starts with the semantic-commit prefix and then has an uppercase verb as a first word after the colon!

Comment thread plugins/inputs/diskio/diskio_linux.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux.go Outdated
@srebhan srebhan self-assigned this Apr 9, 2026
@WZH8898 WZH8898 changed the title fix(inputs.diskio): honor host path environment variables on linux fix(inputs.diskio): Honor host path environment variables on Linux Apr 10, 2026
@WZH8898 WZH8898 force-pushed the fix-diskio-host-paths branch from cad1114 to 88fcfbc Compare April 10, 2026 08:17
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WZH8898! Some more comments from my side.

Comment thread plugins/inputs/diskio/diskio_linux.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
@WZH8898 WZH8898 force-pushed the fix-diskio-host-paths branch from 517fda1 to 3c65601 Compare April 14, 2026 08:18
@WZH8898
Copy link
Copy Markdown
Contributor Author

WZH8898 commented Apr 14, 2026

Thanks for the detailed review, I updated the patch accordingly:

  • DEVPATH handling was simplified to only strip sysPath (removed the extra "/sys" trim and leading-slash normalization).
  • In resolveName(), I removed the /dev/absolute-path trimming logic and now only do the fallback resolution relative to d.devPath.
  • Tests now consistently initialize the plugin via require.NoError(t, plugin.Init()) (using a small helper), instead of manually setting devPath/runPath/sysPath.
  • I replaced the t.TempDir() host-path setup with fixed testdata/hostfs fixtures, as suggested. Added:
    testdata/hostfs/dev/mockdev
    testdata/hostfs/sys/block/sda/wwid

This keeps the test inputs explicit/reproducible and aligns with your requested style.

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WZH8898! Just one more comment...

Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WZH8898! Some more comments regarding the tests.

Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
@WZH8898 WZH8898 force-pushed the fix-diskio-host-paths branch from e8da02b to f15edce Compare April 21, 2026 07:20
@WZH8898
Copy link
Copy Markdown
Contributor Author

WZH8898 commented Apr 21, 2026

Thanks @WZH8898! Some more comments regarding the tests.

Thanks @srebhan , addressed. I replaced setupEnv callbacks with env map[string]string and apply them in the test loop via t.Setenv, removed the redundant createDev indirection by joining paths at the caller side, and dropped the unix.Stat/mtime-dependent setup in favor of direct fixture-based assertions.

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WZH8898! Just a last suggestion to improve readability...

Comment on lines +88 to +89
hostRoot := filepath.Join("testdata", "hostfs")
t.Setenv("HOST_DEV", filepath.Join(hostRoot, "dev"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is easier to read the actual path

Suggested change
hostRoot := filepath.Join("testdata", "hostfs")
t.Setenv("HOST_DEV", filepath.Join(hostRoot, "dev"))
t.Setenv("HOST_DEV", filepath.Join("testdata", "hostfs", "dev"))

Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
Comment on lines +151 to +152
hostSys := filepath.Join("testdata", "hostfs", "sys")
t.Setenv("HOST_SYS", hostSys)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hostSys := filepath.Join("testdata", "hostfs", "sys")
t.Setenv("HOST_SYS", hostSys)
t.Setenv("HOST_SYS", filepath.Join("testdata", "hostfs", "sys"))

@WZH8898 WZH8898 force-pushed the fix-diskio-host-paths branch 2 times, most recently from e11389a to c2b173c Compare April 23, 2026 06:59
@WZH8898
Copy link
Copy Markdown
Contributor Author

WZH8898 commented Apr 23, 2026

Thanks @WZH8898! Just a last suggestion to improve readability...

Thanks @srebhan, addressed.

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WZH8898! Just one more small improvement...

Comment thread plugins/inputs/diskio/diskio_linux_test.go Outdated
@WZH8898 WZH8898 force-pushed the fix-diskio-host-paths branch from c2b173c to ed21ecf Compare April 28, 2026 07:50
@telegraf-tiger
Copy link
Copy Markdown
Contributor

@WZH8898
Copy link
Copy Markdown
Contributor Author

WZH8898 commented Apr 28, 2026

Thanks @WZH8898! Just one more small improvement...

Thanks @srebhan, addressed.

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Thanks @WZH8898!

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Apr 28, 2026
@srebhan srebhan assigned skartikey and unassigned srebhan Apr 28, 2026
Copy link
Copy Markdown
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WZH8898 Thanks for the contribution!

@skartikey skartikey merged commit d2e3a60 into influxdata:master Apr 28, 2026
27 checks passed
@github-actions github-actions Bot added this to the v1.38.4 milestone Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[[inputs.diskio]] not honoring HOST_MOUNT_PREFIX / Missing HOST_DEV environment variable

3 participants