Skip to content

Commit

Permalink
Send metrics to count endpoints with method and status
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Oct 28, 2024
1 parent 67aab85 commit 362e694
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kinto/core/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
unique=[
("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}")
Expand Down
9 changes: 9 additions & 0 deletions tests/core/test_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 362e694

Please sign in to comment.