-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(alerts): on demand metric timeseries support #53053
Changes from 20 commits
9684af3
68586dd
c4ecde8
e1d4ec4
a6229ac
6da4e6e
eb939c5
b8fc1cd
ef71fd4
1eb6e1d
b63451e
b82d399
b604e73
984bd99
cfaf431
2b34075
8af1295
0e226b3
abd3625
7d8daf8
3b2fd6f
c429213
2ea5a82
2f5de75
662badd
25d8adb
5f7a13d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,8 @@ | |
"p99": "d", | ||
} | ||
|
||
# Query fields that on their own do not require on-demand metric extraction. | ||
# Query fields that on their own do not require on-demand metric extraction but if present in an on-demand query | ||
# will be converted to metric extraction conditions. | ||
_STANDARD_METRIC_FIELDS = [ | ||
"release", | ||
"dist", | ||
|
@@ -135,7 +136,9 @@ | |
"browser.name", | ||
"os.name", | ||
"geo.country_code", | ||
# These fields are skipped during on demand spec generation and will not be converted to metric extraction conditions | ||
"event.type", | ||
"project", | ||
] | ||
|
||
# Operators used in ``ComparingRuleCondition``. | ||
|
@@ -222,9 +225,8 @@ def is_on_demand_query( | |
for field in _get_aggregate_fields(aggregate): | ||
if not _is_standard_metrics_field(field): | ||
return True | ||
|
||
try: | ||
return not _is_standard_metrics_query(event_search.parse_search_query(query or "")) | ||
return not is_standard_metrics_query(query) | ||
except InvalidSearchQuery: | ||
logger.error(f"Failed to parse search query: {query}", exc_info=True) | ||
return False | ||
|
@@ -250,6 +252,10 @@ def _get_aggregate_fields(aggregate: str) -> Sequence[str]: | |
return [] | ||
|
||
|
||
def is_standard_metrics_query(query: Optional[str] = "") -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we expose just one out of |
||
return _is_standard_metrics_query(event_search.parse_search_query(query)) | ||
|
||
|
||
def _is_standard_metrics_query(tokens: Sequence[QueryToken]) -> bool: | ||
""" | ||
Recursively checks if any of the supplied token contain search filters that can't be handled by standard metrics. | ||
|
@@ -304,11 +310,17 @@ def __init__(self, field: str, query: str): | |
|
||
""" | ||
|
||
# On-demand metrics are implicitly transaction metrics. Remove the | ||
# filter from the query since it can't be translated to a RuleCondition. | ||
self._query = re.sub(r"event\.type:transaction\s*", "", query) | ||
self._init__query(query) | ||
self._init_aggregate(field) | ||
|
||
def _init__query(self, query: str) -> None: | ||
# On-demand metrics are implicitly transaction metrics. Remove the | ||
# filters from the query that can't be translated to a RuleCondition. | ||
query = re.sub(r"event\.type:transaction\s*", "", query) | ||
query = re.sub(r"project:\w+\s*", "", query) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the project be quoted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, handled with 2ea5a82 |
||
|
||
self._query = query.strip() | ||
|
||
def _init_aggregate(self, aggregate: str) -> None: | ||
""" | ||
Extracts the field name, metric type and metric operation from a Discover | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to just check
if isinstance(self, TimeSeriesQueryBuilder)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Done in 25d8adb