Skip to content

Commit

Permalink
Add auth_api_calls_total and auth_api_calls_total
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Mar 8, 2024
1 parent 7639200 commit fa546fa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
9 changes: 9 additions & 0 deletions docs/reference/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ Queries and compilation
GraphQL query, ``=sql`` for a readonly SQL query from the user, and
``=compiled`` for a backend SQL query compiled and issued by the server.

Auth Extension
^^^^^^^^^^^^^^

``auth_api_calls_total``
**Counter.** Number of API calls to the Auth extension.

``auth_ui_renders_total``
**Counter.** Number of UI pages rendered by the Auth extension.

Errors
^^^^^^

Expand Down
12 changes: 12 additions & 0 deletions edb/server/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,15 @@
"Number of each high-availability watch event.",
labels=("dsn", "event"),
)

auth_api_calls = registry.new_labeled_counter(
"auth_api_calls_total",
"Number of API calls to the Auth extension.",
labels=("tenant",),
)

auth_ui_renders = registry.new_labeled_counter(
"auth_ui_renders_total",
"Number of UI pages rendered by the Auth extension.",
labels=("tenant",),
)
21 changes: 16 additions & 5 deletions edb/server/protocol/protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,18 @@ cdef class HttpProtocol:
def connection_lost(self, exc):
srv_metrics.client_connection_duration.observe(
time.monotonic() - self.connection_made_at,
(
"unknown"
if self.tenant is None
else self.tenant.get_instance_name()
),
self.get_tenant_label(),
"http",
)
self.transport = None
self.unprocessed = None

def get_tenant_label(self):
if self.tenant is None:
return "unknown"
else:
return self.tenant.get_instance_name()

def pause_writing(self):
pass

Expand Down Expand Up @@ -656,6 +658,15 @@ cdef class HttpProtocol:
tenant=self.tenant,
)
await handler.handle_request(request, response, args)
if args:
if args[0] == 'ui':
srv_metrics.auth_ui_renders.inc(
1.0, self.get_tenant_label()
)
else:
srv_metrics.auth_api_calls.inc(
1.0, self.get_tenant_label()
)

elif route == 'auth':
if await self._handle_cors(
Expand Down

0 comments on commit fa546fa

Please sign in to comment.