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(server): Add generic configuration for dynamic sampling rules #907

Merged
merged 20 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## Unreleased
**Features**:

- Improve dynamic sampling rule configuration. ([#907](https://github.com/getsentry/relay/pull/907))

**Internal**:

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion relay-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ tokio = "0.2" # in sync with reqwest
tokio-timer = "0.2.13"
url = { version = "2.1.1", features = ["serde"] }
uuid = { version = "0.8.1", features = ["v5"] }
unicase="2.6.0"

[target."cfg(not(windows))".dependencies]
libc = "0.2.71"

[dev-dependencies]
insta = "0.16.0"
insta = {version="0.16.0", features=["ron"]}

13 changes: 8 additions & 5 deletions relay-server/src/actors/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,11 @@ impl EventProcessor {
None => return Ok(()), // can't process without an event
Some(event) => event,
};

let project_id = state.project_id;
match utils::should_keep_event(event, &state.project_state, project_id) {
match utils::should_keep_event(
event,
&state.project_state,
self.config.processing_enabled(),
) {
Some(false) => Err(ProcessingError::EventSampled),
Some(true) => Ok(()),
None => Ok(()), // Not enough info to make a definite evaluation, keep the event
Expand Down Expand Up @@ -1438,6 +1440,7 @@ impl Handler<HandleEnvelope> for EventManager {
let outcome_producer = self.outcome_producer.clone();
let capture = self.config.relay_mode() == RelayMode::Capture;
let http_encoding = self.config.http_encoding();
let processing_enabled = self.config.processing_enabled();

#[cfg(feature = "processing")]
let store_forwarder = self.store_forwarder.clone();
Expand Down Expand Up @@ -1477,8 +1480,8 @@ impl Handler<HandleEnvelope> for EventManager {
None => Err(ProcessingError::RateLimited(checked.rate_limits)),
}
}))
.and_then(|envelope| {
utils::sample_transaction(envelope, sampling_project, false)
.and_then(move |envelope| {
utils::sample_transaction(envelope, sampling_project, false, processing_enabled)
.map_err(|()| (ProcessingError::TransactionSampled))
})
.and_then(|envelope| {
Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/actors/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct ProjectConfig {
pub quotas: Vec<Quota>,
/// Configuration for sampling traces, if not present there will be no sampling.
#[serde(skip_serializing_if = "Option::is_none")]
pub sampling: Option<SamplingConfig>,
pub dynamic_sampling: Option<SamplingConfig>,
}

impl Default for ProjectConfig {
Expand All @@ -76,7 +76,7 @@ impl Default for ProjectConfig {
datascrubbing_settings: DataScrubbingConfig::default(),
event_retention: None,
quotas: Vec::new(),
sampling: None,
dynamic_sampling: None,
}
}
}
Expand Down
23 changes: 14 additions & 9 deletions relay-server/src/endpoints/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ where
let scoping = Rc::new(RefCell::new(meta.get_partial_scoping()));
let event_id = Rc::new(RefCell::new(None));
let config = request.state().config();
let processing_enabled = config.processing_enabled();

let future = project_manager
.send(GetProject { public_key })
Expand Down Expand Up @@ -475,20 +476,24 @@ where
.map(|project| (envelope, rate_limits, Some(project)));
Box::new(response) as RetVal
}))
.and_then(|(envelope, rate_limits, sampling_project)| {
.and_then(move |(envelope, rate_limits, sampling_project)| {
// do the fast path transaction sampling (if we can't do it here
// we'll try again after the envelope is queued)
let event_id = envelope.event_id();

utils::sample_transaction(envelope, sampling_project.clone(), true).then(
move |result| match result {
Err(()) => Err(BadStoreRequest::TraceSampled(event_id)),
Ok(envelope) if envelope.is_empty() => {
Err(BadStoreRequest::TraceSampled(event_id))
}
Ok(envelope) => Ok((envelope, rate_limits, sampling_project)),
},
utils::sample_transaction(
envelope,
sampling_project.clone(),
true,
processing_enabled,
)
.then(move |result| match result {
Err(()) => Err(BadStoreRequest::TraceSampled(event_id)),
RaduW marked this conversation as resolved.
Show resolved Hide resolved
Ok(envelope) if envelope.is_empty() => {
Err(BadStoreRequest::TraceSampled(event_id))
}
Ok(envelope) => Ok((envelope, rate_limits, sampling_project)),
})
})
.and_then(move |(envelope, rate_limits, sampling_project)| {
event_manager
Expand Down
Loading