This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add kafka to docker compose #5
Draft
bmtcril
wants to merge
10
commits into
main
Choose a base branch
from
bmtcril/add_kafka
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
53b7bd5
feat: Add kafka to docker compose
bmtcril e5d1121
feat: Functional Kafka consumer/producer
bmtcril 80d9aca
fix: Update to latest openedx-event to stop recursion
bmtcril a600a97
chore: Remove unnecessary IDE file
bmtcril 9f2086a
feat: Add a default consumer for login
bmtcril 61d75fc
fix: Make the producer config a dict
bmtcril a2ba3b2
fix: Make kafka images restart if the crash
bmtcril 1073ee2
refactor: Put implementation independent settings together
bmtcril dd999ee
chore: Upgrade to latest event-bus-redis
bmtcril f3a5f75
feat: Working tracking log consumer
bmtcril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
!.gitignore | ||
TODO | ||
__pycache__ | ||
*.DS_Store* | ||
*.egg-info/ | ||
/build/ | ||
/dist/ | ||
/.idea/ | ||
venv/ | ||
env/ | ||
transifex_input.yaml |
114 changes: 114 additions & 0 deletions
114
tutorevent_bus_redis/patches/local-docker-compose-services
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{% if RUN_KAFKA_SERVER %} | ||
# needed by Kafka to keep track of nodes, topics, and messages. | ||
zookeeper: | ||
image: confluentinc/cp-zookeeper:6.2.1 | ||
restart: unless-stopped | ||
ports: | ||
- "2181:2181" | ||
environment: | ||
ZOOKEEPER_CLIENT_PORT: 2181 | ||
ZOOKEEPER_TICK_TIME: 2000 | ||
|
||
# Events broker | ||
kafka: | ||
image: confluentinc/cp-server:6.2.1 | ||
depends_on: | ||
- zookeeper | ||
restart: unless-stopped | ||
ports: | ||
- "9092:9092" | ||
- "9101:9101" | ||
environment: | ||
KAFKA_BROKER_ID: 1 | ||
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT | ||
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 | ||
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 | ||
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1 | ||
KAFKA_CONFLUENT_BALANCER_TOPIC_REPLICATION_FACTOR: 1 | ||
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 | ||
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 | ||
KAFKA_JMX_PORT: 9101 | ||
KAFKA_JMX_HOSTNAME: localhost | ||
KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://schema-registry:18081 | ||
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: kafka:29092 | ||
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1 | ||
CONFLUENT_METRICS_ENABLE: 'true' | ||
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous' | ||
|
||
# storage layer for data schemas in Kafka | ||
schema-registry: | ||
image: confluentinc/cp-schema-registry:6.2.1 | ||
depends_on: | ||
- kafka | ||
restart: unless-stopped | ||
ports: | ||
- "18081:18081" | ||
environment: | ||
SCHEMA_REGISTRY_HOST_NAME: schema-registry | ||
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'kafka:29092' | ||
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:18081 | ||
{% endif %} | ||
|
||
{% if RUN_KAFKA_SERVER and RUN_KAFKA_UI %} | ||
# browser app for monitoring local Kafka cluster. This is quite memory- and CPU-intensive, so it should only be used for local Kafka debugging | ||
kafka-control-center: | ||
image: confluentinc/cp-enterprise-control-center:6.2.1 | ||
depends_on: | ||
- kafka | ||
- schema-registry | ||
restart: unless-stopped | ||
ports: | ||
- "9021:9021" | ||
environment: | ||
CONTROL_CENTER_BOOTSTRAP_SERVERS: kafka:29092 | ||
CONTROL_CENTER_SCHEMA_REGISTRY_URL: http://schema-registry:18081 | ||
CONTROL_CENTER_REPLICATION_FACTOR: 1 | ||
CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS: 1 | ||
CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS: 1 | ||
CONFLUENT_METRICS_TOPIC_REPLICATION: 1 | ||
PORT: 9021 | ||
{% endif %} | ||
|
||
{% if EVENT_BUS_BACKEND %} | ||
# This is just a stub test for showing how we could run consumers | ||
login-consumer: | ||
image: docker.io/overhangio/openedx:17.0.2-nightly | ||
environment: | ||
SERVICE_VARIANT: lms | ||
DJANGO_SETTINGS_MODULE: lms.envs.tutor.production | ||
command: > | ||
./manage.py lms consume_events -t user-login -g user-activity-service {% if EVENT_BUS_BACKEND == "redis" %}--extra '{"consumer_name": "user-login-1"}'{% endif %} | ||
restart: unless-stopped | ||
volumes: | ||
- ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro | ||
- ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro | ||
- ../apps/openedx/config:/openedx/config:ro | ||
- ../../data/lms:/openedx/data | ||
- ../../data/openedx-media:/openedx/media | ||
depends_on: | ||
- {% if EVENT_BUS_BACKEND == "redis" %}redis{% elif EVENT_BUS_BACKEND == "kafka" %}kafka{% endif %} | ||
|
||
# This is just a stub test for showing how we could run consumers | ||
tracking-consumer: | ||
image: docker.io/overhangio/openedx:17.0.2-nightly | ||
environment: | ||
SERVICE_VARIANT: lms | ||
DJANGO_SETTINGS_MODULE: lms.envs.tutor.production | ||
command: > | ||
./manage.py lms consume_events -t analytics -g analytics-service {% if EVENT_BUS_BACKEND == "redis" %}--extra '{"consumer_name": "analytics-1"}'{% endif %} | ||
restart: unless-stopped | ||
volumes: | ||
- ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro | ||
- ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro | ||
- ../apps/openedx/config:/openedx/config:ro | ||
- ../../data/lms:/openedx/data | ||
- ../../data/openedx-media:/openedx/media | ||
{%- for mount in iter_mounts(MOUNTS, "openedx", "lms") %} | ||
- {{ mount }} | ||
{%- endfor %} | ||
depends_on: | ||
- {% if EVENT_BUS_BACKEND == "redis" %}redis{% elif EVENT_BUS_BACKEND == "kafka" %}kafka{% endif %} | ||
{% endif %} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Backend independent settings for event production | ||
EVENT_BUS_PRODUCER_CONFIG = {{ EVENT_BUS_PRODUCER_CONFIG }} | ||
SEND_CATALOG_INFO_SIGNAL = {{ EVENT_BUS_SEND_CATALOG_INFO_SIGNAL }} | ||
|
||
|
||
{% if EVENT_BUS_BACKEND == 'redis' %} | ||
# redis connection url | ||
# https://redis.readthedocs.io/en/stable/examples/ssl_connection_examples.html#Connecting-to-a-Redis-instance-via-a-URL-string | ||
EVENT_BUS_REDIS_CONNECTION_URL = "{{ EVENT_BUS_REDIS_CONNECTION_URL }}" | ||
EVENT_BUS_TOPIC_PREFIX = "{{ EVENT_BUS_REDIS_TOPIC_PREFIX }}" | ||
EVENT_BUS_PRODUCER = "{{ EVENT_BUS_REDIS_PRODUCER }}" | ||
EVENT_BUS_CONSUMER = "{{ EVENT_BUS_REDIS_CONSUMER }}" | ||
{% if EVENT_BUS_REDIS_CONSUMER_CONSECUTIVE_ERRORS_LIMIT %} | ||
EVENT_BUS_REDIS_CONSUMER_CONSECUTIVE_ERRORS_LIMIT = int("{{ EVENT_BUS_REDIS_CONSUMER_CONSECUTIVE_ERRORS_LIMIT }}") | ||
{% endif %} | ||
EVENT_BUS_REDIS_CONSUMER_POLL_TIMEOUT = int("{{ EVENT_BUS_REDIS_CONSUMER_POLL_TIMEOUT }}") | ||
EVENT_BUS_REDIS_STREAM_MAX_LEN = int("{{ EVENT_BUS_REDIS_STREAM_MAX_LEN }}") | ||
{% endif %} | ||
|
||
{% if EVENT_BUS_BACKEND == 'kafka' %} | ||
EVENT_BUS_KAFKA_SCHEMA_REGISTRY_URL = "{{ EVENT_BUS_KAFKA_SCHEMA_REGISTRY_URL }}" | ||
EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS = "{{ EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS }}" | ||
EVENT_BUS_PRODUCER = "{{ EVENT_BUS_KAFKA_PRODUCER }}" | ||
EVENT_BUS_CONSUMER = "{{ EVENT_BUS_KAFKA_CONSUMER }}" | ||
EVENT_BUS_TOPIC_PREFIX = "{{ EVENT_BUS_KAFKA_TOPIC_PREFIX }}" | ||
{% endif %} | ||
|
||
{% if EVENT_BUS_TRACKING_LOGS %} | ||
SEND_TRACKING_EVENT_EMITTED_SIGNAL = True | ||
|
||
# Update the backends to use the event bus | ||
EVENT_TRACKING_BACKENDS["xapi"]["ENGINE"] = "eventtracking.backends.event_bus.EventBusRoutingBackend" | ||
EVENT_TRACKING_BACKENDS["caliper"]["ENGINE"] = "eventtracking.backends.event_bus.EventBusRoutingBackend" | ||
|
||
# Update backend to send events in sync mode | ||
EVENT_TRACKING_BACKENDS["xapi"]["OPTIONS"]["backends"]["xapi"]["ENGINE"] = "event_routing_backends.backends.sync_events_router.SyncEventsRouter" | ||
EVENT_TRACKING_BACKENDS["caliper"]["OPTIONS"]["backends"]["caliper"]["ENGINE"] = "event_routing_backends.backends.sync_events_router.SyncEventsRouter" | ||
|
||
# Remove caliper from the tracking backends to prevent double-event-emission | ||
EVENT_TRACKING_BACKENDS.pop("caliper") | ||
|
||
{% endif %} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you pin this one?