def measure_job_duration(job, final_status): labels = { "dotted_name": job.function_name, "final_status": final_status, "container_id": job.data.get("container_id"), } duration = time.time() - job._started metric_measure(amqp_job_duration, duration, labels)
def measure_job_duration(job, final_status): labels = { 'dotted_name': job.function_name, 'final_status': final_status, 'container_id': job.data.get('container_id'), } duration = time.time() - job._started metric_measure(amqp_job_duration, duration, labels)
def test_metric_measure(): # Measure with None metric just returns metric_measure(None, "foo", "bar") # Measure fills labels and observe histogram = MockPrometheusMetric(["label1", "label2"]) metric_measure(histogram, 20, {"label1": "foo", "label2": "bar"}) assert histogram.labels_called assert histogram.observe_called assert histogram._labels["label1"] == "foo" assert histogram._labels["label2"] == "bar" assert histogram._values == [20]
def test_metric_measure(): # Measure with None metric just returns metric_measure(None, 'foo', 'bar') # Measure fills labels and observe histogram = MockPrometheusMetric(['label1', 'label2']) metric_measure(histogram, 20, { 'label1': 'foo', 'label2': 'bar', }) assert histogram.labels_called assert histogram.observe_called assert histogram._labels['label1'] == 'foo' assert histogram._labels['label2'] == 'bar' assert histogram._values == [20]
def measure_running_jobs(currently_running): metric_measure(amqp_running_jobs, currently_running)