keycloak-metrics-spi: Seems incompatible with Keycloak 21

Description

After having migrated to Keycloak 21 (Quarkus) I get “Internal Server Error” whenever I try to login. The logs show messages like these:

ERROR [io.quarkus.vertx.http.runtime.QuarkusErrorHandler] (executor-thread-7) HTTP Request to /auth/realms/jake/metrics failed, error id: fdebc248-5921-4c51-8db2-2bcbcff3607e-57: org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalArgumentException: Failed to register Collector of type Counter: keycloak_login_attempts_total is already in use by another Collector of type Counter

Keycloak 21 changed metrics implementation from SmallRye to Micrometer, maybe this clashes with this project somehow?

Steps to reproduce

  1. Install and enable keycloak-metrics-spi v2.5.3 on Keycloak 20
  2. Migrate to Keycloak 21
  3. Attempt to login to the admin console

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 20
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

IHMO this repository is abandoned.

We relied on this implementation, but decided to rewrite it for Keycloak 21: kokuwaio/keycloak-event-metrics This implementation adds event metrics to Micrometer from Quarkus at /metrics.

Differences:

  • no Prometheus push (event listener only adds counter to Micrometer)
  • no realm specific Prometheus endpoint, only /metrics
  • no http metrics, this is already included in Keycloak
  • different metric names, see readme
  • deployed to maven central

Feel free to provide feedback.

@ghenadiibatalski has submitted a fix and I’ve verified it with KC 19, 20 and 21. I want to get it merged and released as soon as possible.

It appears that key cloak now natively incudes a /metrics endpoint in prometheus format with Keycloak 21 so it may be that this project is no longer needed for Keycloak 21+: https://www.keycloak.org/2023/02/keycloak-2100-released.html

Yes 🤦 Sorry, I forgot that, too used to gradle. Will send a PR.

@logopk i only needed to remove _total from the metric name. as i understand, _total is a reserved suffix now. The keycloak 21 ships the prometheus 0.16.0 so i updated the PR to keycloak 21 I don’t know, if it could be backported for both versions. But the previous build is good enough for older Keycloak and the new one is compatible from 21 upwards.