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

Store events in a Redis stream instead of a list #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jjmerchante
Copy link
Collaborator

@jjmerchante jjmerchante commented Jul 11, 2024

This PR updates the method of storing events in Redis for later consumption.
Events are now added to a Redis Stream, allowing different types of consumers to process the items for various purposes. The trade-off is that the stream has a fixed length, causing older items to be deleted when new items are added.

@jjmerchante jjmerchante force-pushed the redis-stream branch 2 times, most recently from 153f64b to 6e5e0d9 Compare December 4, 2024 09:18
@jjmerchante jjmerchante marked this pull request as ready for review December 4, 2024 09:19
@jjmerchante jjmerchante force-pushed the redis-stream branch 4 times, most recently from a962b7d to 7cb5cee Compare December 5, 2024 10:42
Copy link
Member

@sduenas sduenas left a comment

Choose a reason for hiding this comment

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

I wonder if you can reduce the PR just to the scope of writing data to the events stream. I think we can add the tasks that process data later.

@jjmerchante
Copy link
Collaborator Author

I updated the PR to include only the change that inserts data in the stream. I also removed the file grimoirelab-dev that was not being used because the contents were moved to runner/commands/run/

Copy link
Member

@sduenas sduenas left a comment

Choose a reason for hiding this comment

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

It looks good in general. Check my comments, though.

@@ -83,6 +81,8 @@ def server(ctx: Context, devel: bool):
env["UWSGI_SINGLE_INTERPRETER"] = "true"

# Run maintenance tasks
from grimoirelab.core.scheduler.scheduler import maintain_tasks
Copy link
Member

Choose a reason for hiding this comment

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

Why did you have to move this statement here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because otherwise, it doesn't work. It has to initialize the Django module first, which is done here: https://github.com/chaoss/grimoirelab-core/blob/main/src/grimoirelab/core/runner/cmd.py#L58

If you try to do the import there you get django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Q_PERCEVAL_JOBS = os.environ.get('GRIMOIRELAB_Q_PERCEVAL_JOBS', 'default')
Q_STORAGE_ITEMS = os.environ.get('GRIMOIRELAB_Q_STORAGE_ITEMS', 'items')
Q_EVENTS = os.environ.get('GRIMOIRELAB_Q_EVENTS', 'events')
Q_EVENTIZER_JOBS = os.environ.get('GRIMOIRELAB_Q_EVENTIZER_JOBS', 'default')
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use the prefix GRIMOIRELAB_ to all these variables that can be configured to make it clear they are part of this app and don't come from other.

}

EVENTS_STREAM_NAME = os.environ.get('GRIMOIRELAB_EVENTS_STREAM_NAME', 'events')
EVENTS_STREAM_MAX_LENGTH = int(os.environ.get('GRIMOIRELAB_EVENTS_STREAM_MAX_LENGTH', 2 * 10 ** 6))
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a magic number. What is it and why is that the length?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the stream's limit. Once the stream reaches this capacity, new items will replace older ones. On average, each Git event consumes approximately 2.6 Kb (calculated using MEMORY USAGE). While this size can be reduced, it is important for consumers to read from the stream before it reaches its limit; otherwise, items will be discarded.

I can lower this number, but it depends on the memory of the Redis server.

This commit updates the method of storing events in
Redis for later consumption.
Events are now added to a Redis Stream, allowing
different types of consumers to process the items for
various purposes. The trade-off is that the stream has a
fixed length, causing older items to be deleted when
new items are added.

Signed-off-by: Jose Javier Merchante <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants