Skip to content

ref(search) case insensitive grammar #69146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2f82625
ref(search): remove rawValue and value parsing from grammar
JonasBa Apr 16, 2024
6117ab4
ref(search): remove number parsing
JonasBa Apr 16, 2024
4601176
ref(search): parse values
JonasBa Apr 17, 2024
1a2f8c4
:hammer_and_wrench: apply eslint style fixes
getsantry[bot] Apr 17, 2024
c2ab492
ref(search): parse values under separate obj
JonasBa Apr 17, 2024
3dae3b4
ref(search): update grammar to parse numeric value
JonasBa Apr 17, 2024
0bae1ef
ref(search): update duration parsing
JonasBa Apr 17, 2024
40feffd
ref(search): remove unused prop
JonasBa Apr 17, 2024
2c3d9ba
ref(search): dont parse if parse config is not set
JonasBa Apr 17, 2024
29d0cf7
ref(search): case insensitive size units
JonasBa Apr 17, 2024
74a6303
ref(search): do the cheaper check first
JonasBa Apr 17, 2024
2ea61c3
ref(search): lowercase size before normalizing value
JonasBa Apr 17, 2024
e9f2805
ref(search): consume unit
JonasBa Apr 17, 2024
f3b89e4
ref(search): change grammar
JonasBa Apr 17, 2024
1074618
ref(search): maybe this
JonasBa Apr 17, 2024
b92036f
ref(search): use regexp
JonasBa Apr 17, 2024
c5b6f67
ref(search): remove blank lines
JonasBa Apr 17, 2024
1ee36b8
ref(search): revert case sensitivity changes
JonasBa Apr 17, 2024
7dceb94
ref(search): revert case sensitivity changes
JonasBa Apr 17, 2024
1a08cbc
ref(search): revert case sensitivity changes
JonasBa Apr 17, 2024
f40a9eb
ref(search): revert parse
JonasBa Apr 17, 2024
a02dd2c
ref(search): revert lowercase
JonasBa Apr 17, 2024
028c21f
ref(search): fix blank lines
JonasBa Apr 17, 2024
490c0c5
ref(search): add value parsing
JonasBa Apr 17, 2024
eb9ae7f
ref(search): add parse tests
JonasBa Apr 17, 2024
fe9c392
ref(search): allow case insensitive units
JonasBa Apr 17, 2024
bb906cb
Update static/app/components/searchSyntax/grammar.pegjs
JonasBa Apr 17, 2024
24b3b8b
ref(search): allow case insensitive units
JonasBa Apr 17, 2024
34373b4
ref(search): allow case insensitive units
JonasBa Apr 17, 2024
b4d76ac
Merge branch 'master' into jb/search/case-sensitive-size-backend
JonasBa Apr 17, 2024
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
10 changes: 8 additions & 2 deletions src/sentry/api/event_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
in_value = (&in_value_termination in_value_char)+
text_in_value = quoted_value / in_value
search_value = quoted_value / value
numeric_value = "-"? numeric ~r"[kmb]"? &(end_value / comma / closed_bracket)
numeric_value = "-"? numeric numeric_unit? &(end_value / comma / closed_bracket)
boolean_value = ~r"(true|1|false|0)"i &end_value
text_in_list = open_bracket text_in_value (spaces comma spaces !comma text_in_value?)* closed_bracket &end_value
numeric_in_list = open_bracket numeric_value (spaces comma spaces !comma numeric_value?)* closed_bracket &end_value
Expand All @@ -166,12 +166,18 @@
ms_format = ~r"\d{1,6}"
tz_format = ~r"[+-]\d{2}:\d{2}"


iso_8601_date_format = date_format time_format? ("Z" / tz_format)? &end_value
rel_date_format = ~r"[+-][0-9]+[wdhm]" &end_value
duration_format = numeric ("ms"/"s"/"min"/"m"/"hr"/"h"/"day"/"d"/"wk"/"w") &end_value
size_format = numeric ("bit"/"nb"/"bytes"/"kb"/"mb"/"gb"/"tb"/"pb"/"eb"/"zb"/"yb"/"kib"/"mib"/"gib"/"tib"/"pib"/"eib"/"zib"/"yib") &end_value
size_format = numeric (size_unit) &end_value
percentage_format = numeric "%"

numeric_unit = ~r"[kmb]"i
size_unit = bits / bytes
bits = ~r"bit|kib|mib|gib|tib|pib|eib|zib|yib"i
bytes = ~r"bytes|nb|kb|mb|gb|tb|pb|eb|zb|yb"i

# NOTE: the order in which these operators are listed matters because for
# example, if < comes before <= it will match that even if the operator is <=
operator = ">=" / "<=" / ">" / "<" / "=" / "!="
Expand Down
5 changes: 5 additions & 0 deletions src/sentry/search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def parse_size(value: str, size: str) -> float:
except ValueError:
raise InvalidQuery(f"{value} is not a valid size value")

# size units are case insensitive
size = size.lower()

if size == "bit":
byte = size_value / 8
elif size == "nb":
Expand Down Expand Up @@ -169,6 +172,8 @@ def parse_numeric_value(value: str, suffix: str | None = None) -> float:
if not suffix:
return parsed_value

# numeric "nuts" are case insensitive
suffix = suffix.lower()
numeric_multiples = {"k": 10.0**3, "m": 10.0**6, "b": 10.0**9}
if suffix not in numeric_multiples:
raise InvalidQuery(f"{suffix} is not a valid number suffix, must be k, m or b")
Expand Down
42 changes: 42 additions & 0 deletions tests/sentry/search/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
get_first_last_release_for_group,
get_latest_release,
get_numeric_field_value,
parse_bool,
parse_duration,
parse_numeric_value,
parse_query,
parse_size,
tokenize_query,
)
from sentry.services.hybrid_cloud.user.model import RpcUser
Expand Down Expand Up @@ -51,6 +54,45 @@ def test_get_numeric_field_value():
}


class TestParseNumericValue(TestCase):
def test_simple(self):
assert parse_numeric_value("10", None) == 10

def test_k(self):
assert parse_numeric_value("1", "k") == 1000.0
assert parse_numeric_value("1", "K") == 1000.0

def test_m(self):
assert parse_numeric_value("1", "m") == 1000000.0
assert parse_numeric_value("1", "M") == 1000000.0

def test_b(self):
assert parse_numeric_value("1", "b") == 1000000000.0
assert parse_numeric_value("1", "B") == 1000000000.0


class TestParseSizeValue(TestCase):
def test_simple(self):
assert parse_size("8", "bit") == 1

def test_uppercase(self):
assert parse_size("1", "KB") == 1000
assert parse_size("1", "kb") == 1000
assert parse_size("1", "Kb") == 1000


class TestParseBooleanValue(TestCase):
def test_true(self):
assert parse_bool("1") is True
assert parse_bool("TRUE") is True
assert parse_bool("true") is True

def test_false(self):
assert parse_bool("0") is False
assert parse_bool("FALSE") is False
assert parse_bool("false") is False


class TestParseDuration(TestCase):
def test_ms(self):
assert parse_duration("123", "ms") == 123
Expand Down
Loading