Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Keycloak 19 fix realm name #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

diversit
Copy link

@diversit diversit commented Sep 7, 2022

Motivation

In Keycloak 19 the 'realm' in the metrics contain a UUID instead of the Realm name.
Apparently Keycloak changed the value of event.getRealmId() from a Realm name to a real Realm id.

What

This change will fix this by looking up the Realm by Id via a RealmProvider so the metrics will still contain a Realm name.

Upgraded Keycloak dependency to 19.0.1 to also verify this library is not using any deprecated sources.
Removed the MetricsEventListenerSpi since this seems to be an old way of adding a listener and is not needed anymore for v19 Quarkus Keycloak.

Why

To have readable realm names in the metrics and on the Keycloak dashboard.

How

Realm name is looked up by using a RealmProvider which is accessible from the KeycloakSession when the MetricsEventListenerFactory is created.

Verification Steps

  1. Build the package, include it in a custom Keycloak 19+ image and start the container.
  2. Login into the admin console
  3. Enable metrics-listener for events in the Realm settings.
  4. Logout
  5. Log back into admin console
  6. Run curl -vk https://<keycloak-url>:<port>/auth/realms/master/metrics | grep -v '^#' | grep login and check metrics output.
    The metrics should still contain the realm name like
keycloak_logins{realm="admin",provider="keycloak",client_id="account-console",} 1.0

Checklist:

  • Code has been tested locally by PR requester
  • Changes have been successfully verified by another team member

Progress

  • Finished task
  • TODO

@@ -64,6 +64,12 @@
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waarom mockito er bij? Die wordt niet gebruikt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wordt in PrometheusExporterTest gebruikt om een Realm provider te mocken.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants