8000 fix(metrics): use rule as path (#150) · python-microservices/pyms@03de4f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03de4f4

Browse files
authored
fix(metrics): use rule as path (#150)
* 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. * Bump ci
1 parent 893f14b commit 03de4f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pyms/flask/services/metrics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ def before_request(self): # pylint: disable=R0201
3030
request.start_time = time.time()
3131

3232
def after_request(self, response):
33+
if hasattr(request.url_rule, "rule"):
34+
path = request.url_rule.rule
35+
else:
36+
path = request.path
3337
request_latency = time.time() - request.start_time
34-
FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, request.path, response.status_code).observe(request_latency)
35-
FLASK_REQUEST_COUNT.labels(self.app_name, request.method, request.path, response.status_code).inc()
38+
FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, path, response.status_code).observe(request_latency)
39+
FLASK_REQUEST_COUNT.labels(self.app_name, request.method, path, response.status_code).inc()
3640

3741
return response
3842

0 commit comments

Comments
 (0)
0