Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 21 additions & 2 deletions src/sentry/grouping/parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,27 @@ def _get_pattern(self, raw_pattern: str) -> str:
(\d{4}-?[01]\d-?[0-3]\d[\sT][0-2]\d:?[0-5]\d) # no seconds
)
|
# Kitchen
([1-9]\d?:\d{2}(:\d{2})?(?:\s?[aApP][Mm])?)
# Kitchen, 12-hr
(
(?<!\d) # Negative lookbehind to ensure hour has at most two digits
([1-9]|1[0-2]) # Hour, no leading zero, 1-12 hours
:[0-5]\d # Minute
(:[0-5]\d)? # Optional second
(?![\d:]) # Negative lookahead to ensure second (or minute, if there are no seconds)
# has at most two digits, and to make sure that if there are seconds, they
# get consumed by the optional seconds part of the pattern (and are
# thereby forced to abide by its restrictions on possible values)
(?:\s?[aApP][Mm])? # Optional, optionally-space-separated AM/PM
)
|
# Kitchen, 24-hr
(
(?<!\d) # Negative lookbehind (same logic as 12-hr pattern above)
(0?\d|1\d|2[0-3]) # Hour, optional leading zero, 0-23 hours
:[0-5]\d # Minute
(:[0-5]\d)? # Optional second
(?![\d:]) # Negative lookahead (same logic as in 12-hr pattern above)
)
|
# Date
(\d{4}-[01]\d-[0-3]\d)
Expand Down
63 changes: 9 additions & 54 deletions tests/sentry/grouping/test_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
"traceparent: <traceparent>",
),
("ip - too many initial characters", "12345:6:789", "<int>:<int>:<int>"),
("ip - too many final characters", "123:4:56789", "<int>:<int>:<int>"),
("traceparent - aws", "1-67891233-abcdef012345678912345678", "<traceparent>"),
(
"traceparent - aws, but not word boundary",
Expand Down Expand Up @@ -98,8 +100,15 @@
("date - kitchen lowercase with space", "12:31 pm", "<date>"),
("date - kitchen 24-hour", "23:21", "<date>"),
("date - kitchen 24-hour with seconds", "23:21:12", "<date>"),
("date - kitchen 24-hour with leading zero", "09:08", "<date>"),
("date - kitchen 24-hour no leading zero", "9:08", "<date>"),
("date - kitchen 24-hour midnight with leading zero", "00:31", "<date>"),
("date - kitchen 24-hour midnight no leading zero", "0:12", "<date>"),
("date - kitchen too many initial digits", "908:31", "<int>:<int>"),
("date - kitchen too many final digits", "11:2112", "<int>:<int>"),
("date - kitchen hour too big", "31:21", "<int>:<int>"),
("date - kitchen minute too big", "12:99", "<int>:<int>"),
("date - kitchen second too big", "12:31:99", "<int>:<int>:<int>"),
("date - time", "15:04:05", "<date>"),
("date - basic", "Mon Jan 02, 1999", "<date>"),
("date - datetime compressed date", "20240220 11:55:33.546593", "<date>"),
Expand Down Expand Up @@ -232,48 +241,6 @@ def test_experimental_parameterization(name: str, input: str, expected: str) ->
# parameterization. (Remember to remove the last item in each tuple for the cases you fix.)
incorrect_cases = [
# ("name", "input", "desired", "actual")
(
"date - kitchen 24-hour with leading zero",
"09:08",
"<date>",
"<int>:<int>",
),
(
"date - kitchen 24-hour midnight with leading zero",
"00:31",
"<date>",
"<int>:<int>",
),
(
"date - kitchen 24-hour midnight no leading zero",
"0:12",
"<date>",
"<int>:<int>",
),
(
"date - kitchen hour too big",
"31:21",
"<int>:<int>",
"<date>",
),
(
"date - kitchen minute too big",
"12:99",
"<int>:<int>",
"<date>",
),
(
"date - kitchen second too big",
"12:31:99",
"<int>:<int>:<int>",
"<date>",
),
(
"date - kitchen too many final digits",
"11:2112",
"<int>:<int>",
"<date>12",
),
(
"hex without prefix - no letters, 8+ digits, negative",
"-12345678",
Expand Down Expand Up @@ -310,18 +277,6 @@ def test_experimental_parameterization(name: str, input: str, expected: str) ->
"Fee::add() called too early",
"<ip>() called too early",
),
(
"ip - too many initial characters",
"12345:6:789",
"<int>:<int>:<int>",
"<int>:<date>9",
),
(
"ip - too many final characters",
"123:4:56789",
"<int>:<int>:<int>",
"<int>:<date>789",
),
(
"ip - v4 mapped to v6",
"::ffff:192.168.1.1",
Expand Down
Loading