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(spool): Introduce in-memory EnvelopeBuffer as alternative to the old spooler #3863

Merged
merged 65 commits into from
Aug 1, 2024

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Jul 25, 2024

This PR introduces a new envelope buffer as designed in https://github.com/getsentry/team-ingest/issues/345, though which all envelopes flow before being processed. Buffered envelopes are stored in per-project stacks. Stacks are sorted by whether the project configs needed for processing are ready, and by latest receive time, such that the latest envelope with a valid project config is always the first in line to be processed.

Currently, only memory-based envelope stacks are supported, but this PR already contains the implementation for disk-based stacks as well.

Class Diagram (partial)

classDiagram




RequestHandler --> "writes to" GuardedEnvelopeBuffer
RequestHandler --> "requests update" ProjectCache


ProjectCache --> "notifies" GuardedEnvelopeBuffer

GuardedEnvelopeBuffer "1" *-- "1" PolymorphicEnvelopeBuffer

class PolymorphicEnvelopeBuffer {
    << enum >>
}

PolymorphicEnvelopeBuffer <|-- EnvelopeBuffer~StackProvider~

class EnvelopeBuffer {
    + push(envelope)
    + pop() Option~Envelope~
    + peek() Option~&Envelope~
    + mark_ready(ProjectKey)
    + mark_pending(ProjectKey)
}

EnvelopeBuffer "1" *-- "1" StackProvider
EnvelopeBuffer "1" *-- "1" PriorityQueue
PriorityQueue "1" *-- "n" EnvelopeStack

class StackProvider {
    << interface >>
    + create_stack()
}

StackProvider <|-- MemoryStackProvider
StackProvider <|-- SqliteStackProvider

StackProvider --> "creates" EnvelopeStack

class EnvelopeStack {
    <<interface>>
    + push(envelope)
    + pop() optional Envelope
}

EnvelopeStack <|-- MemoryEnvelopeStack

EnvelopeStack <|-- SqliteEnvelopeStack
Loading

ref: https://github.com/getsentry/team-ingest/issues/345

@jjbayer jjbayer self-assigned this Jul 26, 2024
@iambriccardo iambriccardo changed the title feat(spool): In-memory envelope buffer feat(spool): Introduce in-memory EnvelopeBuffer as alternative to the old spooler Jul 30, 2024
@jjbayer jjbayer marked this pull request as ready for review July 30, 2024 14:47
@jjbayer jjbayer requested a review from a team as a code owner July 30, 2024 14:47
@iambriccardo iambriccardo self-requested a review July 31, 2024 07:36
Copy link
Member

@iambriccardo iambriccardo left a comment

Choose a reason for hiding this comment

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

LGTM, reviewed offline. Will discuss next steps

relay-server/src/services/project_cache.rs Outdated Show resolved Hide resolved
relay-server/src/services/project_cache.rs Outdated Show resolved Hide resolved
relay-config/src/config.rs Outdated Show resolved Hide resolved
Comment on lines 42 to 45
/// Used to notify callers of `peek()` of any changes in the buffer.
notify: tokio::sync::Notify,
/// Used to notify callers of `peek()` of any changes in the buffer.
changed: AtomicBool,
Copy link
Contributor

Choose a reason for hiding this comment

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

These fields have the same documentation, is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, both are used for notification. I didn't find a good way to make it work with only a Notify.

Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
@jjbayer jjbayer enabled auto-merge (squash) July 31, 2024 11:59
Add a gauge metric for the total number of stacks in the priority queue.
@jjbayer jjbayer disabled auto-merge July 31, 2024 14:54
@jjbayer jjbayer merged commit 39bbc1f into master Aug 1, 2024
24 checks passed
@jjbayer jjbayer deleted the feat/envelope-buffer branch August 1, 2024 06:07
jjbayer added a commit to getsentry/sentry that referenced this pull request Aug 1, 2024
`test_histogram_outliers` became flaky after
getsentry/relay#3863.

Add info to the assert to get more insights.
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.

3 participants