opentelemetry-collector-contrib
opentelemetry-collector-contrib copied to clipboard
[receiver/windowsperfcounters] fix: Drop metrics with empty datapoints.
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
debugexporter seesResourceMetricswith no metrics and doesn't throw. - Confirmed that
prometheusremotewriteexporter 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)
@braydonk
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.
This PR was marked stale due to lack of activity. It will be closed in 14 days.
This PR was marked stale due to lack of activity. It will be closed in 14 days.