Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

PYTHON26_OR_OLDER = sys.version_info < (2, 7)


def make_wsgi_app(registry=core.REGISTRY):
'''Create a WSGI app which serves the metrics from a registry.'''
def prometheus_app(environ, start_response):
Expand Down Expand Up @@ -179,7 +180,9 @@ def handle():
return handle


def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None, handler=default_handler):
def push_to_gateway(
gateway, job, registry, grouping_key=None, timeout=30,
handler=default_handler):
'''Push metrics to the given pushgateway.
`gateway` the url for your push gateway. Either of the form
Expand All @@ -190,7 +193,7 @@ def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None, han
`grouping_key` please see the pushgateway documentation for details.
Defaults to None
`timeout` is how long push will attempt to connect before giving up.
Defaults to None
Defaults to 30s, can be set to None for no timeout.
`handler` is an optional function which can be provided to perform
requests to the 'gateway'.
Defaults to None, in which case an http or https request
Expand Down Expand Up @@ -221,7 +224,9 @@ def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None, han
_use_gateway('PUT', gateway, job, registry, grouping_key, timeout, handler)


def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None, handler=default_handler):
def pushadd_to_gateway(
gateway, job, registry, grouping_key=None, timeout=30,
handler=default_handler):
'''PushAdd metrics to the given pushgateway.
`gateway` the url for your push gateway. Either of the form
Expand All @@ -232,7 +237,7 @@ def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None,
`grouping_key` please see the pushgateway documentation for details.
Defaults to None
`timeout` is how long push will attempt to connect before giving up.
Defaults to None
Defaults to 30s, can be set to None for no timeout.
`handler` is an optional function which can be provided to perform
requests to the 'gateway'.
Defaults to None, in which case an http or https request
Expand All @@ -245,7 +250,8 @@ def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None,
_use_gateway('POST', gateway, job, registry, grouping_key, timeout, handler)


def delete_from_gateway(gateway, job, grouping_key=None, timeout=None, handler=default_handler):
def delete_from_gateway(
gateway, job, grouping_key=None, timeout=30, handler=default_handler):
'''Delete metrics from the given pushgateway.
`gateway` the url for your push gateway. Either of the form
Expand All @@ -255,7 +261,7 @@ def delete_from_gateway(gateway, job, grouping_key=None, timeout=None, handler=d
`grouping_key` please see the pushgateway documentation for details.
Defaults to None
`timeout` is how long delete will attempt to connect before giving up.
Defaults to None
Defaults to 30s, can be set to None for no timeout.
`handler` is an optional function which can be provided to perform
requests to the 'gateway'.
Defaults to None, in which case an http or https request
Expand Down
2 changes: 2 additions & 0 deletions tests/test_exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def test_delete_with_groupingkey(self):
def test_push_with_handler(self):
def my_test_handler(url, method, timeout, headers, data):
headers.append(['X-Test-Header', 'foobar'])
# Handler should be passed sane default timeout
self.assertEqual(timeout, 30)
return default_handler(url, method, timeout, headers, data)
push_to_gateway(self.address, "my_job", self.registry, handler=my_test_handler)
self.assertEqual(self.requests[0][0].command, 'PUT')
Expand Down