aerogear / keycloak-metrics-spi

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

Cant get request duration metrics #134

Open arbizier01 opened 2 years ago

arbizier01 commented 2 years ago

Description

My keycloak Metrics SPI deploys without any errors but I dont get any values for the request_duration histogram

Expected Behavior

I should get the normal histogram for request duration

Environment

Steps to reproduce

I deployed the metrics-spi as per instructions with no errors, but not all the metrics get scraped, they are just missing.

Here are the logs form the deployment: 2022-04-28 10:30:56,261 INFO [org.keycloak.subsystem.server.extension.KeycloakProviderDeploymentProcessor] (MSC service thread 1-3) Undeploying Keycloak provider: keycloak-metrics-spi-2.5.3-SNAPSHOT.jar 2022-04-28 10:30:56,266 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0028: Stopped deployment keycloak-metrics-spi-2.5.3-SNAPSHOT.jar (runtime-name: keycloak-metrics-spi-2.5.3-SNAPSHOT.jar) in 74ms 2022-04-28 10:31:00,977 INFO [org.wildfly.extension.metrics] (ServerService Thread Pool -- 47) WFLYMETRICS0001: Activating Base Metrics Subsystem 2022-04-28 10:31:01,925 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "keycloak-metrics-spi-2.5.3-SNAPSHOT.jar" (runtime-name: "keycloak-metrics-spi-2.5.3-SNAPSHOT.jar") 2022-04-28 10:31:02,282 WARN [org.jboss.as.dependency.private] (MSC service thread 1-1) WFLYSRV0018: Deployment "deployment.keycloak-metrics-spi-2.5.3-SNAPSHOT.jar" is using a private module ("org.keycloak.keycloak-services") which may be changed or removed in future versions without notice. 2022-04-28 10:31:02,298 INFO [org.keycloak.subsystem.server.extension.KeycloakProviderDeploymentProcessor] (MSC service thread 1-4) Deploying Keycloak provider: keycloak-metrics-spi-2.5.3-SNAPSHOT.jar 2022-04-28 10:31:07,664 WARN [org.keycloak.services] (ServerService Thread Pool -- 58) KC-SERVICES0047: metrics-listener (org.jboss.aerogear.keycloak.metrics.MetricsEventListenerFactory) is implementing the internal SPI eventsListener. This SPI is internal and may change without notice 2022-04-28 10:31:07,669 WARN [org.keycloak.services] (ServerService Thread Pool -- 58) KC-SERVICES0047: metrics (org.jboss.aerogear.keycloak.metrics.MetricsEndpointFactory) is implementing the internal SPI realm-restapi-extension. This SPI is internal and may change without notice 2022-04-28 10:31:13,502 INFO [org.jboss.as.server] (ServerService Thread Pool -- 33) WFLYSRV0010: Deployed "keycloak-metrics-spi-2.5.3-SNAPSHOT.jar" (runtime-name : "keycloak-metrics-spi-2.5.3-SNAPSHOT.jar")

For Logins, Errors and some other metrics it works fine but request_duration is not logged as it seems, what could provoke this problem, or what else do you need from me?

jfiedler-jaconi commented 2 years ago

Same issue here (using Keycloak 18.0.1-legacy). I checked recent changes and found this interesting commit that tried to prepare things for Keycloak.X: https://github.com/aerogear/keycloak-metrics-spi/pull/120

Part of the changes was to make the registration of MetricsFilter conditional based on a check against the version number of the underlying Keycloak RestEasy version. The old way of registering is used for RestEasy 3.x only (after the change). It seems that Keycloak 15.0.0 was using RestEasy 3.x.

I checked a Keycloak 16.0.0 Docker image and found that it started using RestEasy 4.x under the covers (at least I found only 4.x jars in the file system). This means that starting with Keycloak 16 this version check will not register the MetricFilter the old way anymore. I have no idea whether the "new way" of using the MetricsFilterProvider works with Keycloak 16 or whether this is limited to Keycloak X distribution.

davidpiendl commented 1 year ago

I am facing the same issue with keycloak-metrics-spi-2.5.4-SNAPSHOT (2.5.3 tagged sources) and Keycloak 19.0.1-legacy. All other metrics we set up in our dashboards are available, but keycloak_request_duration is not available anymore. I built the SPI on ourselfs with keycloakVersion=19.0.1 and prometheusVersion=0.9.0

Did we I anything wrong? Did someone else find a solution?

jtama commented 1 year ago

Same here, with same images

parthiban1610 commented 1 year ago

Facing same issue, Im using keycloak 16.1.1 , have anyone found a way to fix this .

chipironcin commented 1 year ago

Has anyone tried the latest version of the spi? 3.0.0

gouravsw commented 1 year ago

@chipironcin I have used the 3.0.0 spi version. In this version getting request duration metrics like keycloak_request_duration.bucket, keycloak_request_duration.count, keycloak_request_duration.sum, keycloak_request_duration_created

Registration metrics is missing in UI. But when port forwarding/exposing endpoint auth/realms/chimera/metrics. In that list getting registration metrics.

keycloak_registrations_total keycloak_registrations_errors_total

dbaumgarten commented 1 year ago

Is there still no fix available? I just updated from Keycloak 15 to 18.0.2 and with that the request_duration metric stopped working. Every other metric seems to work just fine. Tried it with both 2.5.3 and 3.0.0. Same result on both.

Update: I compiled the metrics-spi myself and removed the if condition @jfiedler-jaconi pointed out. Sadly it did not change anything.

chipironcin commented 11 months ago

This is how we fixed it in Docker, hope it helps everybody with this issue:

RUN git clone --depth 1 --branch 2.5.3 https://github.com/aerogear/keycloak-metrics-spi.git
WORKDIR /keycloak-metrics-spi
# make required changes to keycloak metrics spi for keycloak 19 
RUN sed -i 's/"3."/"4."/' src/main/java/org/jboss/aerogear/keycloak/metrics/MetricsEndpointFactory.java
RUN sed -i 's/15.0.2/19.0.3/' gradle.properties
# build keycloak metrics spi
RUN ./gradlew build