Skip to content

Non-stringy label values in MetricFamily metrics cause export-time errors #270

Open

Description

@DrewBloechl

This is very similar to #18 only I'm using the GaugeMetricFamily/CounterMetricFamily interface, otherwise the symptoms are the same. I'm using the default pypi version (which I think is 0.2.0).

I was inadvertently passing in ints for a couple of the label values in .add_metric(), which results in a 500 error on export and the following traceback. Wrapping a str() around the values makes this go away. Coercing these values as was done in the fix for #18 seems like the right thing to do here as well.

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/local/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/usr/local/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/local/lib/python3.6/http/server.py", line 406, in handle_one_request
    method()
  File "/usr/local/lib/python3.6/site-packages/prometheus_client/exposition.py", line 95, in do_GET
    output = generate_latest(registry)
  File "/usr/local/lib/python3.6/site-packages/prometheus_client/exposition.py", line 78, in generate_latest
    for k, v in sorted(labels.items())]))
  File "/usr/local/lib/python3.6/site-packages/prometheus_client/exposition.py", line 78, in <listcomp>
    for k, v in sorted(labels.items())]))
AttributeError: 'int' object has no attribute 'replace'

Activity

  1. brian-brazil commented on Apr 25, 2018

    @brian-brazil
    Contributor

    Would you like to send a PR?

  2. DrewBloechl commented on Apr 26, 2018

    @DrewBloechl
    Author

    At a glance it looks simple enough to fix (famous last words). I'll give it a shot within the next couple of days.

  3. brian-brazil commented on Aug 8, 2019

    @brian-brazil
    Contributor

    Did you have a chance to work on this?

  4. Prof-Bloodstone commented on Aug 16, 2019

    @Prof-Bloodstone

    This hit me yesterday and the workaround isn't pretty.

    I was looking at how to fix it, and the easiest solution (and potentially slowest , but given suboptimal string operations around, not that bad), is to use str(v).replace(... .
    The only other way I see is do this during adding the labels, but this isn't restricted in any way and would require quite a bit of changes and potentially is error-prone.

    Might take a deeper look at it once I'm done with my exporter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions