kyma-project / kyma

Kyma is an opinionated set of Kubernetes-based modular building blocks, including all necessary capabilities to develop and run enterprise-grade cloud-native applications.
https://kyma-project.io
Apache License 2.0
1.52k stars 405 forks source link

Event metadata missing in event object passed to serverless function #9645

Closed pbochynski closed 3 years ago

pbochynski commented 4 years ago

Description

Kyma delivers messages internally with CloudEvents specification. The metadata of the event is sent in HTTP request headers. Example:

  'ce-eventtypeversion': 'v1',
  'ce-id': 'c2b0aaa5-097e-4fd3-8bec-10e1d48c012e',
  'ce-knativearrivaltime': '2020-10-07T06:36:32.120434441Z',
  'ce-knativehistory': 'default-kne-trigger-kn-channel.default.svc.cluster.local',
  'ce-source': 'commerce',
  'ce-sourceid': 'commerce',
  'ce-specversion': '1.0',
  'ce-time': '2020-10-07T06:36:32.002Z',
  'ce-type': 'order.created',

But in the function different headers are expected and copied to the event object:

        const event = {
            'event-type': req.get('event-type'),
            'event-id': req.get('event-id'),
            'event-time': req.get('event-time'),
            'event-namespace': req.get('event-namespace'),
            data,
            'extensions': { request: req, response: res },
        };

Source: https://github.com/kubeless/runtimes/blob/e40586e968c4ecdb636b0da4c173647cfac16c2b/stable/nodejs/kubeless.js#L87-L94

Expected result

Event object in serverless function contains type, version and source of the event.

Actual result

Metadata fields contain undefined values:

  'event-type': undefined,
  'event-id': undefined,
  'event-time': undefined,
  'event-namespace': undefined

Steps to reproduce

Just send the event to the function with single line in the main body:

module.exports = { 
  main: function (event, context) {
    console.log(event)
  }
}

Workaround

You can access the CloudEvents metadata from incoming request headers:

console.log(event.extensions.request.headers)
pbochynski commented 4 years ago

The possible solutions:

  1. send double headers (ce- and event-) from default-broker-filter to the function
  2. modify kubeless runtime (contribute to the upstream project or fork)

I vote for option 2

stale[bot] commented 3 years ago

This issue has been automatically marked as stale due to the lack of recent activity. It will soon be closed if no further activity occurs. Thank you for your contributions.