Skip to content

Info Metric Value Type Support #583

Closed

Description

@siddharths2710

For accomodating a collection of information as part of my requirement, I was initially under the impression that the Info metric will be able to support a key-value pair with the value field entered as a list of objects.

For Ex.

from prometheus_client import start_http_server, Info
start_http_server(8001)
inf = Info("name","desc")
inf.Info({"key":["val1","val2"]})

The above piece of code however throws the below Stack Trace:

Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/path/to/prometheus_client_python/prometheus_client/exposition.py", line 52, in prometheus_app
    status, header, output = _bake_output(registry, accept_header, params)
  File "/path/to/prometheus_client_python/prometheus_client/exposition.py", line 40, in _bake_output
    output = encoder(registry)
  File "/path/to/prometheus_client_python/prometheus_client/exposition.py", line 137, in generate_latest
    output.append(sample_line(s))
  File "/path/to/prometheus_client_python/prometheus_client/exposition.py", line 95, in sample_line
    for k, v in sorted(line.labels.items())]))
  File "/path/to/prometheus_client_python/prometheus_client/exposition.py", line 95, in <listcomp>
    for k, v in sorted(line.labels.items())]))
AttributeError: ("'list' object has no attribute 'replace'", Metric(ede, dfe, info, , [Sample(name='ede_info', labels={'key': ['str1', 'str2']}, value=1.0, timestamp=None, exemplar=None)]))

I'd want to know how this case must be handled:

  • The list type as value should have been accepted, in which case the code must be modified
  • If list type isn't an acceptable value, then a readable error message must be thrown instead.

Activity

  1. siddharths2710 commented on Sep 28, 2020

    @siddharths2710
    Author

    In case of the latter, how will I be able to handle one-to-many associations ( Ex. The info of all clients to a given server in a distributed system? )

    I can add a label for the server identifier, but my problem is that the client info is variable.

  2. brian-brazil commented on Sep 28, 2020

    @brian-brazil
    Contributor

    The docs show that it's a string value, and I don't think it makes sense to try and catch every way that a user tries to put in arbitrary invalid data types with a specific error. This is more a usage question, and it makes more sense to ask questions like this on the prometheus-users mailing list rather than in a GitHub issue. On the mailing list, more people are available to potentially respond to your question, and the whole community can benefit from the answers provided.

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