Skip to content

Commit

Permalink
Include input line in openmetrics parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevon committed May 23, 2024
1 parent d4ef6dc commit e891e6e
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@

from prometheus_client.metrics_core import Metric
from prometheus_client.parser import _parse_sample, _replace_help_escaping
from itertools import tee
from six.moves import zip


def text_fd_to_metric_families(fd):
raw_lines, input_lines = tee(fd, 2)
try:
for raw_line, metric_family in zip(raw_lines, _parse_payload(input_lines)):
yield metric_family
except Exception as e:
raise ValueError("Failed to parse the metric response '{}': {}".format(raw_line, e))


# This copies most of the code from upstream at that version:
# https://github.com/prometheus/client_python/blob/049744296d216e6be65dc8f3d44650310f39c384/prometheus_client/parser.py#L144
# but reverting the behavior to a compatible version, which doesn't change counters to have a total suffix. See
# https://github.com/prometheus/client_python/commit/a4dd93bcc6a0422e10cfa585048d1813909c6786#diff-0adf47ea7f99c66d4866ccb4e557a865L158
def text_fd_to_metric_families(fd):
def _parse_payload(fd):
"""Parse Prometheus text format from a file descriptor.
This is a laxer parser than the main Go parser, so successful parsing does
Expand Down

0 comments on commit e891e6e

Please sign in to comment.