From b61bb34a0ff37a4b4f32a20762d4e8cf87e71c34 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Mon, 23 Sep 2024 17:21:10 +0200 Subject: [PATCH] feat(eap): Include server-side sample rates in sampling weight --- rust_snuba/src/processors/eap_spans.rs | 22 +++++++++++-------- ...sors__eap_spans__tests__serialization.snap | 6 ++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/rust_snuba/src/processors/eap_spans.rs b/rust_snuba/src/processors/eap_spans.rs index a78181e4a6..fe38187034 100644 --- a/rust_snuba/src/processors/eap_spans.rs +++ b/rust_snuba/src/processors/eap_spans.rs @@ -151,17 +151,18 @@ impl From for EAPSpan { } if let Some(measurements) = from.measurements { - measurements.iter().for_each(|(k, v)| { - if k == "client_sample_rate" && v.value != 0.0 { - res.sampling_factor = v.value; - res.sampling_weight = 1.0 / v.value; - res.sampling_weight_2 = (1.0 / v.value) as u64; - } else { - insert_num(k.clone(), v.value); - } + measurements.iter().for_each(|(k, v)| match k.as_str() { + "client_sample_rate" if v.value > 0.0 => res.sampling_factor *= v.value, + "server_sample_rate" if v.value > 0.0 => res.sampling_factor *= v.value, + _ => insert_num(k.clone(), v.value), }); } + // lower precision to compensate floating point errors + res.sampling_factor = (res.sampling_factor * 1e9).round() / 1e9; + res.sampling_weight *= 1.0 / res.sampling_factor; + res.sampling_weight_2 = res.sampling_weight.round() as u64; + if let Some(data) = from.data { data.iter().for_each(|(k, v)| { match v { @@ -222,7 +223,10 @@ mod tests { "value": 50.0 }, "client_sample_rate": { - "value": 0.01 + "value": 0.1 + }, + "server_sample_rate": { + "value": 0.2 } }, "organization_id": 1, diff --git a/rust_snuba/src/processors/snapshots/rust_snuba__processors__eap_spans__tests__serialization.snap b/rust_snuba/src/processors/snapshots/rust_snuba__processors__eap_spans__tests__serialization.snap index 05eac7c04f..79402c4c59 100644 --- a/rust_snuba/src/processors/snapshots/rust_snuba__processors__eap_spans__tests__serialization.snap +++ b/rust_snuba/src/processors/snapshots/rust_snuba__processors__eap_spans__tests__serialization.snap @@ -19,9 +19,9 @@ expression: span "exclusive_time_ms": 0.228, "retention_days": 90, "name": "/api/0/relays/projectconfigs/", - "sampling_factor": 0.01, - "sampling_weight": 100.0, - "sampling_weight_2": 100, + "sampling_factor": 0.02, + "sampling_weight": 50.0, + "sampling_weight_2": 50, "sign": 1, "attr_str_0": { "relay_protocol_version": "3",