-
Notifications
You must be signed in to change notification settings - Fork 94
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(stats): Add quantity to TrackOutcome and new attachment outcomes #942
Changes from 4 commits
c0b47cc
f10dece
a19b099
292a0f0
3a1e03c
948fbb2
d257433
f58dbf0
30bc59a
b14efc0
17449e1
ea1df32
7f6e7e0
558c2fd
efb7825
1a9691d
c864a89
f121228
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ use crate::envelope::{self, AttachmentType, ContentType, Envelope, Item, ItemTyp | |
use crate::http::{HttpError, RequestBuilder}; | ||
use crate::metrics::{RelayCounters, RelayHistograms, RelaySets, RelayTimers}; | ||
use crate::service::ServerError; | ||
use crate::utils::{self, ChunkedFormDataAggregator, FormDataIter, FutureExt}; | ||
use crate::utils::{self, ChunkedFormDataAggregator, EnvelopeSummary, FormDataIter, FutureExt}; | ||
|
||
#[cfg(feature = "processing")] | ||
use { | ||
|
@@ -1483,12 +1483,13 @@ impl Handler<HandleEnvelope> for EventManager { | |
|
||
let scoping = Rc::new(RefCell::new(envelope.meta().get_partial_scoping())); | ||
let is_received = Rc::new(AtomicBool::from(false)); | ||
let envelope_summary = Rc::new(RefCell::new(EnvelopeSummary::empty())); | ||
|
||
let future = project | ||
.send(CheckEnvelope::fetched(envelope)) | ||
.map_err(ProcessingError::ScheduleFailed) | ||
.and_then(|result| result.map_err(ProcessingError::ProjectFailed)) | ||
.and_then(clone!(scoping, |response| { | ||
.and_then(clone!(scoping, envelope_summary, |response| { | ||
// Use the project id from the loaded project state to account for redirects. | ||
let project_id = response.scoping.project_id.value(); | ||
metric!(set(RelaySets::UniqueProjects) = project_id as i64); | ||
|
@@ -1497,7 +1498,10 @@ impl Handler<HandleEnvelope> for EventManager { | |
|
||
let checked = response.result.map_err(ProcessingError::EventRejected)?; | ||
match checked.envelope { | ||
Some(envelope) => Ok(envelope), | ||
Some(envelope) => { | ||
envelope_summary.replace(EnvelopeSummary::compute(&envelope)); | ||
Ok(envelope) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the latest place where we need to update the envelope summary? (I love how it can be written like this in the Rust syntax, btw.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the case in Technically, that would also apply to the |
||
None => Err(ProcessingError::RateLimited(checked.rate_limits)), | ||
} | ||
})) | ||
|
@@ -1696,11 +1700,25 @@ impl Handler<HandleEnvelope> for EventManager { | |
outcome_producer.do_send(TrackOutcome { | ||
timestamp: Instant::now(), | ||
scoping: *scoping.borrow(), | ||
outcome, | ||
outcome: outcome.clone(), | ||
event_id, | ||
remote_addr, | ||
category, | ||
}) | ||
quantity: 1, | ||
}); | ||
|
||
let envelope_summary = envelope_summary.borrow(); | ||
if envelope_summary.attachment_quantity > 0 { | ||
JoshFerge marked this conversation as resolved.
Show resolved
Hide resolved
jan-auer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outcome_producer.do_send(TrackOutcome { | ||
timestamp: start_time, | ||
scoping: *scoping.borrow(), | ||
outcome, | ||
event_id, | ||
remote_addr, | ||
category: DataCategory::Attachment, | ||
quantity: envelope_summary.attachment_quantity, | ||
}); | ||
} | ||
} | ||
}) | ||
.then(move |x, slf, _| { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ use failure::Fail; | |
use futures::prelude::*; | ||
use serde::Deserialize; | ||
|
||
use relay_common::{clone, metric, tryf}; | ||
use relay_common::{clone, metric, tryf, DataCategory}; | ||
use relay_config::Config; | ||
use relay_general::protocol::{EventId, EventType}; | ||
use relay_log::LogError; | ||
|
@@ -26,7 +26,7 @@ use crate::envelope::{AttachmentType, Envelope, EnvelopeError, ItemType, Items}; | |
use crate::extractors::RequestMeta; | ||
use crate::metrics::RelayCounters; | ||
use crate::service::{ServiceApp, ServiceState}; | ||
use crate::utils::{self, ApiErrorResponse, FormDataIter, MultipartError}; | ||
use crate::utils::{self, ApiErrorResponse, EnvelopeSummary, FormDataIter, MultipartError}; | ||
|
||
#[derive(Fail, Debug)] | ||
pub enum BadStoreRequest { | ||
|
@@ -410,19 +410,19 @@ where | |
|
||
let scoping = Rc::new(RefCell::new(meta.get_partial_scoping())); | ||
let event_id = Rc::new(RefCell::new(None)); | ||
let event_category = Rc::new(RefCell::new(None)); | ||
let envelope_summary = Rc::new(RefCell::new(EnvelopeSummary::empty())); | ||
let config = request.state().config(); | ||
let processing_enabled = config.processing_enabled(); | ||
|
||
let future = project_manager | ||
.send(GetProject { public_key }) | ||
.map_err(BadStoreRequest::ScheduleFailed) | ||
.and_then(clone!(event_id, event_category, scoping, |project| { | ||
.and_then(clone!(event_id, envelope_summary, scoping, |project| { | ||
extract_envelope(&request, meta) | ||
.into_future() | ||
.and_then(clone!(event_id, event_category, |envelope| { | ||
.and_then(clone!(event_id, envelope_summary, |envelope| { | ||
event_id.replace(envelope.event_id()); | ||
event_category.replace(envelope.get_event_category()); | ||
envelope_summary.replace(EnvelopeSummary::compute(&envelope)); | ||
|
||
if envelope.is_empty() { | ||
Err(BadStoreRequest::EmptyEnvelope) | ||
|
@@ -446,6 +446,8 @@ where | |
Some(envelope) => envelope, | ||
None => return Err(BadStoreRequest::RateLimited(checked.rate_limits)), | ||
}; | ||
// TODO: Ensure that outcomes are emitted correctly for rate-limited attachments | ||
// so that it is safe to update envelope_summary here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, we will have to update the envelope summary here. We chose not to do this just yet, until the rate limiting code inside |
||
|
||
if check_envelope_size_limits(&config, &envelope) { | ||
Ok((envelope, checked.rate_limits)) | ||
|
@@ -530,15 +532,29 @@ where | |
.or_else(move |error: BadStoreRequest| { | ||
metric!(counter(RelayCounters::EnvelopeRejected) += 1); | ||
|
||
if let Some(category) = *event_category.borrow() { | ||
if let Some(outcome) = error.to_outcome() { | ||
let envelope_summary = envelope_summary.borrow(); | ||
if let Some(outcome) = error.to_outcome() { | ||
if let Some(category) = envelope_summary.event_category { | ||
outcome_producer.do_send(TrackOutcome { | ||
timestamp: start_time, | ||
scoping: *scoping.borrow(), | ||
outcome, | ||
outcome: outcome.clone(), | ||
event_id: *event_id.borrow(), | ||
remote_addr, | ||
category, | ||
quantity: 1, | ||
}); | ||
} | ||
|
||
if envelope_summary.attachment_quantity > 0 { | ||
outcome_producer.do_send(TrackOutcome { | ||
timestamp: start_time, | ||
scoping: *scoping.borrow(), | ||
outcome, | ||
JoshFerge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event_id: *event_id.borrow(), | ||
remote_addr, | ||
category: DataCategory::Attachment, | ||
quantity: envelope_summary.attachment_quantity, | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to get rid of the
event_category
variable as a result of this, and useenvelope_summary
in theor_else
error handler.