Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug on empty openmetrics scrape response #14508

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ def parse_metrics(self):
# Since we determine `self.parse_metric_families` dynamically from the response and that's done as a
# side effect inside the `line_streamer` generator, we need to consume the first line in order to
# trigger that side effect.
line_streamer = chain([next(line_streamer)], line_streamer)
try:
line_streamer = chain([next(line_streamer)], line_streamer)
except StopIteration:
# If line_streamer is an empty iterator, next(line_streamer) fails.
return

for metric in self.parse_metric_families(line_streamer):
self.submit_telemetry_number_of_total_metric_samples(metric)
Expand Down
9 changes: 9 additions & 0 deletions openmetrics/tests/test_openmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ def test_openmetrics_use_latest_spec(aggregator, dd_run_check, mock_http_respons
assert scraper.http.options['headers']['Accept'] == (
'application/openmetrics-text;version=1.0.0,application/openmetrics-text;version=0.0.1'
)


def test_openmetrics_empty_response(aggregator, dd_run_check, mock_http_response, openmetrics_payload, caplog):
mock_http_response("")

check = OpenMetricsCheck('openmetrics', {}, [instance_new])
dd_run_check(check)

aggregator.assert_all_metrics_covered()