-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(occurrences on eap): Implement double reads from EAP for error counts timeseries #107308
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
Open
shashjar
wants to merge
4
commits into
master
Choose a base branch
from
implement-eap-occurrence-double-reads-get-errors-counts-timeseries
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.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cd1da73
Implement double reads of occurrences from EAP for `get_errors_counts…
shashjar 9b35157
Merge branch 'master' into implement-eap-occurrence-double-reads-get-…
shashjar 14b28b1
Add `type` attribute for occurrences
shashjar b2204cd
Merge branch 'master' into implement-eap-occurrence-double-reads-get-…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
| import logging | ||
| from datetime import datetime, timezone | ||
| from typing import Any | ||
|
|
||
| from snuba_sdk import Request as SnubaRequest | ||
|
|
@@ -12,10 +13,18 @@ | |
| from snuba_sdk.orderby import Direction, OrderBy | ||
| from snuba_sdk.query import Query | ||
|
|
||
| from sentry.models.organization import Organization | ||
| from sentry.models.project import Project | ||
| from sentry.search.eap.occurrences.rollout_utils import EAPOccurrencesComparator | ||
| from sentry.search.eap.types import SearchResolverConfig | ||
| from sentry.search.events.types import SnubaParams | ||
| from sentry.snuba.dataset import Dataset | ||
| from sentry.snuba.occurrences_rpc import Occurrences | ||
| from sentry.snuba.referrer import Referrer | ||
| from sentry.utils import snuba | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def get_errors_counts_timeseries_by_project_and_release( | ||
| end: datetime, | ||
|
|
@@ -24,6 +33,45 @@ def get_errors_counts_timeseries_by_project_and_release( | |
| release_value_list: list[str], | ||
| start: datetime, | ||
| environments_list: list[str] | None = None, | ||
| ) -> list[dict[str, Any]]: | ||
| snuba_results = _get_errors_counts_timeseries_snuba( | ||
| end=end, | ||
| organization_id=organization_id, | ||
| project_id_list=project_id_list, | ||
| release_value_list=release_value_list, | ||
| start=start, | ||
| environments_list=environments_list, | ||
| ) | ||
| results = snuba_results | ||
|
|
||
| if EAPOccurrencesComparator.should_check_experiment( | ||
| "release_thresholds.get_errors_counts_timeseries" | ||
| ): | ||
| eap_results = _get_errors_counts_timeseries_eap( | ||
| end=end, | ||
| organization_id=organization_id, | ||
| project_id_list=project_id_list, | ||
| release_value_list=release_value_list, | ||
| start=start, | ||
| environments_list=environments_list, | ||
| ) | ||
| results = EAPOccurrencesComparator.check_and_choose( | ||
| snuba_results, | ||
| eap_results, | ||
| "release_thresholds.get_errors_counts_timeseries", | ||
| is_experimental_data_a_null_result=len(eap_results) == 0, | ||
| ) | ||
|
|
||
| return results | ||
|
|
||
|
|
||
| def _get_errors_counts_timeseries_snuba( | ||
| end: datetime, | ||
| organization_id: int, | ||
| project_id_list: list[int], | ||
| release_value_list: list[str], | ||
| start: datetime, | ||
| environments_list: list[str] | None = None, | ||
| ) -> list[dict[str, Any]]: | ||
| additional_conditions = [] | ||
| if environments_list: | ||
|
|
@@ -61,3 +109,92 @@ def get_errors_counts_timeseries_by_project_and_release( | |
| )["data"] | ||
|
|
||
| return data | ||
|
|
||
|
|
||
| def _get_errors_counts_timeseries_eap( | ||
| end: datetime, | ||
| organization_id: int, | ||
| project_id_list: list[int], | ||
| release_value_list: list[str], | ||
| start: datetime, | ||
| environments_list: list[str] | None = None, | ||
| ) -> list[dict[str, Any]]: | ||
| try: | ||
| organization = Organization.objects.get(id=organization_id) | ||
| except Organization.DoesNotExist: | ||
| logger.warning( | ||
| "Organization not found for EAP error counts timeseries query", | ||
| extra={"organization_id": organization_id}, | ||
| ) | ||
| return [] | ||
|
|
||
| projects = list(Project.objects.filter(id__in=project_id_list, organization_id=organization_id)) | ||
| if not projects: | ||
| return [] | ||
|
|
||
shashjar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not release_value_list: | ||
| return [] | ||
|
|
||
| query_string = "type:error" | ||
|
Member
Author
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.
|
||
|
|
||
| if len(release_value_list) == 1: | ||
| query_string += f' release:"{release_value_list[0]}"' | ||
| else: | ||
| release_filter = " OR ".join([f'release:"{r}"' for r in release_value_list]) | ||
| query_string += f" ({release_filter})" | ||
|
|
||
| if environments_list: | ||
| if len(environments_list) == 1: | ||
| query_string += f' environment:"{environments_list[0]}"' | ||
| else: | ||
| env_filter = " OR ".join([f'environment:"{e}"' for e in environments_list]) | ||
| query_string += f" ({env_filter})" | ||
shashjar marked this conversation as resolved.
Show resolved
Hide resolved
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| snuba_params = SnubaParams( | ||
| start=start, | ||
| end=end, | ||
| organization=organization, | ||
| projects=projects, | ||
| granularity_secs=60, | ||
| ) | ||
|
|
||
| try: | ||
| timeseries_results = Occurrences.run_grouped_timeseries_query( | ||
| params=snuba_params, | ||
| query_string=query_string, | ||
| y_axes=["count()"], | ||
| groupby=["release", "project_id", "environment"], | ||
| referrer=Referrer.SNUBA_SESSIONS_CHECK_RELEASES_HAVE_HEALTH_DATA.value, | ||
| config=SearchResolverConfig(), | ||
| ) | ||
shashjar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Transform to match Snuba response format | ||
| transformed: list[dict[str, Any]] = [] | ||
| for row in timeseries_results: | ||
| count = row.get("count()", 0) | ||
| if count > 0: | ||
| bucket_dt = datetime.fromtimestamp(row["time"], tz=timezone.utc) | ||
| transformed.append( | ||
| { | ||
| "release": row.get("release"), | ||
| "project_id": int(row["project_id"]), | ||
| "environment": row.get("environment"), | ||
| "time": bucket_dt.isoformat(), | ||
| "count()": int(count), | ||
| } | ||
| ) | ||
|
|
||
| transformed.sort(key=lambda x: x["time"], reverse=True) | ||
|
|
||
| return transformed | ||
|
|
||
| except Exception: | ||
| logger.exception( | ||
| "Fetching error counts timeseries from EAP failed", | ||
| extra={ | ||
| "organization_id": organization_id, | ||
| "project_ids": project_id_list, | ||
| "releases": release_value_list, | ||
| }, | ||
| ) | ||
| return [] | ||
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
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.