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

ref(buffering): Add BufferService with SQLite backend #1920

Merged
merged 39 commits into from
Mar 30, 2023

Conversation

olksdr
Copy link
Contributor

@olksdr olksdr commented Mar 13, 2023

In PR:

  • add config option to enable persistent buffer
  • add migrations to create DB and required table for storing the envelopes
    • migrations are built-in
    • migrations run on start up and if the failure happens relay won't start at all
  • when persist the envelopes to the disk, the outcome won't be sent
  • keep a memory buffer and spool it when it hits defined memory limit
  • update BufferService to handle the sqlite pooling and insert/select/delete operations
  • when Relay stops we try to spool in-memory buffer to disk as well

fix: https://github.com/getsentry/team-ingest/issues/78

This is the initial naive implementation of the prsistent envelope
buffer backed by SQLite.

In this initial iterration:
* add config option to enable persistent buffer
* add migrations to create DB and required table for storing the
  envelopes
  - migrations run on start up and if the failure happens relay won't
    start at all
* update envelope context to avoid sending the outcome if it's dropped
  while persisting it into the buffer - we might want to use `done` here
  instead
* add SqliteBufferService which handles the sqlite pooling and
  insert/select/delete operations

Still some TODOs:
* metrics won't make any sense if we dropp and re-create the envelope
  context, still have to handle this properly
  - persist the data from the initil context?
  - don't care about it at all?
* add high-/lowwaterrmark and use the memory for the inital buffer
  before storing envelopes in the db
* read up the envelopes in batches instead of all at once
@olksdr olksdr requested a review from a team March 13, 2023 08:00
@olksdr olksdr self-assigned this Mar 13, 2023
@olksdr olksdr closed this Mar 13, 2023
@olksdr olksdr deleted the feat/buff-with-lite branch March 13, 2023 14:30
@olksdr olksdr restored the feat/buff-with-lite branch March 13, 2023 14:30
@olksdr olksdr reopened this Mar 13, 2023
@olksdr olksdr force-pushed the feat/buff-with-lite branch from 69266f2 to 7c4f618 Compare March 20, 2023 15:52
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

Preliminary review, mostly questions and bikeshedding.

Comment on lines +3 to +4
own_key TEXT,
sampling_key TEXT,
Copy link
Member

Choose a reason for hiding this comment

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

Can we make these fixed width 32 byte arrays? That should make the lookup faster (at least in theory).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will have to look into this, how the indicies on the binary fields work.

Copy link
Member

Choose a reason for hiding this comment

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

That should make the lookup faster

I'm basing this on an assumption that TEXT fields store a reference to a string that is saved somewhere else, while fixed-width types are stored "inline". But this assumption might be wrong as I have no idea how sqlite does it.

relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_cache.rs Outdated Show resolved Hide resolved
relay-server/src/utils/buffer.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

This is good stuff, looks good!

Some comments on top of what Joris suggests.

relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-server/src/lib.rs Outdated Show resolved Hide resolved
relay-server/src/utils/managed_envelope.rs Outdated Show resolved Hide resolved
Comment on lines +19 to +21
/// Describes the errors linked with the `Sqlite` backed buffer.
#[error("failed to fetch data from the database")]
DatabaseError(#[from] sqlx::Error),
Copy link
Contributor

Choose a reason for hiding this comment

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

A database is a type of backend of a buffer. Should we abstract it? Feel free to address this in a follow-up PR, or not do it at all until we actually use another backend.

relay-server/src/utils/buffer.rs Outdated Show resolved Hide resolved
relay-server/src/utils/buffer.rs Outdated Show resolved Hide resolved
relay-server/src/utils/buffer.rs Outdated Show resolved Hide resolved
migrations/20230311081917_envelopes_table.sql Show resolved Hide resolved
relay-server/src/actors/project_cache.rs Outdated Show resolved Hide resolved
@olksdr olksdr requested review from jjbayer, iker-barriocanal and a team March 23, 2023 09:42
Comment on lines +3 to +4
own_key TEXT,
sampling_key TEXT,
Copy link
Member

Choose a reason for hiding this comment

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

That should make the lookup faster

I'm basing this on an assumption that TEXT fields store a reference to a string that is saved somewhere else, while fixed-width types are stored "inline". But this assumption might be wrong as I have no idea how sqlite does it.

migrations/20230311081917_envelopes_table.sql Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/utils/buffer.rs Outdated Show resolved Hide resolved
Copy link
Member

@jjbayer jjbayer 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, I think this is ready for load testing.

migrations/20230311081917_envelopes_table.sql Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_cache.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_cache.rs Outdated Show resolved Hide resolved
relay-server/src/utils/buffer.rs Outdated Show resolved Hide resolved
relay-server/src/utils/semaphore.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Show resolved Hide resolved
Copy link
Member

@jjbayer jjbayer 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! There are still some open questions & suggestions, but none of them are blocking from my point of view.

relay-config/src/config.rs Show resolved Hide resolved
relay-server/src/actors/project_cache.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Show resolved Hide resolved
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

The PR looks good to me, I'd address the order topic before deploying, in this conversation.

relay-server/src/actors/project_cache.rs Outdated Show resolved Hide resolved
relay-server/src/actors/project_buffer.rs Outdated Show resolved Hide resolved
@olksdr olksdr enabled auto-merge (squash) March 30, 2023 08:27
@olksdr olksdr merged commit e67f343 into master Mar 30, 2023
@olksdr olksdr deleted the feat/buff-with-lite branch March 30, 2023 09:16
jan-auer added a commit that referenced this pull request Mar 30, 2023
* master:
  ref(buffering): Add BufferService with SQLite backend (#1920)
jan-auer added a commit that referenced this pull request Mar 30, 2023
* master:
  ref(buffering): Add BufferService with SQLite backend (#1920)
  ref(server): Move from actix-web to axum (#1938)
  ref(tx-processor): Apply transaction rules after UUID scrubbing (#1964)
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