Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to route events in sync #361

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

Ian2012
Copy link
Contributor

@Ian2012 Ian2012 commented Oct 25, 2023

Description

This PR creates a handler to process tracking log from the event bus.

  • Update the event router to include a field to define when to process the events in celery or in the same thread.
  • Update the setting to use the event bus by default.

Testing instructions

  • Install openedx-events from the mentioned PR
  • Update your EVENT_TRACKING_BACKENDS settings to use the engine eventtracking.backends.event_bus.EventBusRoutingBackend and update the caliper and xapi backends to use: event_routing_backends.backends.sync_events_router.SyncEventsRouter
  • Install event-tracking from this PR feat: add event bus backend event-tracking#246
  • Configure the event bus
  • Run: tutor dev exec lms ./manage.py lms consume_events -t analytics -g event_routing_backends --extra '{"consumer_name": "aspects"}'
  • Install, enable and initialize tutor-contrib-aspects
  • Verify the xAPI statements are sent to Ralph

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 25, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 25, 2023

Thanks for the pull request, @Ian2012! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@Ian2012 Ian2012 marked this pull request as draft October 25, 2023 16:31
@Ian2012 Ian2012 changed the title feat: add listener for tracking event emitted signal feat: process tracking log via event bus Oct 26, 2023
@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch from d6b3fa6 to d80db69 Compare October 26, 2023 20:21
@Ian2012 Ian2012 marked this pull request as ready for review October 26, 2023 21:42
@Ian2012 Ian2012 requested review from ziafazal and bmtcril and removed request for ziafazal October 26, 2023 21:42
@Ian2012
Copy link
Contributor Author

Ian2012 commented Oct 26, 2023

@ziafazal do you have any ideas to update the settings based on the event bus is enabled? If not use celery

cc @bmtcril

@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch from e2fe19a to 1756e91 Compare October 26, 2023 23:12
@ziafazal
Copy link
Contributor

@ziafazal do you have any ideas to update the settings based on the event bus is enabled? If not use celery
@Ian2012 I'm not getting you. Could you please explain a bit what you are trying to achieve?

@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch 2 times, most recently from 350ebc2 to e142f24 Compare October 27, 2023 13:20
@Ian2012
Copy link
Contributor Author

Ian2012 commented Oct 27, 2023

I can imagine some people that would like to still use the celery backend instead of the event bus. Before the settings were connected to the Async one, and I've changed it to the EventBus. How can we automagically update our own settings to define when to use one or the other?

@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch 2 times, most recently from b138dde to 6b9530b Compare October 27, 2023 19:21
@ziafazal
Copy link
Contributor

ziafazal commented Oct 28, 2023

@Ian2012 if you don't want to process EventBus events asnchronously you can use this engine
'ENGINE': 'eventtracking.backends.routing.RoutingBackend',

@Ian2012
Copy link
Contributor Author

Ian2012 commented Oct 30, 2023

We are implementing a new backend for these reasons:

  • Reduce the latency of Aspects by sending events through the event bus
  • Scale the Aspects sync service independently of the LMS-workers
  • Using the RoutingBackend by default will send all the events synchronously and will cause slowdowns in the LMS

I'm in the process of refactoring the EventRouter so that there are two classes to send events. One for using celery and another one for sending events in the same thread.

@bmtcril The current implementation will process and load events to the backends in the same thread but I'm not sure if that's what we really want.

I see some advantages in performing everything in the same thread and defining an "IDA" in Aspects, but then we will lose the retry capabilities and we will have to perform more operator tasks related to the event bus.

Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still trying to wrap my head around it all, but here are some initial comments

event_routing_backends/backends/events_router.py Outdated Show resolved Hide resolved
event_routing_backends/backends/sync_events_router.py Outdated Show resolved Hide resolved
event_routing_backends/backends/sync_events_router.py Outdated Show resolved Hide resolved
event_routing_backends/handlers.py Outdated Show resolved Hide resolved
event_routing_backends/settings/common.py Outdated Show resolved Hide resolved
event_routing_backends/settings/common.py Outdated Show resolved Hide resolved
event_routing_backends/handlers.py Outdated Show resolved Hide resolved
event_routing_backends/settings/common.py Outdated Show resolved Hide resolved
event_routing_backends/tasks.py Show resolved Hide resolved
event_routing_backends/handlers.py Outdated Show resolved Hide resolved
event_routing_backends/handlers.py Outdated Show resolved Hide resolved
@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch from d43da89 to a76dc9c Compare November 2, 2023 19:25
@Ian2012
Copy link
Contributor Author

Ian2012 commented Nov 2, 2023

@bmtcril added new test cases and updated the docs

@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch from cd8ccb0 to e73201c Compare November 7, 2023 23:36
@Ian2012
Copy link
Contributor Author

Ian2012 commented Nov 8, 2023

@bmtcril added batching capabilities. Hopefully, we can implement a management command to trigger the consumption of events every N seconds, but I'm worried about race conditions unless we only send events every N seconds and not every X event.

I'm using a Redis list to save the events to be sent to the backends (xAPI, Caliper) then those are processed and sent in batch to the backends

@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch from 5fd42a5 to 3e724fd Compare December 4, 2023 21:29
@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch 5 times, most recently from cb0476d to 14df49d Compare February 2, 2024 19:22
@Ian2012
Copy link
Contributor Author

Ian2012 commented Feb 5, 2024

@ziafazal This is ready for re-review. Especially if you have any concerns about the settings changes or the refactoring commit: cf59bfa

Copy link
Contributor

@ziafazal ziafazal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ian2012 Thanks for making these changes. I have a question could you please answer that?

event_routing_backends/handlers.py Outdated Show resolved Hide resolved
@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch 6 times, most recently from f6c89f8 to 3a21781 Compare February 16, 2024 20:58
@Ian2012 Ian2012 force-pushed the cag/add-consumer-for-tracking-logs branch from 3a21781 to 9d5e704 Compare February 16, 2024 21:00
@Ian2012 Ian2012 changed the title feat: process tracking log via event bus feat: refactor EventsRouter bettween sync and async router Feb 16, 2024
@Ian2012
Copy link
Contributor Author

Ian2012 commented Feb 16, 2024

@ziafazal @bmtcril This is finally ready for review, it's mainly a refactor however we should release and tag this to allow people to configure the event bus backend.

Would you agree to not change the default settings here but to provide a flag in tutor-contrib-aspects that allows to easily switch from celery to the event-bus?

I'm thinking on ASPECTS_ENABLE_EVENT_BUS_CONSUMER which automatically configures the xapi and celery backends to use the event bus backends and the sync router

@Ian2012 Ian2012 changed the title feat: refactor EventsRouter bettween sync and async router feat: allow to route events in sync Feb 16, 2024
Copy link
Contributor

@ziafazal ziafazal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Ian2012 Ian2012 merged commit 8bbd98c into master Feb 19, 2024
10 checks passed
@Ian2012 Ian2012 deleted the cag/add-consumer-for-tracking-logs branch February 19, 2024 16:32
@openedx-webhooks
Copy link

@Ian2012 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants