aerogear / keycloak-metrics-spi

Adds a Metrics Endpoint to Keycloak
Apache License 2.0
526 stars 151 forks source link

Make metrics-spi usable with Keycloak and Keycloak.X with 15.0.2 #120

Closed thomasdarimont closed 2 years ago

thomasdarimont commented 2 years ago

Motivation

Currently the keycloak-metrics-spi does not work with Keycloak.X because the MetricsEndpointFactory explicitly registers a MetricsFilter instance via the ResteasyProviderFactory, that uses Resteasy 3 API, which is not available in Keycloak.X.

What

Add a workaround to be able to use keycloak-metrics-spi with Keycloak and Keycloak.X.

Why

keycloak-metrics-spi did not work with Keycloak.X,

How

This PR adds a guard around the MetricsFilter registration in the MetricsEndpointFactory, which uses the Resteasy 3 API only if available.

To register the MetricsFilter in Keycloak.X environments, we use the JAX-RS providers support of of the Quarkus platform, which dynamically discovers and registers the MetricsFilterProvider, which delegates filter invocations to the MetricsFilter instance.

Verification Steps

Add the steps required to check this change. Following an example.

  1. Build the .jar
  2. Deploy the jar to Keycloak
  3. Deploy the jar to Keycloak.X
  4. Verify both servers can start and expose the metrics endpoint
  5. Login to the Keycloak admin-console and inspect http://localhost:8080/realms/realms/master/metrics
  6. Login to the Keycloak.X admin-console and inspect http://localhost:8080/realms/master/metrics

Checklist

[x] Code has been tested locally by PR requester [] Changes have been successfully verified by another team member

Progress

[x] Finished task

Additional Notes

Updated the keycloak version to 15.0.2 Updated the prometheus client version to 0.12.0 Fixed broken references in readme

Fixes https://github.com/aerogear/keycloak-metrics-spi/issues/107

pb82 commented 2 years ago

thanks @thomasdarimont , much appreciated. Will this retain compatibility with non X / older Keycloak versions?

thomasdarimont commented 2 years ago

@pb82 you're welcome :) I tested this with Keycloak.X 15.0.2 and Keycloak 15.0.2. A wildfly / JBoss EAP based Keycloak server will ignore the annotated MetricsFilterProvider.

pb82 commented 2 years ago

:+1: I'll try it with an older version, then it should be good to go

Alexcei88 commented 2 years ago

When will fixes be merged?

Looks like I faced with the same problem on Keycloak 15.0.0

semangard commented 2 years ago

@pb82 : The extension currently prevents KeyCloak 16.0.0 from starting, is it possible to merge it quickly please ?

pb82 commented 2 years ago

Some unit tests are failing, i'm looking into this now. Will merge once I have them passing or updated.

pb82 commented 2 years ago

@thomasdarimont failing tests are caused by the upgrade of prometheus client. This causes some of the metric names to change. I'll merge this, but keep the Prometheus version at 0.9.0 as this would be a breaking change otherwise. We can upgrade that in a separate release.