From d2692edc0c0a572e638cbba29a0d7324b3474a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 31 Mar 2020 15:38:29 +0200 Subject: [PATCH] Add comments --- .../datadog_checks/base/checks/libs/prometheus.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/datadog_checks_base/datadog_checks/base/checks/libs/prometheus.py b/datadog_checks_base/datadog_checks/base/checks/libs/prometheus.py index 9f4b0df62b610..7c5c68776c6fa 100644 --- a/datadog_checks_base/datadog_checks/base/checks/libs/prometheus.py +++ b/datadog_checks_base/datadog_checks/base/checks/libs/prometheus.py @@ -6,11 +6,16 @@ from prometheus_client.parser import _parse_sample, _replace_help_escaping +# 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): """Parse Prometheus text format from a file descriptor. - This is a laxer parser than the main Go parser, - so successful parsing does not imply that the parsed - text meets the specification. + + This is a laxer parser than the main Go parser, so successful parsing does + not imply that the parsed text meets the specification. + Yields Metric's. """ name = '' @@ -20,6 +25,7 @@ def text_fd_to_metric_families(fd): allowed_names = [] def build_metric(name, documentation, typ, samples): + # This is where the change is happening: we don't munge counters as upstream does. metric = Metric(name, documentation, typ) metric.samples = samples return metric