mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 23:23:50 +01:00
Add response time metrics for introspection requests (#16131)
See #16119
This commit is contained in:
parent
0aba4a4eaa
commit
6130afb862
2 changed files with 28 additions and 7 deletions
1
changelog.d/16131.misc
Normal file
1
changelog.d/16131.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add response time metrics for introspection requests for delegated auth.
|
|
@ -20,6 +20,7 @@ from authlib.oauth2.auth import encode_client_secret_basic, encode_client_secret
|
||||||
from authlib.oauth2.rfc7523 import ClientSecretJWT, PrivateKeyJWT, private_key_jwt_sign
|
from authlib.oauth2.rfc7523 import ClientSecretJWT, PrivateKeyJWT, private_key_jwt_sign
|
||||||
from authlib.oauth2.rfc7662 import IntrospectionToken
|
from authlib.oauth2.rfc7662 import IntrospectionToken
|
||||||
from authlib.oidc.discovery import OpenIDProviderMetadata, get_well_known_url
|
from authlib.oidc.discovery import OpenIDProviderMetadata, get_well_known_url
|
||||||
|
from prometheus_client import Histogram
|
||||||
|
|
||||||
from twisted.web.client import readBody
|
from twisted.web.client import readBody
|
||||||
from twisted.web.http_headers import Headers
|
from twisted.web.http_headers import Headers
|
||||||
|
@ -46,6 +47,13 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
introspection_response_timer = Histogram(
|
||||||
|
"synapse_api_auth_delegated_introspection_response",
|
||||||
|
"Time taken to get a response for an introspection request",
|
||||||
|
["code"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Scope as defined by MSC2967
|
# Scope as defined by MSC2967
|
||||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/2967
|
# https://github.com/matrix-org/matrix-spec-proposals/pull/2967
|
||||||
SCOPE_MATRIX_API = "urn:matrix:org.matrix.msc2967.client:api:*"
|
SCOPE_MATRIX_API = "urn:matrix:org.matrix.msc2967.client:api:*"
|
||||||
|
@ -190,6 +198,9 @@ class MSC3861DelegatedAuth(BaseAuth):
|
||||||
# Do the actual request
|
# Do the actual request
|
||||||
# We're not using the SimpleHttpClient util methods as we don't want to
|
# We're not using the SimpleHttpClient util methods as we don't want to
|
||||||
# check the HTTP status code, and we do the body encoding ourselves.
|
# check the HTTP status code, and we do the body encoding ourselves.
|
||||||
|
|
||||||
|
start_time = self._clock.time()
|
||||||
|
try:
|
||||||
response = await self._http_client.request(
|
response = await self._http_client.request(
|
||||||
method="POST",
|
method="POST",
|
||||||
uri=uri,
|
uri=uri,
|
||||||
|
@ -198,6 +209,15 @@ class MSC3861DelegatedAuth(BaseAuth):
|
||||||
)
|
)
|
||||||
|
|
||||||
resp_body = await make_deferred_yieldable(readBody(response))
|
resp_body = await make_deferred_yieldable(readBody(response))
|
||||||
|
except Exception:
|
||||||
|
end_time = self._clock.time()
|
||||||
|
introspection_response_timer.labels("ERR").observe(end_time - start_time)
|
||||||
|
raise
|
||||||
|
|
||||||
|
end_time = self._clock.time()
|
||||||
|
introspection_response_timer.labels(response.code).observe(
|
||||||
|
end_time - start_time
|
||||||
|
)
|
||||||
|
|
||||||
if response.code < 200 or response.code >= 300:
|
if response.code < 200 or response.code >= 300:
|
||||||
raise HttpResponseException(
|
raise HttpResponseException(
|
||||||
|
|
Loading…
Reference in a new issue