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

Custom Collector with timestamp producing exposition prometheus cannot parse #4911

Closed
sedan07 opened this Issue Nov 25, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@sedan07
Copy link

sedan07 commented Nov 25, 2018

I have an external system which doesn't directly expose metrics in prometheus format. To get these metrics into prometheus I'm attempting to write a custom collector in Python which scrapes the external system and publishes them in prometheus format. However the metrics from the external system are delayed by 30 minutes. Looking at the source code for the GaugeMetricFamily class it's possible to pass a timestamp. This also matches the docs on the exposition format.

However passing a timestamp causes the Prometheus server (v2.5.0) not to be able to read the metrics and gives the error: 'expected next entry after timestamp, got "MNAME"'. The following code shows the issue:

Using v0.4.2 of the python client and Python 3.7

from datetime import datetime, timedelta
import time
from prometheus_client import start_http_server
from prometheus_client.core import GaugeMetricFamily, REGISTRY

class CustomCollector(object):
    def collect(self):
        now = datetime.now()
        metric_time = now - timedelta(minutes=30)

        g = GaugeMetricFamily('my_gauge', 'Help text', labels=['foo'])
        g.add_metric(['bar'], 1.7, metric_time.timestamp())
        g.add_metric(['baz'], 3.8, metric_time.timestamp())
        yield g

def main():
    start_http_server(8000)
    REGISTRY.register(CustomCollector())

    while True: time.sleep(1)

main()

Viewing the output of localhost:8000 appears to show the metrics in the correct format matching the exposition format and doesn't show any extra values which might cause it. Am I simply using this wrong? or is this a bug somehow?

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Nov 26, 2018

This is a bug on the Prometheus side, it's not negotiating openmetrics correctly if gzip is not in use.

@brian-brazil brian-brazil transferred this issue from prometheus/client_python Nov 26, 2018

brian-brazil added a commit that referenced this issue Nov 26, 2018

Pass through content-type for non-compressed output.
Fixes #4911

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>

@simonpasquier simonpasquier added this to the v2.6.0 milestone Nov 26, 2018

brian-brazil added a commit that referenced this issue Nov 26, 2018

Pass through content-type for non-compressed output. (#4912)
Fixes #4911

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>

@simonpasquier simonpasquier removed this from the v2.6.0 milestone Nov 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.