Fixes prometheus start metric
This commit is contained in:
parent
2d9ce6dbe3
commit
68c5384473
2 changed files with 17 additions and 4 deletions
|
@ -542,8 +542,9 @@ class EphemeralBuilderManager(BaseManager):
|
||||||
try:
|
try:
|
||||||
# log start time to prometheus
|
# log start time to prometheus
|
||||||
realm_data = yield From(self._etcd_client.read(self._etcd_realm_key(build_component.builder_realm)))
|
realm_data = yield From(self._etcd_client.read(self._etcd_realm_key(build_component.builder_realm)))
|
||||||
start_time = json.loads(realm_data.value)['start_time']
|
parsed_realm_data = json.loads(realm_data.value)
|
||||||
metric_queue.builder_time_to_build(time.time() - start_time, labelvalues=[realm_data.executor_name])
|
start_time = parsed_realm_data['start_time']
|
||||||
|
metric_queue.builder_time_to_build(time.time() - start_time, labelvalues=[parsed_realm_data.get('executor_name', 'unknown')])
|
||||||
except (KeyError, etcd.EtcdKeyError):
|
except (KeyError, etcd.EtcdKeyError):
|
||||||
logger.warning('Could not read realm key %s', build_component.builder_realm)
|
logger.warning('Could not read realm key %s', build_component.builder_realm)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from trollius import coroutine, Return, get_event_loop
|
from trollius import coroutine, Return, get_event_loop, From
|
||||||
|
|
||||||
from util.metrics.metricqueue import duration_collector_async
|
from util.metrics.metricqueue import duration_collector_async
|
||||||
|
|
||||||
|
@ -25,6 +25,10 @@ def duration_decorated():
|
||||||
def duration_decorated_error():
|
def duration_decorated_error():
|
||||||
raise NonReturn("not a Return error")
|
raise NonReturn("not a Return error")
|
||||||
|
|
||||||
|
@coroutine
|
||||||
|
def calls_decorated():
|
||||||
|
yield From(duration_decorated())
|
||||||
|
|
||||||
|
|
||||||
class DurationDecoratorTestCase(unittest.TestCase):
|
class DurationDecoratorTestCase(unittest.TestCase):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -44,7 +48,15 @@ class DurationDecoratorTestCase(unittest.TestCase):
|
||||||
with self.assertRaises(NonReturn):
|
with self.assertRaises(NonReturn):
|
||||||
self.loop.run_until_complete(duration_decorated_error())
|
self.loop.run_until_complete(duration_decorated_error())
|
||||||
assert not mock_histogram.Observe.called
|
assert not mock_histogram.Observe.called
|
||||||
|
|
||||||
|
def test_duration_decorator_caller(self):
|
||||||
|
mock_histogram.reset_mock()
|
||||||
|
|
||||||
|
self.loop.run_until_complete(calls_decorated())
|
||||||
|
assert mock_histogram.Observe.called
|
||||||
|
assert 1 - mock_histogram.Observe.call_args[0][0] < 1 # duration should be close to 1s
|
||||||
|
assert mock_histogram.Observe.call_args[1]["labelvalues"] == ["testlabel"]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Reference in a new issue