From 517a7e9d1f24d5844921d875707eaa74dc748b44 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Thu, 24 Oct 2024 12:57:55 +0200 Subject: [PATCH] Send metrics to count endpoints with method and status --- kinto/core/initialization.py | 10 ++++++++++ tests/core/test_initialization.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/kinto/core/initialization.py b/kinto/core/initialization.py index 643551681..b721664be 100644 --- a/kinto/core/initialization.py +++ b/kinto/core/initialization.py @@ -481,6 +481,16 @@ def on_new_response(event): auth, user_id = user_id.split(":") metrics_service.count("users", unique=[("auth", auth), ("userid", user_id)]) + # Count served requests. + metrics_service.count( + "request_summary", + [ + ("method", request.method.lower()), + ("endpoint", utils.strip_uri_prefix(request.path)), + ("status", str(request.response.status_code)), + ], + ) + # Count authentication verifications. if hasattr(request, "authn_type"): metrics_service.count(f"authn_type.{request.authn_type}") diff --git a/tests/core/test_initialization.py b/tests/core/test_initialization.py index 3801ae919..aaaa8dc5c 100644 --- a/tests/core/test_initialization.py +++ b/tests/core/test_initialization.py @@ -404,6 +404,15 @@ def test_statsd_counts_nothing_on_anonymous_requests(self): app.get("/") self.assertFalse(self.mocked.count.called) + def test_statsd_counts_endpoints(self): + kinto.core.initialize(self.config, "0.0.1", "settings_prefix") + app = webtest.TestApp(self.config.make_wsgi_app()) + app.get("/v0/__heartbeat__") + self.mocked().count.assert_any_call( + "request_summary", + [("method", "get"), ("endpoint", "/__heartbeat__"), ("status", "200")], + ) + def test_statsd_counts_views_and_methods(self): kinto.core.initialize(self.config, "0.0.1", "settings_prefix") app = webtest.TestApp(self.config.make_wsgi_app())