-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add management command for testing event production; config fixes
- Update manual-testing instructions - Switch to `SESSION_LOGIN_COMPLETED` for the single signal we support since it's easier to test with (but may want to choose a different one in the future that doesn't involve PII, even fake PII). - Move test receiver to event_consumer module for simplicity; wrap in try-block for safety. - Tolerate some missing settings in the consumer - Add unit tests - Some small control flow changes: - Move responsibility for handling None messages from `process_single_message` to `consume_indefinitely` - Collapse None/empty headers into single case - Log and docstring tweaks
- Loading branch information
Showing
8 changed files
with
251 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,36 +3,32 @@ Manual testing | |
|
||
The producer can be tested manually against a Kafka running in devstack. | ||
|
||
#. Create a "unit test" in one of the test files that will actually call Kafka. For example, this could be added to the end of ``edx_event_bus_kafka/publishing/test_event_producer.py``:: | ||
|
||
def test_actually_send_to_event_bus(): | ||
import random | ||
signal = openedx_events.learning.signals.SESSION_LOGIN_COMPLETED | ||
# Make events distinguishable | ||
id = random.randrange(1000) | ||
event_data = { | ||
'user': UserData( | ||
id=id, | ||
is_active=True, | ||
pii=UserPersonalData( | ||
username=f'foobob_{id:03}', | ||
email='[email protected]', | ||
name="Bob Foo", | ||
) | ||
) | ||
} | ||
|
||
print(f"Sending event with random user ID {id}.") | ||
with override_settings( | ||
SCHEMA_REGISTRY_URL='http://edx.devstack.schema-registry:8081', | ||
KAFKA_BOOTSTRAP_SERVERS='edx.devstack.kafka:29092', | ||
): | ||
ep.send_to_event_bus(signal, 'user_stuff', 'user.id', event_data) | ||
|
||
#. Make or refresh a copy of this repo where it can be seen from inside devstack: ``rsync -sax -delete ./ ../src/event-bus-kafka/`` | ||
#. In devstack, start Kafka and the control webapp: ``make dev.up.kafka-control-center`` and watch ``make dev.logs.kafka-control-center`` until server is up and happy (may take a few minutes; watch for ``INFO Kafka startTimeMs``) | ||
#. Load the control center UI: http://localhost:9021/clusters and wait for the cluster to become healthy | ||
#. In devstack, run ``lms-up-without-deps-shell`` to bring up an arbitrary shell inside Docker networking (LMS, in this case) | ||
#. In the LMS shell, run ``pip install -e /edx/src/event-bus-kafka`` and then run whatever test you want, e.g. ``pytest /edx/src/event-bus-kafka/edx_event_bus_kafka/publishing/test_event_producer.py::test_actually_send_to_event_bus`` | ||
#. Go to the topic that was created and then into the Messages tab; select offset=0 to make sure you can see messages that were sent before you had the UI open. | ||
#. Rerun ``rsync`` after any edits | ||
#. In edx-platform's ``cms/envs/common.py``: | ||
|
||
- Add ``'edx_event_bus_kafka'`` to the ``INSTALLED_APPS`` list | ||
- Add the following:: | ||
|
||
KAFKA_CONSUMERS_ENABLED = True | ||
KAFKA_BOOTSTRAP_SERVERS = "edx.devstack.kafka:29092" | ||
SCHEMA_REGISTRY_URL = "http://edx.devstack.schema-registry:8081" | ||
|
||
#. In devstack, run ``make devpi-up studio-up-without-deps-shell`` to bring up Studio with a shell. | ||
#. In the Studio shell, run ``pip install -e /edx/src/event-bus-kafka`` | ||
#. Test the producer: | ||
|
||
- Run the example command listed in the ``edx_event_bus_kafka.management.commands.produce_event.Command`` docstring | ||
- Expect to see output that ends with a line containing "Event delivered to topic" | ||
- Go to the topic that was created and then into the Messages tab; select offset=0 to make sure you can see messages that were sent before you had the UI open. | ||
|
||
#. Test the consumer: | ||
|
||
- Run the example command listed in the ``edx_event_bus_kafka.consumer.event_consumer.ConsumeEventsCommand`` docstring | ||
- Expect to see output that ends with a line containing "Received SESSION_LOGIN_COMPLETED signal with user_data" | ||
- Kill the management command (which would run indefinitely). | ||
|
||
#. Rerun rsync after any edits as needed. | ||
|
||
(Any IDA should work for testing, but all interactions have to happen inside devstack's networking layer, otherwise Kafka can't talk to itself.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.