Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] CloudEvent not compatible with schema #40135

Closed
3 tasks done
joahuber opened this issue May 13, 2024 · 7 comments · Fixed by #40332
Closed
3 tasks done

[BUG] CloudEvent not compatible with schema #40135

joahuber opened this issue May 13, 2024 · 7 comments · Fixed by #40332
Labels
Azure.Core azure-core azure-spring All azure-spring related issues azure-spring-eventgrid Issues related to Spring Event Grid bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Grid needs-team-attention This issue needs attention from Azure service team or SDK team

Comments

@joahuber
Copy link

joahuber commented May 13, 2024

Describe the bug
The com.azure.core.models.CloudEvent class is not compatible with the EventGrid events anymore. This is an issue since version 5.9.0.

Exception or Stack Trace


com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: (String)"[{
     "specversion": "1.0",
     "type": "Microsoft.Storage.BlobCreated",  
     "source": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account}",
     "id": "9aeb0fdf-c01e-0131-0922-9eb54906e209",
     "time": "2019-11-18T15:13:39.4589254Z",
     "subject": "blobServices/default/containers/{storage-container}/blobs/{new-file}",    
     "data": {
         "api": "PutBlockList",
         "clientRequestId": "4c5dd7fb-2c48"[truncated 508 chars]; line: 8, column: 14] (through reference chain: java.util.ArrayList[0]->com.azure.core.models.CloudEvent["data"])

	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1752)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1526)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1431)
	at com.fasterxml.jackson.databind.DeserializationContext.extractScalarFromObject(DeserializationContext.java:943)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseString(StdDeserializer.java:1424)
	at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:48)
	at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:314)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:359)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:28)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4825)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3772)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3755)
	at com.galenica.gaas.portal.common.apis.eventhub.consumers.EventHubConsumerServiceTest.given_validEventMessage_when_subscriptionCreatedEventPublished_then_eventCanBeParsed(EventHubConsumerServiceTest.java:48)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

To Reproduce
Try parsing a sample json event, e.g. https://learn.microsoft.com/en-us/azure/event-grid/cloud-event-schema#sample-event-using-cloudevents-schema with a version >5.8.0.

Code Snippet
Unit test to reproduce:

package com.galenica.gaas.portal.common.apis.eventhub.consumers;


import com.azure.core.models.CloudEvent;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;

public class EventHubConsumerServiceTest {
    @Test
    void given_validEventMessage_when_subscriptionCreatedEventPublished_then_eventCanBeParsed() throws JsonProcessingException {
        //Given
        String eventMessage = """
                [{
                     "specversion": "1.0",
                     "type": "Microsoft.Storage.BlobCreated", \s
                     "source": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account}",
                     "id": "9aeb0fdf-c01e-0131-0922-9eb54906e209",
                     "time": "2019-11-18T15:13:39.4589254Z",
                     "subject": "blobServices/default/containers/{storage-container}/blobs/{new-file}",   \s
                     "data": {
                         "api": "PutBlockList",
                         "clientRequestId": "4c5dd7fb-2c48-4a27-bb30-5361b5de920a",
                         "requestId": "9aeb0fdf-c01e-0131-0922-9eb549000000",
                         "eTag": "0x8D76C39E4407333",
                         "contentType": "image/png",
                         "contentLength": 30699,
                         "blobType": "BlockBlob",
                         "url": "https://gridtesting.blob.core.windows.net/testcontainer/{new-file}",
                         "sequencer": "000000000000000000000000000099240000000000c41c18",
                         "storageDiagnostics": {
                             "batchId": "681fe319-3006-00a8-0022-9e7cde000000"
                         }
                     }
                 }]
                """;
        //When
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        List<CloudEvent> cloudEvents = null;
        cloudEvents = objectMapper.readValue(eventMessage, new TypeReference<>() {
        });
        //Then
        assertThat(cloudEvents, hasSize(1));
    }
}

Expected behavior
Events from EventGrid can be parsed into CloudEvent object.

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: macOs
  • IDE: IntelliJ
  • Library/Libraries: spring-cloud-azure-dependencies:com.azure.spring:5.9.0
  • Java version: 17
  • App Server/Environment: n.a.
  • Frameworks: Spring Boot

Additional context
n.a.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 13, 2024
@Netyyyy Netyyyy added azure-spring All azure-spring related issues azure-spring-eventgrid Issues related to Spring Event Grid bug This issue requires a change to an existing behavior in the product in order to be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 17, 2024
@github-actions github-actions bot removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label May 17, 2024
@Netyyyy
Copy link
Member

Netyyyy commented May 17, 2024

Hi @joahuber . Thank you for reporting this issue. Could you help provide a minimal project? And we will take a look. We appreciate your input and will review this matter as soon as possible.
Please feel free to provide any additional information or context that you think may be helpful. We'll keep you updated on the progress of our review.

@saragluna
Copy link
Member

@joshfree should this be an Event Grid related issue?

@joahuber
Copy link
Author

@Netyyyy Please find the sample project below. It consists of a single unit test. As soon as you upgrade to version 5.9.0 of the spring-cloud-azure-dependencies dependencies it fails.
CloudEventSample.zip

@Netyyyy
Copy link
Member

Netyyyy commented May 23, 2024

Hi @joahuber , thanks for your sample. I saw you are using azure-messaging-eventgrid directly which is not managed by spring-cloud-azure-dependencies, so the error is not caused by Spring Cloud Azure and you can remove our bom.
Also, could you check your azure-messaging-eventgrid version? I also encountered this error when upgrading from 4.20.1 to 4.22.1, don't know which version you're using.

@billwert please help take a look

@Netyyyy Netyyyy added Event Grid and removed azure-spring All azure-spring related issues azure-spring-eventgrid Issues related to Spring Event Grid labels May 23, 2024
@github-actions github-actions bot added the needs-team-attention This issue needs attention from Azure service team or SDK team label May 23, 2024
@Netyyyy Netyyyy added azure-spring All azure-spring related issues azure-spring-eventgrid Issues related to Spring Event Grid labels May 23, 2024
@joahuber
Copy link
Author

joahuber commented May 23, 2024

Hi @Netyyyy
Sorry for the confusion, we do not need azure-messaging-eventgrid (which seems to be managed by your BOM) but only

<dependency>
      <artifactId>azure-core</artifactId>
      <groupId>com.azure</groupId>
</dependency>

which is pulled in as transitive dependency by azure-messaging-eventgrid. It only seems to happen when upgrading to 5.10 of your BOM.

@Netyyyy Netyyyy added the Azure.Core azure-core label May 23, 2024
@Netyyyy
Copy link
Member

Netyyyy commented May 23, 2024

Hi @Netyyyy Sorry for the confusion, we do not need azure-messaging-eventgrid (which seems to be managed by your BOM) but only

<dependency>
      <artifactId>azure-core</artifactId>
      <groupId>com.azure</groupId>
</dependency>

which is pulled in as transitive dependency by azure-messaging-eventgrid. It only seems to happen when upgrading to 5.10 of your BOM.

OK, @alzimmermsft please help take a look, it occurs when using azure-core 1.46

@alzimmermsft
Copy link
Member

Hi @joahuber, thanks for reporting this, this definitely did break with the release of azure-core:1.46.0.

Within your application would it be possible to use CloudEvent.fromString which returns List<CloudEvent> as a work around for the time being? Or, if you use our JacksonAdapter.createDefaultSerializerAdapter() it should work as well, as a work around.

I'll look into getting this fixed for future releases of azure-core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core azure-core azure-spring All azure-spring related issues azure-spring-eventgrid Issues related to Spring Event Grid bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Grid needs-team-attention This issue needs attention from Azure service team or SDK team
Projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants