open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.89k stars 2.26k forks source link

[receiver/hostmetrics/cpuscraper] Windows - CTX timeout, use CountsWithContext instead and make it configurable #32133

Open dloucasfx opened 5 months ago

dloucasfx commented 5 months ago

Component(s)

receiver/hostmetrics

What happened?

Description

The cpu.Counts gopsutil func, which is called by the cpu scraper, does not set a deadline/timeout on its context, which forces WMIQueryWithContext to set it using the hardcoded timeout value of 3 seconds. In large busy env or/and low resourced, the wmi call can take longer than 3 seconds, which will lead to a context deadline exceeded error and fail to get the CPU counts.

Steps to Reproduce

Find a windows host where the wmi calls take longer than 3 seconds and run the hostmetrics receiver with the cpu scraper.

Expected Result

Get all the metrics, including the physical and logical CPU counts

Actual Result

CPU counts are missing and we see this error in the logs

4670103 Mar 29 00:13 Error       splunk-otel-collector          3 1.7116855975244713e+09        error
                                                                  scraperhelper/scrapercontroller.go:200        Error
                                                                  scraping metrics      {"kind": "receiver", "name":
                                                                  "hostmetrics", "data_type": "metrics", "error":
                                                                  "context deadline exceeded", "scraper": "cpu"}
                                                                  go.opentelemetry.io/collector/receiver/scraperhelper.
                                                                  (*controller).scrapeMetricsAndReport
                                                                        go.opentelemetry.io/collector/receiver@v0.95.0/scrap
                                                                  erhelper/scrapercontroller.go:200
                                                                  go.opentelemetry.io/collector/receiver/scraperhelper.
                                                                  (*controller).startScraping.func1
                                                                        go.opentelemetry.io/collector/receiver@v0.95.0/scrap
                                                                  erhelper/scrapercontroller.go:176

Collector version

v0.95.0

Environment information

Environment

host_cpu_cores:"2"
host_cpu_model:"Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz"
host_mem_total:"8080924"
host_os_name":"Microsoft Windows Server 2016 Datacenter",

OpenTelemetry Collector configuration

No response

Log output

4670103 Mar 29 00:13 Error       splunk-otel-collector          3 1.7116855975244713e+09        error
                                                                  scraperhelper/scrapercontroller.go:200        Error
                                                                  scraping metrics      {"kind": "receiver", "name":
                                                                  "hostmetrics", "data_type": "metrics", "error":
                                                                  "context deadline exceeded", "scraper": "cpu"}
                                                                  go.opentelemetry.io/collector/receiver/scraperhelper.
                                                                  (*controller).scrapeMetricsAndReport
                                                                        go.opentelemetry.io/collector/receiver@v0.95.0/scrap
                                                                  erhelper/scrapercontroller.go:200
                                                                  go.opentelemetry.io/collector/receiver/scraperhelper.
                                                                  (*controller).startScraping.func1
                                                                        go.opentelemetry.io/collector/receiver@v0.95.0/scrap
                                                                  erhelper/scrapercontroller.go:176

Additional context

Suggestion is to use CountsWithContext instead of Counts and introduce a wmi_timeout option for cpuscraper

cc: @atoulme who helped with the RCA

github-actions[bot] commented 5 months ago

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

dloucasfx commented 5 months ago

This PR "does not" fix the main ask here, but improves and avoid the issue when the metric is not enabled

crobert-1 commented 4 months ago

Removing needs triage based on original PR being merged, I'll defer to code owners for more discussion on the potentially adding configuration options here.

cforce commented 4 months ago

Is this only an issue for windows or also Linux?

github-actions[bot] commented 2 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

crobert-1 commented 2 months ago

Is this only an issue for windows or also Linux?

Since the bug is in a WMI call, it looks like it's Windows only.

dloucasfx commented 3 weeks ago

Another user hitting this issue, can we look into this?