Azure / Azure-Spring-Apps

Azure Spring Cloud
MIT License
8 stars 5 forks source link

GitHub Actions support for Spring Boot 3/Java 17 #33

Closed felipmiguel closed 1 year ago

felipmiguel commented 1 year ago

Describe the bug GitHub Action azure/spring-apps-deploy@v1 fails when targeting a Java 17 Spring Boot 3 application. The same application works fine if deployed from Azure cli (version 2.44)

To Reproduce Steps to reproduce the behavior:

  1. Create an application targeting Spring Boot 3.0
  2. Create an action that uses azure/spring-apps-deploy@v1 using a jar file. It can be deployed to Azure Spring Apps Basic or Standard
  3. Execute the action.
  4. The deployment fails
  5. Check application logs, for instance using az spring app logs command

An example can be found here https://github.com/felipmiguel/spring-petclinic-microservices/blob/3.0.0/.github/workflows/action.yml Failing action:

- name: Deploy api-gateway
      uses: azure/spring-apps-deploy@v1
      with:
        azure-subscription: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
        action: deploy
        service-name: ${{ secrets.SPRING_APPS_SERVICE_NAME }}
        app-name: ${{ env.API_GATEWAY }}
        use-staging-deployment: false
        package: ${{ github.workspace }}/${{ env.API_GATEWAY_JAR }}
        jvm-options: -Xms2048m -Xmx2048m
        runtime-version: Java_17
        environment-variables: -SPRING_PROFILES_ACTIVE passwordless

Expected behavior The application should be deployed and started normally. The same application has been deployed using the following command and it works:

az spring app deploy \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SPRING_CLOUD_SERVICE} \
        --name ${API_GATEWAY} \
        --artifact-path ${API_GATEWAY_JAR} \
        --jvm-options='-Xms2048m -Xmx2048m' \
        --runtime-version Java_17 \
        --env SPRING_PROFILES_ACTIVE=passwordless

Screenshots

Here the failed application logs:

Build in Environment Variables
BUILD_IN_EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=https://fmiguel-spring-petclinic.svc.azuremicroservices.io/eureka/eureka
BUILD_IN_SPRING_CLOUD_CONFIG_URI=https://fmiguel-spring-petclinic.svc.azuremicroservices.io/config
BUILD_IN_SPRING_CLOUD_CONFIG_FAILFAST=true
[Azure Spring Cloud] The following environment variables are loaded: SPRING_PROFILES_ACTIVE
Picked up JAVA_TOOL_OPTIONS:  -Xms2048m -Xmx2048m
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2023-01-16 10:28:25.157Z INFO  c.m.applicationinsights.agent - Application Insights Java Agent 3.4.4 started successfully (PID 1, JVM running for 9.397 s)
2023-01-16 10:28:25.232Z INFO  c.m.applicationinsights.agent - Java version: 17.0.5, vendor: Microsoft, home: /usr/lib/jvm/msopenjdk-17
10:28:36.658 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.ResponseEntity.getStatusCode()'
        at com.microsoft.azure.telemetry.TelemetrySender.sendTelemetryData(TelemetrySender.java:58)
        at com.microsoft.azure.telemetry.TelemetrySender.send(TelemetrySender.java:74)
        at com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessorHelper.sendTelemetry(KeyVaultEnvironmentPostProcessorHelper.java:219)
        at com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessorHelper.<init>(KeyVaultEnvironmentPostProcessorHelper.java:56)
        at com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessor.postProcessEnvironment(KeyVaultEnvironmentPostProcessor.java:40)
        at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:109)
        at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:94)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:352)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
        at org.springframework.samples.petclinic.api.ApiGatewayApplication.main(ApiGatewayApplication.java:50)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:95)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
10:28:36.733 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter -

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.microsoft.azure.telemetry.TelemetrySender.sendTelemetryData(TelemetrySender.java:58)

The following method did not exist:

    'org.springframework.http.HttpStatus org.springframework.http.ResponseEntity.getStatusCode()'

The calling method's class, com.microsoft.azure.telemetry.TelemetrySender, was loaded from the following location:

    jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/azure-spring-boot-2.3.0.jar!/com/microsoft/azure/telemetry/TelemetrySender.class

The called method's class, org.springframework.http.ResponseEntity, is available from the following locations:

    jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/spring-web-6.0.3.jar!/org/springframework/http/ResponseEntity.class

The called method's class hierarchy was loaded from the following locations:

    org.springframework.http.ResponseEntity: jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/spring-web-6.0.3.jar!/
    org.springframework.http.HttpEntity: jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/spring-web-6.0.3.jar!/

Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.microsoft.azure.telemetry.TelemetrySender and org.springframework.http.ResponseEntity

Additional context Also created an issue here https://github.com/Azure/spring-apps-deploy/issues/22

Can we contact you for additional details? Y/N

If yes, please send us your contact information to AzureSpringCloud-Talk@service.microsoft.com and include the issue number in the email title.

felipmiguel commented 1 year ago

The issue seems related to the application insights version attached to the application as seems to refer to azure-spring-boot-2.3.0.jar instead of azure-spring-boot.3.0.0

felipmiguel commented 1 year ago

I created a new Azure Spring Apps cluster and deployed again the application using azure/spring-apps-deploy Github action and this time it works. I think the issue happens with existing clusters, not new ones. My environment was for testing, but this solution (create a new cluster) cannot be applied in production environments.

felipmiguel commented 1 year ago

After reviewing the solution I realized that the version deployed with azure cli and the version deployed with github actions are not exactly the same. The failing version included an old version for one of the dependencies. Removing that dependency fixed the issue.