ansible/event-driven-ansible

Include headers in kafka message

clyang82 opened this issue · 0 comments

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that ansible-rulebook is open source software provided for free and that I might not receive a timely response.

Feature type

New Feature

Feature Summary

We use EDA to connect with kafka and the kafka message is following the cloudevents specification. the example of cloudevents is

{
    "specversion" : "1.0",
    "type" : "com.github.pull.create",
    "source" : "https://github.com/cloudevents/spec/pull",
    "subject" : "123",
    "id" : "A234-1234-1234",
    "time" : "2018-04-05T17:31:00Z",
    "comexampleextension1" : "value",
    "comexampleothervalue" : 5,
    "datacontenttype" : "text/xml",
    "data" : "<much wow=\"xml\"/>"
}

currently, EDA only handles the data field. Do not support headers.

Steps to reproduce

It is very simple to connect kafka as source of EDA.

Current results

{'hosts': ['all'],
 'inventory': '../inventory',
 'project_data_file': None,
 'rule': 'Notify',
 'rule_run_at': '2024-05-20T12:36:10.706124Z',
 'rule_set': 'Read messages from a kafka topic',
 'rule_set_uuid': 'c30c6b82-1331-4bb6-b7a6-963068415dea',
 'rule_uuid': '9612402d-5720-455f-b6d4-cff2fc9b22a1',
 'variables': {'CAFILE_PATH': 'ca.crt',
               'CERTFILE_PATH': 'client.crt',
               'HOST': 'xxx',
               'KEYFILE_PATH': 'client.key',
               'TOPIC': 'event',
               'event': {'body': [{'clusterId': 'dfd94785-6296-48a7-afab-2c72e9ccf816',
                                   'createdAt': '2024-05-20T08:50:58Z',
                                   'eventName': 'demo-managed-a1-03.17cea',
                                   'eventNamespace': 'demo-managed-a1',
                                   'message': 'demo-managed-a1 is available '
                                              'now',
                                   'reason': '',
                                   'reportingController': 'cluster-import-controller',
                                   'reportingInstance': '',
                                   'type': 'Imported'}],
                         'meta': {'received_at': '2024-05-20T12:36:10.694889Z',
                                  'source': {'name': 'ansible.eda.kafka',
                                             'type': 'ansible.eda.kafka'},
                                  'uuid': '26896c96-0fe7-48f4-8737-1f95975f3083'}}}}

Sugested feature result

{'hosts': ['all'],
 'inventory': '../inventory',
 'project_data_file': None,
 'rule': 'Notify',
 'rule_run_at': '2024-05-20T12:50:11.186972Z',
 'rule_set': 'Read messages from a kafka topic',
 'rule_set_uuid': '7736c8aa-d216-49b1-b9d4-2d9096314010',
 'rule_uuid': '18e66b5b-fd7d-433f-8c9e-9da3ec6689cb',
 'variables': {'CAFILE_PATH': 'ca.crt',
               'CERTFILE_PATH': 'client.crt',
               'HOST': 'xxxx',
               'KEYFILE_PATH': 'client.key',
               'TOPIC': 'event',
               'event': {'body': [{'clusterId': 'dfd94785-6296-48a7-afab-2c72e9ccf816',
                                   'createdAt': '2024-05-20T12:38:13Z',
                                   'eventName': 'demo-managed-a1-05.17cea',
                                   'eventNamespace': 'demo-managed-a1',
                                   'message': 'demo-managed-a1 is available '
                                              'now',
                                   'reason': '',
                                   'reportingController': 'cluster-import-controller',
                                   'reportingInstance': '',
                                   'type': 'Imported'}],
                         'meta': {'received_at': '2024-05-20T12:50:11.174858Z',
                                  'source': {'name': 'ansible.eda.kafka',
                                             'type': 'ansible.eda.kafka'},
                                 'headers': {'ce-extversion': '11.12',
                                     'ce-id': '425a635c-75cc-43b4-8ad6-885c4a885e07',
                                     'ce-source': 'demo-hub-a',
                                     'ce-specversion': '1.0',
                                     'ce-time': '2024-05-20T12:38:15.533874238Z',
                                     'ce-type': 'io.open-cluster-management.operator.multiclusterglobalhubs.event.managedcluster',
                                     'content-type': 'application/json'},
                                  'uuid': 'f34dc74e-e2be-4a30-8b77-21ff23a5a074'}}}}

Additional information

No response