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

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

Open
n-peugnet opened this issue Feb 14, 2025 · 0 comments

Comments

@n-peugnet
Copy link

n-peugnet commented Feb 14, 2025

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:

for suffix in set(type_suffixes.get(typ, []) + [""]):
if name + suffix in seen_names:
raise ValueError("Clashing name: " + name + suffix)

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant