L21s / keycloak-monitoring-prometheus

Monitor your keycloak with prometheus
MIT License
64 stars 17 forks source link

java.lang.IndexOutOfBoundsException very noisy #7

Closed hypery2k closed 5 years ago

hypery2k commented 5 years ago

Thanks for the plugin. We have some issues, we got this message very often:


13:59:59,081 ERROR [org.keycloak.events.EventBuilder] (default task-16) Failed to send type to com.larscheidschmitzhermes.keycloak.events.MonitoringEventListenerProvider@672e879c: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 |  
-- | --
  | at java.util.ArrayList.rangeCheck(ArrayList.java:657)
  | at java.util.ArrayList.get(ArrayList.java:433)
  | at com.larscheidschmitzhermes.keycloak.events.MonitoringEventListenerProvider.increaseCounter(MonitoringEventListenerProvider.java:86)
  | at com.larscheidschmitzhermes.keycloak.events.MonitoringEventListenerProvider.onEvent(MonitoringEventListenerProvider.java:32)
  | at org.keycloak.events.EventBuilder.send(EventBuilder.java:187)
  | at org.keycloak.events.EventBuilder.success(EventBuilder.java:156)
  | at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.resourceOwnerPasswordCredentialsGrant(TokenEndpoint.java:536)
  | at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.processGrantRequest(TokenEndpoint.java:176)
  | at sun.reflect.GeneratedMethodAccessor392.invoke(Unknown Source)
  | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  | at java.lang.reflect.Method.invoke(Method.java:498)
  | at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
  | at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
  | at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
  | at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:138)
  | at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:107)
  | at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:133)
  | at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:101)
  | at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
  | at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:213)
  | at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
  | at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
  | at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
  | at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
  | at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
  | at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
  | at org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:90)
  | at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
  | at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
  | at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
  | at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
  | at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:65)
  | at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
  | at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
  | at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  | at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
  | at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
  | at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  | at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
  | at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
  | at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
  | at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
  | at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
  | at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
  | at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  | at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
  | at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  | at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
  | at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  | at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
  | at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
  | at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
  | at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
  | at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
  | at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
  | at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
  | at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
  | at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
  | at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
  | at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
  | at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
  | at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
  | at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
  | at io.undertow.server.Connectors.executeRootHandler(Connectors.java:330)
  | at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
  | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  | at java.lang.Thread.run(Thread.java:748)

I think it's related to threading issues for the file write

tobilarscheid commented 5 years ago

Hi Martin, which release of the Plugin are you using?

hypery2k commented 5 years ago

1.1.0 Is there a new version available?

tobilarscheid commented 5 years ago

No, sorry, I thought I saw that issue in an earlier version, but I was mistaken. I think the problem appears when you have more than one realm, a setup I never used. What do you think about providing a PR with a fix? Best case it should be a matter of just wrapping the file access in a synchronized method - and you have the setup to test!

hypery2k commented 5 years ago

If added a PR. Seems to work for me.

BTW: Did you intent to add more event details, like ip etc to each entry?

tobilarscheid commented 5 years ago

Thank you for your PR, just merged and released it.

Regarding more event details: I did not really think about it, but it sounds useful. I just don't know if the standard keycloak events I am using do support the details you mention? If yes, feel free to PR - I would be happy to merge!

hypery2k commented 5 years ago

cool, we'll do this ;)

hypery2k commented 5 years ago

BTW: Could you post the JAR directly under GitHub Releases?

tobilarscheid commented 5 years ago

Why would you want that? You can directly download the jar from jitpack like so: https://jitpack.io/com/github/larscheid-schmitzhermes/keycloak-monitoring-prometheus/1.2.0/keycloak-monitoring-prometheus-1.2.0.jar