-
Notifications
You must be signed in to change notification settings - Fork 103
ref(client-reports): Move Client Reports to the new processing #5338
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
Open
tobias-wilfert
wants to merge
17
commits into
master
Choose a base branch
from
tobias-wilfert/feat/migrate-process-client-reports
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
91ba01a
Initial changes
tobias-wilfert 5c1fb4b
move tests
tobias-wilfert 70eb032
change processor logic to never forward reports, but rather always pr…
tobias-wilfert 673958e
clean up code after checking rate limiting and metric logic
tobias-wilfert 5505925
Merge branch 'master' into tobias-wilfert/feat/migrate-process-client…
tobias-wilfert 709bdaa
small code cleanup
tobias-wilfert f8d85af
remove redundant ratelimiting logic
tobias-wilfert 1535881
rename `SerializedClientReport` to `SerializedClientReports`
tobias-wilfert 12316be
breaking: remove emit_client_outcomes
tobias-wilfert 843a1c6
split processing logic into: expand, validate and emit
tobias-wilfert c8e8263
Merge branch 'master' into tobias-wilfert/feat/migrate-process-client…
tobias-wilfert c76a024
fix merge
tobias-wilfert bc85629
fix doc lint
tobias-wilfert b9fdd3e
Update relay-server/src/processing/client_reports/mod.rs
tobias-wilfert 089341c
Update relay-server/src/processing/client_reports/mod.rs
tobias-wilfert 59c8298
Update relay-server/src/processing/client_reports/mod.rs
tobias-wilfert af3ee0b
Update relay-server/src/processing/client_reports/process.rs
tobias-wilfert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use relay_quotas::RateLimits; | ||
| use relay_system::Addr; | ||
|
|
||
| use crate::envelope::{EnvelopeHeaders, Item, ItemType}; | ||
| use crate::managed::{Counted, Managed, ManagedEnvelope, OutcomeError, Quantities, Rejected}; | ||
| use crate::processing::{self, Context, CountRateLimited, Nothing, Output, QuotaRateLimiter}; | ||
| use crate::services::outcome::{Outcome, TrackOutcome}; | ||
|
|
||
| mod process; | ||
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| /// The client-reports are rate limited. | ||
| #[error("rate limited")] | ||
| RateLimited(RateLimits), | ||
| } | ||
|
|
||
| impl OutcomeError for Error { | ||
| type Error = Self; | ||
|
|
||
| fn consume(self) -> (Option<Outcome>, Self::Error) { | ||
| let outcome = match &self { | ||
| Self::RateLimited(limits) => { | ||
| let reason_code = limits.longest().and_then(|limit| limit.reason_code.clone()); | ||
| Some(Outcome::RateLimited(reason_code)) | ||
| } | ||
| }; | ||
| (outcome, self) | ||
| } | ||
| } | ||
|
|
||
| impl From<RateLimits> for Error { | ||
| fn from(value: RateLimits) -> Self { | ||
| Self::RateLimited(value) | ||
| } | ||
| } | ||
|
|
||
| /// A processor for Client-Reports. | ||
| pub struct ClientReportsProcessor { | ||
| limiter: Arc<QuotaRateLimiter>, | ||
| aggregator: Addr<TrackOutcome>, | ||
| } | ||
|
|
||
| impl ClientReportsProcessor { | ||
| /// Creates a new [`Self`]. | ||
| pub fn new(limiter: Arc<QuotaRateLimiter>, aggregator: Addr<TrackOutcome>) -> Self { | ||
| Self { | ||
| limiter, | ||
| aggregator, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl processing::Processor for ClientReportsProcessor { | ||
| type UnitOfWork = SerializedClientReport; | ||
| type Output = Nothing; | ||
| type Error = Error; | ||
|
|
||
| fn prepare_envelope( | ||
| &self, | ||
| envelope: &mut ManagedEnvelope, | ||
| ) -> Option<Managed<Self::UnitOfWork>> { | ||
| let headers = envelope.envelope().headers().clone(); | ||
|
|
||
| let client_reports = envelope | ||
| .envelope_mut() | ||
| .take_items_by(|item| matches!(*item.ty(), ItemType::ClientReport)) | ||
| .into_vec(); | ||
tobias-wilfert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let work = SerializedClientReport { | ||
| headers, | ||
| client_reports, | ||
| }; | ||
| Some(Managed::from_envelope(envelope, work)) | ||
| } | ||
|
|
||
| async fn process( | ||
| &self, | ||
| mut client_reports: Managed<Self::UnitOfWork>, | ||
| ctx: Context<'_>, | ||
| ) -> Result<Output<Self::Output>, Rejected<Self::Error>> { | ||
| process::process_client_reports( | ||
| &mut client_reports, | ||
| ctx.config, | ||
| ctx.project_info, | ||
| &self.aggregator, | ||
| ); | ||
|
|
||
| self.limiter | ||
| .enforce_quotas(&mut client_reports, ctx) | ||
| .await?; | ||
tobias-wilfert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // FIXME: Not sure if we want to emit some metrics here still | ||
| Ok(Output { | ||
| main: None, | ||
| metrics: None, | ||
| }) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Client-Reports in their serialized state, as transported in an envelope. | ||
| #[derive(Debug)] | ||
| pub struct SerializedClientReport { | ||
tobias-wilfert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Original envelope headers. | ||
| headers: EnvelopeHeaders, | ||
|
|
||
| /// A list of client-reports waiting to be processed. | ||
| /// | ||
| /// All items contained here must be client-reports. | ||
| client_reports: Vec<Item>, | ||
| } | ||
|
|
||
| impl Counted for SerializedClientReport { | ||
| fn quantities(&self) -> Quantities { | ||
| // TODO: Check the envelope rete_limiter | ||
| smallvec::smallvec![] | ||
| } | ||
| } | ||
|
|
||
| impl CountRateLimited for Managed<SerializedClientReport> { | ||
| type Error = Error; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.