Skip to content

Commit

Permalink
feat: add namespace to schemas (#212)
Browse files Browse the repository at this point in the history
Add namespace to event schemas. This should be able to be deployed the producer and consumer in any order.
This will make the schema for a topic look like

{
 "doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
  "fields": [<no change>],
  "name": "CloudEvent",
  "namespace": "org.openedx.content_authoring.course.catalog_info.changed.v1",
  "type": "record"
}
Adding the namespace ensures that there is no conflict when registering schemas by topic/record name, which is how we will be allowing more than one event type per topic. It will also make it easier to identify schemas for use in Avro unions if other users want to try that route.
  • Loading branch information
Rebecca Graber authored May 8, 2023
1 parent 8182d0d commit 06635f3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Change Log
Unreleased
----------

[7.2.0] - 2023-05-03
--------------------
Changed
~~~~~~~
* Added event type as namespace to generated Avro schemas


[7.1.0] - 2023-05-03
--------------------
Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "7.1.0"
__version__ = "7.2.0"
1 change: 1 addition & 0 deletions openedx_events/event_bus/avro/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def schema_from_signal(signal, custom_type_to_avro_type=None):
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [],
"namespace": signal.event_type,
}

for data_key, data_type in signal.init_data.items():
Expand Down
1 change: 1 addition & 0 deletions openedx_events/event_bus/avro/tests/test_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_schema_string(self):
'name': 'CloudEvent',
'type': 'record',
'doc': 'Avro Event Format for CloudEvents created with openedx_events/schema',
'namespace': 'simple.signal',
'fields': [
{
'name': 'data',
Expand Down
8 changes: 8 additions & 0 deletions openedx_events/event_bus/avro/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_simple_schema_generation(self):
"type": "record",
"name": "CloudEvent",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
'namespace': 'simple.signal',
"fields": [
{"name": "event_data", "type":
{"name": "SimpleAttrs", "type": "record", "fields": [
Expand All @@ -58,6 +59,7 @@ def test_nested_attrs_object_serialization(self):
"type": "record",
"name": "CloudEvent",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
'namespace': 'simple.signal',
"fields": [
{"name": "test_data", "type":
{"name": "EventData", "type": "record", "fields": [
Expand Down Expand Up @@ -97,6 +99,7 @@ def test_multiple_top_level_fields(self):
"type": "record",
"name": "CloudEvent",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
'namespace': 'simple.signal',
"fields": [
{"name": "top_level_key_0", "type":
{
Expand Down Expand Up @@ -128,6 +131,7 @@ def test_schema_for_custom_type(self):
"type": "record",
"name": "CloudEvent",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
'namespace': 'simple.signal',
"fields": [
{"name": "test_data", "type": "string"}
],
Expand All @@ -141,6 +145,7 @@ def test_schema_for_nested_custom_type(self):
"type": "record",
"name": "CloudEvent",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
'namespace': 'simple.signal',
"fields": [
{"name": "test_data", "type": {
"name": "NestedNonAttrs",
Expand All @@ -160,6 +165,7 @@ def test_schema_for_types_with_defaults(self):
"type": "record",
"name": "CloudEvent",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
'namespace': 'simple.signal',
"fields": [
{"name": "test_data", "type":
{"name": "SimpleAttrsWithDefaults", "type": "record", "fields": [
Expand Down Expand Up @@ -191,6 +197,7 @@ def test_schema_for_types_with_nested_defaults(self):
'name': 'CloudEvent',
'type': 'record',
'doc': 'Avro Event Format for CloudEvents created with openedx_events/schema',
'namespace': 'simple.signal',
'fields': [{
'name': 'test_data',
'type': {
Expand Down Expand Up @@ -255,6 +262,7 @@ def test_list_with_annotation_works(self):
'name': 'CloudEvent',
'type': 'record',
'doc': 'Avro Event Format for CloudEvents created with openedx_events/schema',
'namespace': 'simple.signal',
'fields': [{
'name': 'list_input',
'type': {'type': 'array', 'items': 'long'},
Expand Down
1 change: 1 addition & 0 deletions openedx_events/event_bus/avro/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_schema_string(self):
'name': 'CloudEvent',
'type': 'record',
'doc': 'Avro Event Format for CloudEvents created with openedx_events/schema',
'namespace': 'simple.signal',
'fields': [
{
'name': 'data',
Expand Down

0 comments on commit 06635f3

Please sign in to comment.