Skip to content

Commit 203fdaf

Browse files
authored
feat(spanv2): Implement store retentions (#5252)
Considered passing `Retention` to the `store`, but then I feel like `Retention` should be a type 'owned' by the store and we should refactor all usages. So might keep that for a follow-up and just keep it consistent with the rest.
1 parent b2088b7 commit 203fdaf

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

relay-server/src/processing/spans/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Forward for SpanOutput {
188188
fn forward_store(
189189
self,
190190
s: &relay_system::Addr<crate::services::store::Store>,
191-
_: processing::ForwardContext<'_>,
191+
ctx: processing::ForwardContext<'_>,
192192
) -> Result<(), Rejected<()>> {
193193
let spans = match self {
194194
SpanOutput::NotProcessed(spans) => {
@@ -199,17 +199,12 @@ impl Forward for SpanOutput {
199199
SpanOutput::Processed(spans) => spans,
200200
};
201201

202-
let (spans, server_sample_rate) =
203-
spans.split_with_context(|spans| (spans.spans, spans.server_sample_rate));
204-
205202
let ctx = store::Context {
206-
server_sample_rate,
207-
// TODO: retentions still need to be taken from the project info.
208-
retention_days: crate::constants::DEFAULT_EVENT_RETENTION,
209-
downsampled_retention_days: crate::constants::DEFAULT_EVENT_RETENTION,
203+
server_sample_rate: spans.server_sample_rate,
204+
retention: ctx.retention(|r| r.span.as_ref()),
210205
};
211206

212-
for span in spans {
207+
for span in spans.split(|spans| spans.spans) {
213208
if let Ok(span) = span.try_map(|span, _| store::convert(span, &ctx)) {
214209
s.send(span)
215210
};

relay-server/src/processing/spans/store.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use relay_event_schema::protocol::SpanV2;
44
use relay_protocol::{Annotated, FiniteF64};
55

66
use crate::envelope::WithHeader;
7+
use crate::processing::Retention;
78
use crate::processing::spans::{Error, Result};
89
use crate::services::outcome::DiscardReason;
910
use crate::services::store::StoreSpanV2;
@@ -25,12 +26,10 @@ macro_rules! required {
2526

2627
/// Context required for [`convert`].
2728
pub struct Context {
28-
/// Span retention in days.
29-
pub retention_days: u16,
30-
/// Span downsampled retention in day.
31-
pub downsampled_retention_days: u16,
3229
/// Server side applied sample rate.
3330
pub server_sample_rate: Option<f64>,
31+
/// Item retention.
32+
pub retention: Retention,
3433
}
3534

3635
/// Converts a processed [`SpanV2`] into a [Kafka](crate::services::store::Store) compatible format.
@@ -43,8 +42,8 @@ pub fn convert(span: WithHeader<SpanV2>, ctx: &Context) -> Result<Box<StoreSpanV
4342

4443
Ok(Box::new(StoreSpanV2 {
4544
routing_key,
46-
retention_days: ctx.retention_days,
47-
downsampled_retention_days: ctx.downsampled_retention_days,
45+
retention_days: ctx.retention.standard,
46+
downsampled_retention_days: ctx.retention.downsampled,
4847
item: span,
4948
}))
5049
}

tests/integration/test_spansv2.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ def test_spansv2_basic(
4747

4848
project_id = 42
4949
project_config = mini_sentry.add_full_project_config(project_id)
50-
project_config["config"]["features"] = [
51-
"organizations:standalone-span-ingestion",
52-
"projects:span-v2-experimental-processing",
53-
]
50+
project_config["config"].update(
51+
{
52+
"features": [
53+
"organizations:standalone-span-ingestion",
54+
"projects:span-v2-experimental-processing",
55+
],
56+
"retentions": {"span": {"standard": 42, "downsampled": 1337}},
57+
}
58+
)
5459

5560
relay = relay(relay_with_processing(options=TEST_CONFIG), options=TEST_CONFIG)
5661

@@ -102,8 +107,8 @@ def test_spansv2_basic(
102107
"end_timestamp": time_within(ts.timestamp() + 0.5),
103108
"is_remote": False,
104109
"status": "ok",
105-
"retention_days": 90,
106-
"downsampled_retention_days": 90,
110+
"retention_days": 42,
111+
"downsampled_retention_days": 1337,
107112
"key_id": 123,
108113
"organization_id": 1,
109114
"project_id": 42,

0 commit comments

Comments
 (0)