aerogear / keycloak-metrics-spi

Adds a Metrics Endpoint to Keycloak
Apache License 2.0
530 stars 152 forks source link

zip END header not found: cannot deploy in kubernetes environment #88

Closed micst closed 3 years ago

micst commented 3 years ago

We have a HA deployment in kuberenetes, the keycloak docker image is adapted to include the metrics jar file. When starting up I get the following log messages:

15:24:04,336 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 1) WFLYDR0001: Content added at location /opt/jboss/keycloak/standalone/data/content/ea/2903a5d4983483d20e0c7e3cf6c422e89208f8/content 15:24:04,347 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "keycloak-metrics-spi-2.1.0.jar" (runtime-name: "keycloak-metrics-spi-2.1.0.jar")
15:24:04,351 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."keycloak-metrics-spi-2.1.0.jar".STRUCTURE: org.jboss.msc.service.StartException in service jboss.deployment.unit."keycloak-metrics-spi-2.1.0.jar".STRUCTURE: WFLYSRV0153: Failed to process phase STRUCTURE of deployment "keycloak-metrics-spi-2.1.0.jar"
        at org.jboss.as.server@12.0.3.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
        at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
        at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
        at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
        at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
        at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYSRV0160: Failed to mount deployment content
        at org.jboss.as.server@12.0.3.Final//org.jboss.as.server.deployment.module.DeploymentRootMountProcessor.deploy(DeploymentRootMountProcessor.java:95)
        at org.jboss.as.server@12.0.3.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
        ... 8 more
Caused by: java.util.zip.ZipException: zip END header not found
        at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1567)
        at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1462)
        at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1469)
        at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1274)
        at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1237)
        at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:727)
        at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:844)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:247)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:177)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:348)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:319)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:285)
        at org.jboss.vfs@3.2.15.Final//org.jboss.vfs.spi.JavaZipFileSystem.<init>(JavaZipFileSystem.java:90)
        at org.jboss.vfs@3.2.15.Final//org.jboss.vfs.spi.JavaZipFileSystem.<init>(JavaZipFileSystem.java:77)
        at org.jboss.vfs@3.2.15.Final//org.jboss.vfs.VFS.mountZip(VFS.java:386)
        at org.jboss.vfs@3.2.15.Final//org.jboss.vfs.VFS.mountZip(VFS.java:410)
        at org.jboss.as.server@12.0.3.Final//org.jboss.as.server.deployment.DeploymentMountProvider$Factory$ServerDeploymentRepositoryImpl.mountDeploymentContent(DeploymentMountProvider.java:108)
        at org.jboss.as.server@12.0.3.Final//org.jboss.as.server.deployment.module.DeploymentRootMountProcessor.deploy(DeploymentRootMountProcessor.java:91)
        ... 9 more

15:24:04,354 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "keycloak-metrics-spi-2.1.0.jar")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"keycloak-metrics-spi-2.1.0.jar\".STRUCTURE" => "WFLYSRV0153: Failed to process phase STRUCTURE of deployment \"keycloak-metrics-spi-2.1.0.jar\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYSRV0160: Failed to mount deployment content
    Caused by: java.util.zip.ZipException: zip END header not found"}}
15:24:04,355 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "keycloak-metrics-spi-2.1.0.jar" (runtime-name : "keycloak-metrics-spi-2.1.0.jar")
15:24:04,356 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit."keycloak-metrics-spi-2.1.0.jar".STRUCTURE: WFLYSRV0153: Failed to process phase STRUCTURE of deployment "keycloak-metrics-spi-2.1.0.jar"

Any Ideas how I could solve this?

pb82 commented 3 years ago

Have you tried using a different version of the plugin? Same behavior in that case?

micst commented 3 years ago

My fault, everything works fine. I just found out yesterday. We extend the original docker image from jboss/keycloak to add the metrics listener to avoid complex init container configuration like this:

# install prometheus metrics provider
ENV providerProjectUrl https://github.com/aerogear/keycloak-metrics-spi
ENV providerVersion 2.1.0
ENV providerFileName keycloak-metrics-spi-${providerVersion}.jar
ENV providerFileUrl ${providerProjectUrl}/releases/download/${providerVersion}/${providerFileName}
RUN echo "=== installing metric provider ===" \
  && cd /opt/jboss/keycloak/standalone/deployments \
  && curl -s -k -L --output ${providerFileName} ${providerFileUrl}  \
  && touch ${providerFileName}.dodeploy

I was missing the -L parameter in the curl command, got no error and saw that something was downloaded. Never checked if the downloaded file actually was a real .jar. It was not obviously. It was some html code telling me I hit a redirect. Simply adding -L to the curl command line fixed everything. Sorry for any inconvenience and thanks for the answer!

RomainPhil commented 2 years ago

Got the same issue with using the init container and wget

if you use helm of codecentric this is an exemple which work:

extraInitContainers: |
  - name: download-metric-spi
    image: curlimages/curl:latest
    command: 
      - 'sh'
    args: 
      - -c
      -  | 
        curl -s -k -L --output /metrics/keycloak-metrics-spi-2.1.0.jar https://github.com/aerogear/keycloak-metrics-spi/releases/download/2.1.0/keycloak-metrics-spi-2.1.0.jar
        touch /metrics/keycloak-metrics-spi-2.1.0.jar.dodeploy
    volumeMounts:
      - name: metrics
        mountPath: /metrics
extraVolumes: |
  - name: metrics
    emptyDir: {}
extraVolumeMounts: | 
  - name: metrics
    mountPath: /opt/jboss/keycloak/standalone/deployments/