aerogear / keycloak-metrics-spi

Adds a Metrics Endpoint to Keycloak
Apache License 2.0
549 stars 156 forks source link

MGDSTRM-3724 Add the status code to the keycloak_request_duration_bucket metric #108

Closed CathalOConnorRH closed 3 years ago

CathalOConnorRH commented 3 years ago

Motivation

https://issues.redhat.com/browse/MGDSTRM-3724 https://issues.redhat.com/browse/MGDSTRM-4318

What

Add status code and uri to the keycloak_request_duration_bucket metric

Why

This will allow filtering on specific statuses Currently no status are returned in the metric keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="50.0",} 0.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="100.0",} 0.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="250.0",} 0.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="500.0",} 0.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="1000.0",} 1.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="2000.0",} 1.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="10000.0",} 1.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="30000.0",} 1.0 keycloak_request_duration_bucket{method="POST",resource="realms,realms/master/protocol/openid-connect",le="+Inf",} 1.0 keycloak_request_duration_count{method="POST",resource="realms,realms/master/protocol/openid-connect",} 1.0 keycloak_request_duration_sum{method="POST",resource="realms,realms/master/protocol/openid-connect",} 625.0

How

added status code and uri to the to the bucket output.

Verification Steps

Option 1

  1. Build the code
  2. Copy the artifact into $KC/standalone/deployments
  3. Make sure the metrics logger is turned on
  4. Play with Keycloak a bit
  5. Look at the following url: "$KC/auth/realms/master/metrics"

Option 2

update keycloak cr to use the jar built and released from my fork https://github.com/CathalOConnorRH/keycloak-metrics-spi/releases/tag/v2.4.1-beta

Metrics should look similar to keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="50.0",} 0.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="100.0",} 0.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="250.0",} 1.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="500.0",} 1.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="1000.0",} 1.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="2000.0",} 1.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="10000.0",} 1.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="30000.0",} 1.0 keycloak_request_duration_bucket{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",le="+Inf",} 1.0 keycloak_request_duration_count{code="200",method="POST",resource="realms,realms/master/protocol/openid-connect",uri="realms/master/protocol/openid-connect/token",} 1.0

Checklist:

Progress

Additional Notes

PS.: Add images and/or .gifs to illustrate what was changed if this pull request modifies the appearance/output of something presented to the users.

Rajagopalan-Ranganathan commented 3 years ago

/lgtm

akoserwal commented 3 years ago

@pb82 Would like to take a look as well?

akoserwal commented 3 years ago

LGTM

pb82 commented 3 years ago

@CathalOConnorRH if it is absolutely required to add those labels to the histogram, can we make that opt-in behind a flag?

CathalOConnorRH commented 3 years ago

@pb82 I've updated the ResourceExtractor to include a URI_METRICS_ENABLED boolean and a check for /token URI. an example of the metrics output is attached

Let me know what you think

KeycloakMetrics.txt

CathalOConnorRH commented 3 years ago

Hey @pb82 Have you had any thoughts on the above changes ?

pb82 commented 3 years ago

thanks @CathalOConnorRH I'll give it a final try and then merge

Rajagopalan-Ranganathan commented 3 years ago

@pb82 did you find time to try it out? Just curious about the status. Thanks!

CathalOConnorRH commented 3 years ago

@pb82 I've implemented the detailed output and removed the uri when it's not enabled. Some sample output of each of the three scenarios are attached. Let me know what you think
URIEnabledURIDetailed.txt URIDisabled.txt URIEnabled.txt

Rajagopalan-Ranganathan commented 3 years ago

@pb82 We need this change in MAS SSO soon, to build some metrics - dashboards and also to investigate and get precise information regarding our load (which end points are used most). Can you take a look and close this at the earliest?