-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Use case:
Scraping underlying host metrics from a container
Existing approach to scrape host metrics from container:
- Mount host filesystem
/
path to some path inside container, e.g./hostfs
. - Setup env variables supported by gosutil to point it to different locations, e.g.
HOST_PROC=/hostfs/proc
Problem description:
The described approach works for all hostmetrics
receiver scrapers except for filesystem
.
filesystem
scraper workflow (assuming HOST_PROC=/hostfs/proc
) is the following:
- Fetch list of disc partitions with
gopsutil/disk.Partitions
: all the paths in the returned list are plain host paths, not prefixed with/hostfs
. - Read usage stats of the partitions returned at the step 1 with
gopsutil/disk.Usage
using mount points paths: since the mount point paths are used as is (without/hostfx
prefix), the function reads container partition stats instead of host partition stats. Obviously, most of the host mount points are not available in the container, and it results in throwing the following errors:
2021-10-23T16:39:03.988Z error scraperhelper/scrapercontroller.go:198 Error scraping metrics {"kind": "receiver", "name": "hostmetrics", "error": "no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory; no such file or directory", "scraper": "filesystem"}
go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).scrapeMetricsAndReport
go.opentelemetry.io/collector@v0.37.1-0.20211015233822-bd87fb628058/receiver/scraperhelper/scrapercontroller.go:198
go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).startScraping.func1
go.opentelemetry.io/collector@v0.37.1-0.20211015233822-bd87fb628058/receiver/scraperhelper/scrapercontroller.go:173
The issue was uncovered by this change to goputils library shirou/gopsutil#1133. Before that gopsutil/disk.Partitions
used to return container disk partitions, so it looked like it worked well, but it didn't.
Suggested solution:
Add new configuration option to hostmetrics
receiver: root_path
with /
as default. The receiver behavior stays the same with default value, but if the root_path
set to something else:
- Make sure that all the env variables needed for gopsutil are automatically set (only if not provided by user)
- Handle all the paths translation between
gopsutil/disk.Partitions
andgopsutil/disk.Usage
calls in filesystem scraper to fix the described issue. We cannot expect users to always mount the whole/
host path to the container, so any files misses should throw debug logs instead of errors.