prometheus / prometheus/client_python

OpenMetrics parser cannot parse the output of `promtool tsdb dump-openmetrics`

Open
#1,091 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.4k
Forks
876
Avg merge
8d 4h
Merged PRs (30d)
1

Description

I tried using the example code...

import sys
from prometheus_client.openmetrics.parser import text_string_to_metric_families

for family in text_string_to_metric_families(sys.stdin.read()):
  for sample in family.samples:
      print("Name: {0} Labels: {1} Value: {2} Timestamp: {3}".format(*sample))

...to parse an OpenMetrics file produced by promtool tsdb dump-openmetrics, but I run into the following issue:

Traceback (most recent call last):
  File "/home/nicolas/IE6/synapse-meshsim/exp/./normalise_timestamps.py", line 6, in <module>
    for family in text_string_to_metric_families(sys.stdin.read()):
  File "/home/nicolas/IE6/synapse-meshsim/exp/venv/lib/python3.11/site-packages/prometheus_client/openmetrics/parser.py", line 18, in text_string_to_metric_families
    yield from text_fd_to_metric_families(StringIO.StringIO(text))
  File "/home/nicolas/IE6/synapse-meshsim/exp/venv/lib/python3.11/site-packages/prometheus_client/openmetrics/parser.py", line 543, in text_fd_to_metric_families
    yield build_metric(name, documentation, typ, unit, samples)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolas/IE6/synapse-meshsim/exp/venv/lib/python3.11/site-packages/prometheus_client/openmetrics/parser.py", line 472, in build_metric
    raise ValueError("Clashing name: " + name + suffix)
ValueError: Clashing name: go_gc_duration_seconds

This comes from this code: https://github.com/prometheus/client_python/blob/46eae7bae88f76951f7246d9f359f2dd5eeff110/prometheus_client/openmetrics/parser.py#L487-L489

But I don't understand why this check exists in the first place? In my case, I have the same metrics for multiple instances, and dump-openmetrics groups them by instance, then by metrics name. Can't we just remove this check altogether?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with prometheus_client/openmetrics/parser.py at the linked build_metric check and compare its assumptions with the grouped output from promtool tsdb dump-openmetrics. Reproduce the failure using the example parser code and that output. Done means the parser's behavior for repeated metric names is defined and the reported clashing-name failure is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.