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

push_to_gateway function uses PUT method, which is rejected by WSGI server #1072

Open
mallika-mur opened this issue Nov 20, 2024 · 1 comment

Comments

@mallika-mur
Copy link

mallika-mur commented Nov 20, 2024

Hello, I'm still a newbie, so maybe I am misinterpreting something, but it appears as if there's an issue with the push_to_gateway() function defined in exposition.py.

Since v0.21 has been released, I cannot get my custom collector to expose its metrics over HTTP. It appears that even though the WSGI server when start_http_server() only supports OPTION and GET as methods, push_to_gateway() uses PUT, which gives me a "405 Method Not Allowed" error. Since my little program runs flawlessly with v0.20, I'm inclined to believe this may be a bug.

Here's what works in v0.20:

import prometheus_client
from prometheus_client.core import GaugeMetricFamily
import requests
import time


class MyCollector(object):
    def __init__(self):
        pass

    def collect(self):
        datajson = requests.get('https://api.example.com/foo)
        rawdata = datajson.json()

        registry = prometheus_client.CollectorRegistry()
        g = GaugeMetricFamily('mymetric', 'My Gauge Metric', value=rawdata['meta']['total'])
        yield g


if __name__ == '__main__':
    prometheus_client.start_http_server(8000)
    R = prometheus_client.REGISTRY.register(MyCollector())
    while True: 
        prometheus_client.push_to_gateway('localhost:8000', job='gaugemetricvalues', registry=R)
        time.sleep(3600)
@csmarchbanks
Copy link
Member

Push to gateway is not meant to push data back to itself, it is meant to push to a separate instance of the Pushgateway. Previously your pushes just were not doing anything, now we have slightly tighter handling of http requests so it is appropriately returning an error indicating that your program is not working as you intend.

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

2 participants