-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(occurrences on eap): Implement EAP read for group hourly count (is_escalating algorithm)
#104830
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
Draft
shashjar
wants to merge
9
commits into
master
Choose a base branch
from
read-group-hourly-count-from-eap-old-is-escalating-algorithm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+438
−18
Draft
feat(occurrences on eap): Implement EAP read for group hourly count (is_escalating algorithm)
#104830
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b92953
Implement EAP read for group hourly count (`is_escalating` algorithm)
shashjar 89dc369
Gate the occurrence reads from EAP behind an option
shashjar f754784
Add tests
shashjar 21acae0
Fix mypy
shashjar 96d9f0f
Merge branch 'master' into read-group-hourly-count-from-eap-old-is-es…
shashjar 894a3f9
Use rollout utils to gate EAP read query & validation
shashjar fa0f8e4
Add `Occurrences` RPC framework class from https://github.com/getsent…
shashjar 7241a35
Abstract out logic for counting EAP occurrences with some filters
shashjar 06d84ba
Check option value for usage of EAP query result
shashjar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from sentry_protos.snuba.v1.request_common_pb2 import TraceItemType | ||
| from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey | ||
|
|
||
| from sentry.search.eap.columns import ColumnDefinitions, ResolvedAttribute | ||
| from sentry.search.eap.common_columns import COMMON_COLUMNS | ||
|
|
||
| OCCURRENCES_ALWAYS_PRESENT_ATTRIBUTES = [ | ||
| AttributeKey(name="group_id", type=AttributeKey.Type.TYPE_INT), | ||
| ] | ||
|
|
||
|
|
||
| OCCURRENCE_COLUMNS = { | ||
| column.public_alias: column | ||
| for column in ( | ||
| COMMON_COLUMNS | ||
| + [ | ||
| ResolvedAttribute( | ||
| public_alias="id", | ||
| internal_name="sentry.item_id", | ||
| search_type="string", | ||
| ), | ||
| ResolvedAttribute( | ||
| public_alias="group_id", | ||
| internal_name="group_id", | ||
| search_type="integer", | ||
| ), | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| OCCURRENCE_DEFINITIONS = ColumnDefinitions( | ||
| aggregates={}, # c.f. SPAN_AGGREGATE_DEFINITIONS when we're ready. | ||
| formulas={}, | ||
| columns=OCCURRENCE_COLUMNS, | ||
| contexts={}, | ||
| trace_item_type=TraceItemType.TRACE_ITEM_TYPE_OCCURRENCE, | ||
| filter_aliases={}, | ||
| alias_to_column=None, | ||
| column_to_alias=None, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import logging | ||
| from datetime import datetime | ||
|
|
||
| from google.protobuf.timestamp_pb2 import Timestamp | ||
| from sentry_protos.snuba.v1.endpoint_trace_item_table_pb2 import Column as EAPColumn | ||
| from sentry_protos.snuba.v1.endpoint_trace_item_table_pb2 import TraceItemTableRequest | ||
| from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType | ||
| from sentry_protos.snuba.v1.trace_item_attribute_pb2 import ( | ||
| AttributeAggregation, | ||
| AttributeKey, | ||
| AttributeValue, | ||
| ) | ||
| from sentry_protos.snuba.v1.trace_item_attribute_pb2 import Function as EAPFunction | ||
| from sentry_protos.snuba.v1.trace_item_attribute_pb2 import StrArray | ||
| from sentry_protos.snuba.v1.trace_item_filter_pb2 import ( | ||
| AndFilter, | ||
| ComparisonFilter, | ||
| TraceItemFilter, | ||
| ) | ||
|
|
||
| from sentry.utils import snuba_rpc | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def count_occurrences( | ||
| organization_id: int, | ||
| project_ids: list[int], | ||
| start: datetime, | ||
| end: datetime, | ||
| referrer: str, | ||
| group_id: int | None = None, | ||
| environments: list[str] | None = None, | ||
| ) -> int: | ||
| """ | ||
| Count the number of occurrences in EAP matching the given filters. | ||
|
|
||
| Args: | ||
| organization_id: The organization ID | ||
| project_ids: List of project IDs to query | ||
| start: Start timestamp | ||
| end: End timestamp | ||
| referrer: Referrer string for the query | ||
| group_id: Optional group ID to filter by | ||
| environments: Optional list of environments to filter by | ||
|
|
||
| Returns: | ||
| The count of matching occurrences, or 0 if the query fails | ||
| """ | ||
| start_timestamp = Timestamp() | ||
| start_timestamp.FromDatetime(start) | ||
| end_timestamp = Timestamp() | ||
| end_timestamp.FromDatetime(end) | ||
|
|
||
| count_column = EAPColumn( | ||
| aggregation=AttributeAggregation( | ||
| aggregate=EAPFunction.FUNCTION_COUNT, | ||
| key=AttributeKey(name="group_id", type=AttributeKey.TYPE_INT), | ||
| ), | ||
| label="count", | ||
| ) | ||
|
|
||
| filters: list[TraceItemFilter] = [] | ||
|
|
||
| if group_id is not None: | ||
| group_id_filter = TraceItemFilter( | ||
| comparison_filter=ComparisonFilter( | ||
| key=AttributeKey(name="group_id", type=AttributeKey.TYPE_INT), | ||
| op=ComparisonFilter.OP_EQUALS, | ||
| value=AttributeValue(val_int=group_id), | ||
| ) | ||
| ) | ||
| filters.append(group_id_filter) | ||
|
|
||
| if environments: | ||
| environment_filter = TraceItemFilter( | ||
| comparison_filter=ComparisonFilter( | ||
| key=AttributeKey(name="environment", type=AttributeKey.TYPE_STRING), | ||
| op=ComparisonFilter.OP_IN, | ||
| value=AttributeValue(val_str_array=StrArray(values=environments)), | ||
| ) | ||
| ) | ||
| filters.append(environment_filter) | ||
|
|
||
| item_filter = None | ||
| if len(filters) == 1: | ||
| item_filter = filters[0] | ||
| elif len(filters) > 1: | ||
| item_filter = TraceItemFilter(and_filter=AndFilter(filters=filters)) | ||
|
|
||
| request = TraceItemTableRequest( | ||
| meta=RequestMeta( | ||
| organization_id=organization_id, | ||
| project_ids=project_ids, | ||
| cogs_category="issues", | ||
| referrer=referrer, | ||
| start_timestamp=start_timestamp, | ||
| end_timestamp=end_timestamp, | ||
| trace_item_type=TraceItemType.TRACE_ITEM_TYPE_OCCURRENCE, | ||
| ), | ||
| columns=[count_column], | ||
| filter=item_filter, | ||
| limit=1, | ||
| ) | ||
|
|
||
| try: | ||
| count = 0 | ||
| responses = snuba_rpc.table_rpc([request]) | ||
| if responses and responses[0].column_values: | ||
| results = responses[0].column_values[0].results | ||
| if results: | ||
| count = int(results[0].val_double) | ||
| return count | ||
| except Exception: | ||
| logger.exception( | ||
| "Fetching occurrence count from EAP failed", | ||
| extra={ | ||
| "organization_id": organization_id, | ||
| "project_ids": project_ids, | ||
| "group_id": group_id, | ||
| "referrer": referrer, | ||
| }, | ||
| ) | ||
| return 0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.