opentelemetry-collector-contrib icon indicating copy to clipboard operation
opentelemetry-collector-contrib copied to clipboard

[receiver/windowsperfcounters] fix: Drop metrics with empty datapoints.

Open alxbl opened this issue 1 year ago • 2 comments

Description: When scraping Windows Performance Counters, it's possible that some counter objects do not exist. When that is the case, windowsperfcounters will still create the Metric object with no datapoints in it. Some exporters throw errors when encountering this. The fix proposed in this PR does an extra pass after all metrics have been scraped and removes the Metric objects for which no datapoints were scraped.

Link to tracking Issue: #4972

Testing:

  • Confirmed that debug exporter sees ResourceMetrics with no metrics and doesn't throw.
  • Confirmed that prometheusremotewrite exporter no longer complains about empty datapoints and that it skips the export when no metrics are available
  • ~No unit tests added for now. I will add a unit test once I have confirmation that this is the right way to remove empty datapoints~ Unit test covering the changes and enabling fixture validation which was not implemented.

Documentation:

  • CHANGELOG (user-facing)

alxbl avatar Apr 15 '24 14:04 alxbl

@braydonk

dashpole avatar Apr 18 '24 14:04 dashpole

Added a unit test for empty data points and ran it: No Fix:

--- FAIL: Test_WindowsPerfCounterScraper (0.36s)
    --- FAIL: Test_WindowsPerfCounterScraper/MetricDefinedButNoScrapedValue (0.00s)
        c:\git\opentelemetry-contrib\receiver\windowsperfcountersreceiver\windowsperfcounters_scraper_test.go:200: 
            	Error Trace:	c:/git/opentelemetry-contrib/receiver/windowsperfcountersreceiver/windowsperfcounters_scraper_test.go:200
            	Error:      	Received unexpected error:
            	            	resource "map[]": scope "": number of metrics doesn't match expected: 1, actual: 2
            	Test:       	Test_WindowsPerfCounterScraper/MetricDefinedButNoScrapedValue
FAIL
FAIL	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowsperfcountersreceiver	0.483s
FAIL

With Fix:

PASS
ok      github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowsperfcountersreceiver  3.697s

I also found out that the tests didn't actually validate any of the data fixtures (so essentially they weren't testing much). I took the opportunity to fix that as well.

alxbl avatar Apr 18 '24 17:04 alxbl

This PR was marked stale due to lack of activity. It will be closed in 14 days.

github-actions[bot] avatar May 24 '24 05:05 github-actions[bot]

This PR was marked stale due to lack of activity. It will be closed in 14 days.

github-actions[bot] avatar Jun 08 '24 05:06 github-actions[bot]