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

Skip to content

Commit cc62604

Browse files
committed
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.
1 parent 893f14b commit cc62604

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pyms/flask/services/metrics.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ 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
37+
3338
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()
39+
FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, path, response.status_code).observe(request_latency)
40+
FLASK_REQUEST_COUNT.labels(self.app_name, request.method, path, response.status_code).inc()
3641

3742
return response
3843

0 commit comments

Comments
 (0)
0