question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cloud events incorrectly unmarshalled: first argument is undefined, 2nd argument differs from production

See original GitHub issue

When Pubsub notifications are sent to a locally hosted cloud event function, the first argument is undefined. It should contain the event information. The 2nd argument though present, does not match production signature; rather than containing metadata about the notification, it contains the entire event object, which should be the contents of argument 1 instead.

My dummy cloud events function:

exports.helloEvents = (data, context) => {
  console.log(data);
  console.log(context);
};

Pub/sub notification being sent:

{
  "subscription": "projects/myproj/subscriptions/mysub",
  "message": {
    "data": "...my base 64 encoded data...",
    "messageId": "1",
    "attributes": {}
  }
}

helloEvents log in production:

Argument 1, data, is:

{  
   "subscription":"projects/myproj/subscriptions/mysub",
   "message":{  
      "data":"...my base 64 encoded data...",
      "messageId":"1",
      "attributes":{}
   }
}

Argument 2, context, is:

{  
   "eventId":"12032d95-089a-4663-9be5-8aafd9d4c623",
   "resource":{  
      "service":"pubsub.googleapis.com",
      "name":"projects/myproj/topics/mytopic"
   },
   "eventType":"google.pubsub.topic.publish",
   "timestamp":"2019-06-16T18:39:44.809Z"
}

On local, the results I get is very different.

  • Argument 1: undefined
  • Argument 2:
{  
   "subscription":"projects/myproj/subscriptions/mysub",
   "message":{  
      "data":"...my base 64 encoded data...",
      "messageId":"1",
      "attributes":{}
   }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
grantcommented, Jun 2, 2020

Hey all, thanks for the comments. I know this is an issue. I’m not sure of the exact solution right now.

We’re formally supporting CloudEvents in the Functions Framework spec and will be looking at better, more accurate support for CloudEvents (and legacy events) in the frameworks.

I’ve pinged a colleague to see if we can also improve our docs on cloud.google.com

In any case, this whole section seems to be flat wrong, because following the approach simply doesn’t work.

I’ve removed that section until we have accurate docs.

3reactions
mykwilliscommented, Feb 28, 2020

@alexsanzdev the tests pass, but I don’t believe that they are terribly comprehensive. There is no test data that looks anything like the Cloud Pub/Sub request.

Incidentally, there is test data named “GCF legacy event” that looks like this:

      name: 'GCF legacy event',
      body: {
        eventId: 'testEventId',
        timestamp: 'testTimestamp',
        eventType: 'testEventType',
        resource: 'testResource',
        data: { some: 'payload' },
      },
      expectedResource: 'testResource',
    },

So it seems like maybe there should be a test for the PubSub event format, and the associated fix to pull data from correct place, but I’m still stuck scratching my head asking how this works on GCF production.

In any case, this whole section seems to be flat wrong, because following the approach simply doesn’t work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write event-driven functions | Cloud Functions Documentation
Event -driven functions in the Cloud Functions (1st gen) Node.js, Python, Go, and Java runtimes expect different arguments from CloudEvent functions.
Read more >
Strange second argument passed to event handler (always ...
The event listener called with 2 arguments: synthetic event and strange undefined value. I think, normal behavior is when handler called with a ......
Read more >
XDK for Java XML Error Messages - Oracle Help Center
Cause: The content model in the element declaration was invalid, the content particle requires an element name. See Production [48] in XML 1.0...
Read more >
RHSA-2021:3759 - Security Advisory - Red Hat Customer Portal
Red Hat OpenShift Container Platform is Red Hat's cloud computing Kubernetes application platform solution designed for on-premise or ...
Read more >
Kogito Documentation - Red Hat on GitHub
The kogito.codegen.sources.directory parameter defines the custom target ... The custom {KOGITO} Service is now configured to produce cloud events that will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found