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

Provide alternative in-memory queue for publishing events #763

Open
wants to merge 79 commits into
base: develop
Choose a base branch
from

Conversation

sydjryan
Copy link

@sydjryan sydjryan commented Dec 7, 2022

💸 TL;DR

The event & trace publisher sidecars currently use a POSIX queue to have a buffer in case the services are unavailable. We may not always have access to the special sysctl settings required by to use a POSIX queue, so this PR adds an optional in-memory queue (using queue.Queue). We still default to the POSIX queue, but can optionally pass a command line flag to use this new implementation instead.

We need to gevent patch very early - will add this to the sidecar container entrypoint here: https://github.snooguts.net/reddit/docker-baseplate-sidecars/pull/36

📜 Details

Jira
One-pager

🧪 Testing Steps / Validation

Added both integration & unit tests for the new implementation.

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

docker-compose.yml Outdated Show resolved Hide resolved
syd ryan added 4 commits December 7, 2022 14:54
@sydjryan sydjryan changed the title Replace posix queue event publishing Provide alternative in-memory queue for publishing events Dec 7, 2022
@sydjryan sydjryan marked this pull request as ready for review December 8, 2022 00:52
@sydjryan sydjryan requested a review from a team as a code owner December 8, 2022 00:52
@isugimpy
Copy link
Contributor

isugimpy commented Dec 8, 2022

This is maybe an ignorant question, but I feel like I'm missing something. With the in-memory implementation, how is the item that's on the queue making it from the main baseplate application to the sidecar process?

Copy link

@gfmio gfmio left a comment

Choose a reason for hiding this comment

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

Looks good for a start. Jayme is right though that the baseplate service will need to talk to the sidecar, so we need another queue type RemoteMessageQueue that will call a server in the sidecar. Likewise the sidecar needs to expose such a server RemoteMessageQueueServer that uses the InMemoryMessageQueue for the method implementation.

baseplate/lib/message_queue.py Show resolved Hide resolved
baseplate/lib/message_queue.py Show resolved Hide resolved
baseplate/lib/message_queue.py Show resolved Hide resolved
baseplate/lib/message_queue.py Outdated Show resolved Hide resolved
baseplate/observers/tracing.py Outdated Show resolved Hide resolved
@maeivysea
Copy link
Contributor

🏃 Have to drop from this for now with the Snoodev Code Yellow (not focusing on baseplate releases), please feel free to re-tag once we're clear (we're aiming to exit SCY by end of quarter)

@maeivysea maeivysea removed their request for review December 8, 2022 21:22
Copy link
Contributor

@KTAtkinson KTAtkinson left a comment

Choose a reason for hiding this comment

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

My biggest concern is how this will be used, an in memory queue only works if the Baseplate server and the process consuming the queue share memory, in most cases where this is being used, like event publishing, this is not the case. It was mentioned that maybe we need a server to front this, at that point we might want to consider using something existing and not writing our own. It would be great to see a one pager to get a general idea of the approach and goals for this change.

baseplate/lib/message_queue.py Show resolved Hide resolved
baseplate/lib/message_queue.py Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
@sydjryan sydjryan marked this pull request as draft December 14, 2022 16:16
@sydjryan sydjryan requested a review from eaceaser March 9, 2023 23:59
@@ -4,6 +4,10 @@
from typing import NamedTuple
from typing import Optional

import gevent

gevent.monkey.patch_all()
Copy link
Author

Choose a reason for hiding this comment

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

@eaceaser lmk if there's somewhere better to put this

Choose a reason for hiding this comment

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

Lets move this somewhere where we can wrap it in if cfg.queue_type == QueueType.IN_MEMORY.value -- that way we know we're not changing existing behavior at all

Choose a reason for hiding this comment

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

we still need to remove this b/c otherwise it'll monkeypatch the sidecar when using the posix queue

Copy link

@eaceaser eaceaser left a comment

Choose a reason for hiding this comment

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

a few minor things, only thing this is really blocked on is putting the monkeypatching behind a conditional so we don't regress existing behavior by accident

baseplate/lib/message_queue.py Outdated Show resolved Hide resolved
service RemoteMessageQueueService {
PutResponse put(
1: binary message
2: double timeout

Choose a reason for hiding this comment

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

do we have a use case where we want to vary this? Otherwise I'd recommend we remove the timeout arg and just set a timeout in the sidecar configuration.

Copy link
Author

Choose a reason for hiding this comment

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

I defaulted to None (block forever) to match posix queue behavior. but doing a quick search it actually looks like most (potentially all?) calls set timeout=0 i.e. dont wait at all. seems like the None default might not be best, but I dont want to change behavior

@sydjryan sydjryan requested a review from eaceaser March 16, 2023 21:23
Copy link

@eaceaser eaceaser left a comment

Choose a reason for hiding this comment

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

we need to remove the global monkeypatching from the sidecar still

@@ -4,6 +4,10 @@
from typing import NamedTuple
from typing import Optional

import gevent

gevent.monkey.patch_all()

Choose a reason for hiding this comment

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

we still need to remove this b/c otherwise it'll monkeypatch the sidecar when using the posix queue

baseplate/sidecars/event_publisher.py Outdated Show resolved Hide resolved
@sydjryan sydjryan requested a review from eaceaser March 21, 2023 18:55
Copy link
Contributor

@isugimpy isugimpy left a comment

Choose a reason for hiding this comment

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

Approving to unblock. If Ed's got confidence in this as is, I'm good with it.

@KTAtkinson KTAtkinson added the v2.6 Pull requests to be included in v2.6 label Apr 4, 2023
@kylelemons kylelemons removed the v2.6 Pull requests to be included in v2.6 label May 5, 2023
@chriskuehl chriskuehl removed the v2.7 label Apr 30, 2024
@chriskuehl
Copy link
Member

Removing 2.7 label for now due to conflicts. @sydjryan do we still want to get this merged in a future release? I know this has been sitting for a while now, just want to make sure it's still good to merge once we fix up the conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

10 participants