From cc626041bdbe982b625023e29402a68b46b1194b Mon Sep 17 00:00:00 2001 From: Alex Perez-Pujol Date: Thu, 10 Sep 2020 19:08:17 +0200 Subject: [PATCH 1/2] fix(metrics): use rule as path Using the real path as metric created useless metrics. When using a dynamic rule, it creates unique paths with every metric, which makes it impossible to aggregate metrics to the same endpoint. --- pyms/flask/services/metrics.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyms/flask/services/metrics.py b/pyms/flask/services/metrics.py index 1525843..585036c 100644 --- a/pyms/flask/services/metrics.py +++ b/pyms/flask/services/metrics.py @@ -30,9 +30,14 @@ def before_request(self): # pylint: disable=R0201 request.start_time = time.time() def after_request(self, response): + if hasattr(request.url_rule, "rule"): + path = request.url_rule.rule + else: + path = request.path + request_latency = time.time() - request.start_time - FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, request.path, response.status_code).observe(request_latency) - FLASK_REQUEST_COUNT.labels(self.app_name, request.method, request.path, response.status_code).inc() + FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, path, response.status_code).observe(request_latency) + FLASK_REQUEST_COUNT.labels(self.app_name, request.method, path, response.status_code).inc() return response From 2cf592590009791c7acbf1bdf9ca0fe915dcf39d Mon Sep 17 00:00:00 2001 From: Alex Perez-Pujol Date: Thu, 10 Sep 2020 21:45:17 +0200 Subject: [PATCH 2/2] Bump ci --- pyms/flask/services/metrics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyms/flask/services/metrics.py b/pyms/flask/services/metrics.py index 585036c..fd00856 100644 --- a/pyms/flask/services/metrics.py +++ b/pyms/flask/services/metrics.py @@ -34,7 +34,6 @@ def after_request(self, response): path = request.url_rule.rule else: path = request.path - request_latency = time.time() - request.start_time FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, path, response.status_code).observe(request_latency) FLASK_REQUEST_COUNT.labels(self.app_name, request.method, path, response.status_code).inc()