Skip to content

Commit

Permalink
fix(eap): Switch to using letters only and not special characters in …
Browse files Browse the repository at this point in the history
…tags (#6847)
  • Loading branch information
phacops authored Feb 1, 2025
1 parent 6092eff commit dd69627
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 6 additions & 6 deletions snuba/web/rpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ def __extract_request_tags(self, in_msg: Tin) -> dict[str, str]:
if hasattr(meta, "start_timestamp") and hasattr(meta, "end_timestamp"):
start = meta.start_timestamp.ToDatetime()
end = meta.end_timestamp.ToDatetime()
delta_in_hours = int((end - start).total_seconds() / 3600)
delta_in_hours = (end - start).total_seconds() / 3600
bucket = bisect_left(_TIME_PERIOD_HOURS_BUCKETS, delta_in_hours)
if delta_in_hours == 1:
tags["time_period"] = "<= 1 hour"
if delta_in_hours <= 1:
tags["time_period"] = "lte_1_hour"
elif delta_in_hours <= 24:
tags["time_period"] = "<= 1 day"
tags["time_period"] = "lte_1_day"
else:
tags["time_period"] = (
f"<= {_TIME_PERIOD_HOURS_BUCKETS[bucket] // 24} days"
f"lte_{_TIME_PERIOD_HOURS_BUCKETS[bucket] // 24}_days"
if bucket < _BUCKETS_COUNT
else f"> {_TIME_PERIOD_HOURS_BUCKETS[_BUCKETS_COUNT - 1] // 24} days"
else f"gt_{_TIME_PERIOD_HOURS_BUCKETS[_BUCKETS_COUNT - 1] // 24}_days"
)

if hasattr(meta, "referrer"):
Expand Down
15 changes: 8 additions & 7 deletions tests/web/rpc/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ def test_trim_time_range() -> None:
@pytest.mark.parametrize(
"hours, expected_time_bucket",
[
(1, "<= 1 hour"),
(24, "<= 1 day"),
(3 * 24, "<= 7 days"),
(11 * 24, "<= 14 days"),
(22 * 24, "<= 30 days"),
(90 * 24, "<= 90 days"),
(99 * 24, "> 90 days"),
(0.5, "lte_1_hour"),
(1, "lte_1_hour"),
(24, "lte_1_day"),
(3 * 24, "lte_7_days"),
(11 * 24, "lte_14_days"),
(22 * 24, "lte_30_days"),
(90 * 24, "lte_90_days"),
(99 * 24, "gt_90_days"),
],
)
def test_tagged_metrics(hours: int, expected_time_bucket: str) -> None:
Expand Down

0 comments on commit dd69627

Please sign in to comment.