Skip to content

Commit

Permalink
Fix bug on empty openmetrics scrape response (#14508)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-lowman-dd authored and aweaver89 committed May 10, 2023
1 parent 8e8b2e4 commit 6c12772
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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()

0 comments on commit 6c12772

Please sign in to comment.