From 47df00d6888d6c0e02a8fd70607f42ee2d228b21 Mon Sep 17 00:00:00 2001 From: jvoravong <47871238+jvoravong@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:08:12 -0700 Subject: [PATCH] [receiver/hostmetrics] Have the hostmetrics receiver file system scraper use more debug messages (#18895) If a locked drive exists on a host, the file system scraper can pollute the logs with errors you can not filter out. This change makes these types of error messages go to the debug level. This was a customer ask. See related ticket for more details. --- ...hance-hostmetrics-filesystem-log-level.yaml | 18 ++++++++++++++++++ .../filesystemscraper/filesystem_scraper.go | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .chloggen/enhance-hostmetrics-filesystem-log-level.yaml diff --git a/.chloggen/enhance-hostmetrics-filesystem-log-level.yaml b/.chloggen/enhance-hostmetrics-filesystem-log-level.yaml new file mode 100644 index 000000000000..b37853465a8b --- /dev/null +++ b/.chloggen/enhance-hostmetrics-filesystem-log-level.yaml @@ -0,0 +1,18 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: hostmetrics + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Have the hostmetrics receiver file system scraper use more debug messages + +# One or more tracking issues related to the change +issues: [18236] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: Log a debug message instead of an error if the collector does not + have the permissions to access a locked drive on the host. We do not want to + log an error message on every poll for this case. diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go index aa2d88f2e226..67aedd6d6f50 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "path/filepath" + "strings" "time" "github.com/shirou/gopsutil/v3/disk" @@ -27,6 +28,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/scrapererror" + "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata" ) @@ -84,7 +86,15 @@ func (s *scraper) scrape(_ context.Context) (pmetric.Metrics, error) { if len(partitions) == 0 { return pmetric.NewMetrics(), scrapererror.NewPartialScrapeError(err, metricsLen) } - errors.AddPartial(0, fmt.Errorf("failed collecting partitions information: %w", err)) + if strings.Contains(strings.ToLower(err.Error()), "locked") { + // Log a debug message instead of an error message if a drive is + // locked and unavailable. For this particular case, we do not want + // to log an error message on every poll. + // See: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18236 + s.settings.Logger.Debug("failed collecting locked partitions information: %w", zap.Error(err)) + } else { + errors.AddPartial(0, fmt.Errorf("failed collecting partitions information: %w", err)) + } } usages := make([]*deviceUsage, 0, len(partitions))