Skip to content

Commit 3bcb2b3

Browse files
authored
ref(EAP): uptime doesnt downsample at 30d (#7657)
Not all item types are going to have 30d as the max fidelity retention, so I added `ITEM_TYPE_FULL_RETENTION` which represents item types that should allow for more than 30days for `TIER_1` data. Also updated tests to the the `eap` marker since these tests are pretty slow otherwise
1 parent 699e881 commit 3bcb2b3

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

snuba/web/rpc/storage_routing/routing_strategies/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ class Outcome:
1212
TraceItemType.TRACE_ITEM_TYPE_LOG: DataCategory.LOG_ITEM,
1313
TraceItemType.TRACE_ITEM_TYPE_METRIC: DataCategory.TRACE_METRIC,
1414
}
15+
16+
ITEM_TYPE_FULL_RETENTION = {
17+
TraceItemType.TRACE_ITEM_TYPE_UPTIME_RESULT,
18+
}

snuba/web/rpc/storage_routing/routing_strategies/outcomes_based.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030
from snuba.web.rpc.storage_routing.common import extract_message_meta
3131
from snuba.web.rpc.storage_routing.routing_strategies.common import (
32+
ITEM_TYPE_FULL_RETENTION,
3233
ITEM_TYPE_TO_OUTCOME_CATEGORY,
3334
Outcome,
3435
)
@@ -164,6 +165,7 @@ def _update_routing_decision(
164165
if (
165166
state.get_int_config("enable_long_term_retention_downsampling", 0)
166167
and older_than_thirty_days
168+
and in_msg_meta.trace_item_type not in ITEM_TYPE_FULL_RETENTION
167169
):
168170
routing_decision.tier = Tier.TIER_8
169171

tests/web/rpc/v1/routing_strategies/test_outcomes_based.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ def _get_request_meta(
3232
end: datetime | None = None,
3333
hour_interval: int | None = None,
3434
downsampled_storage_config: DownsampledStorageConfig | None = None,
35+
trace_item_type: TraceItemType.ValueType | None = None,
3536
) -> RequestMeta:
3637
hour_interval = hour_interval or 24
3738
start = start or BASE_TIME - timedelta(hours=hour_interval)
3839
end = end or BASE_TIME
40+
trace_item_type = trace_item_type or TraceItemType.TRACE_ITEM_TYPE_SPAN
3941
return RequestMeta(
4042
project_ids=[_PROJECT_ID],
4143
organization_id=_ORG_ID,
4244
cogs_category="something",
4345
referrer="something",
4446
start_timestamp=Timestamp(seconds=int(start.timestamp())),
4547
end_timestamp=Timestamp(seconds=int(end.timestamp())),
46-
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
48+
trace_item_type=trace_item_type,
4749
downsampled_storage_config=downsampled_storage_config,
4850
)
4951

5052

5153
@pytest.fixture
52-
def store_outcomes_fixture(clickhouse_db: Any) -> None:
54+
def store_outcomes_fixture(eap: Any) -> None:
5355
# Generate 24 hours of outcomes data with 1M outcomes per hour
5456
outcome_data = []
5557
for hour in range(24):
@@ -59,8 +61,8 @@ def store_outcomes_fixture(clickhouse_db: Any) -> None:
5961
store_outcomes_data(outcome_data)
6062

6163

62-
@pytest.mark.clickhouse_db
6364
@pytest.mark.redis_db
65+
@pytest.mark.eap
6466
def test_outcomes_based_routing_queries_daily_table() -> None:
6567
strategy = OutcomesBasedRoutingStrategy()
6668

@@ -82,7 +84,42 @@ def test_outcomes_based_routing_queries_daily_table() -> None:
8284
assert routing_decision.can_run
8385

8486

85-
@pytest.mark.clickhouse_db
87+
@pytest.mark.eap
88+
@pytest.mark.redis_db
89+
def test_item_type_full_retention() -> None:
90+
"""
91+
Certain item types will not use the long term retention downsampling,
92+
find them in ITEM_TYPE_FULL_RETENTION routing_strategies/common.py
93+
"""
94+
state.set_config(
95+
"enable_long_term_retention_downsampling",
96+
1,
97+
)
98+
strategy = OutcomesBasedRoutingStrategy()
99+
100+
# request that queries last 50 days of data
101+
end_time = datetime.now(UTC).replace(hour=0, minute=0, second=0, microsecond=0)
102+
start_time = end_time - timedelta(hours=1200) # 50 days
103+
request = TraceItemTableRequest(
104+
meta=_get_request_meta(
105+
start=start_time,
106+
end=end_time,
107+
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_UPTIME_RESULT,
108+
)
109+
)
110+
request.meta.downsampled_storage_config.mode = DownsampledStorageConfig.MODE_NORMAL
111+
context = RoutingContext(
112+
in_msg=request,
113+
timer=Timer("test"),
114+
query_id=uuid.uuid4().hex,
115+
)
116+
routing_decision = strategy.get_routing_decision(context)
117+
assert routing_decision.tier == Tier.TIER_1
118+
assert routing_decision.clickhouse_settings == {"max_threads": 10}
119+
assert routing_decision.can_run
120+
121+
122+
@pytest.mark.eap
86123
@pytest.mark.redis_db
87124
def test_outcomes_based_routing_sampled_data_past_thirty_days() -> None:
88125
state.set_config(
@@ -156,7 +193,7 @@ def test_outcomes_based_routing_sampled_data_past_thirty_days() -> None:
156193
assert routing_decision.can_run
157194

158195

159-
@pytest.mark.clickhouse_db
196+
@pytest.mark.eap
160197
@pytest.mark.redis_db
161198
def test_outcomes_based_routing_normal_mode(store_outcomes_fixture: Any) -> None:
162199
strategy = OutcomesBasedRoutingStrategy()
@@ -176,7 +213,7 @@ def test_outcomes_based_routing_normal_mode(store_outcomes_fixture: Any) -> None
176213
assert routing_decision.can_run
177214

178215

179-
@pytest.mark.clickhouse_db
216+
@pytest.mark.eap
180217
@pytest.mark.redis_db
181218
def test_outcomes_based_routing_downsample(store_outcomes_fixture: Any) -> None:
182219
state.set_config("OutcomesBasedRoutingStrategy.max_items_before_downsampling", 5_000_000)
@@ -220,7 +257,7 @@ def test_outcomes_based_routing_downsample(store_outcomes_fixture: Any) -> None:
220257
assert routing_decision.can_run
221258

222259

223-
@pytest.mark.clickhouse_db
260+
@pytest.mark.eap
224261
@pytest.mark.redis_db
225262
def test_outcomes_based_routing_highest_accuracy_mode(store_outcomes_fixture: Any) -> None:
226263
strategy = OutcomesBasedRoutingStrategy()
@@ -240,7 +277,7 @@ def test_outcomes_based_routing_highest_accuracy_mode(store_outcomes_fixture: An
240277
assert routing_decision.can_run
241278

242279

243-
@pytest.mark.clickhouse_db
280+
@pytest.mark.eap
244281
@pytest.mark.redis_db
245282
def test_outcomes_based_routing_defaults_to_tier1_for_unspecified_item_type(
246283
store_outcomes_fixture: Any,

0 commit comments

Comments
 (0)