Skip to content
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

fix(releases): For semver releases, get latest release as the resolving one #80737

Merged
merged 9 commits into from
Nov 15, 2024

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Nov 14, 2024

Select the latest semver release for the project rather than the latest seen for the group.

This is a follow-up to #80655.
This fixes the customer issue #69937 (and possibly these: #74448 and #80194).

@armenzg armenzg self-assigned this Nov 14, 2024
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 14, 2024
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #80737    +/-   ##
========================================
  Coverage   78.39%   78.39%            
========================================
  Files        7206     7206            
  Lines      319290   319437   +147     
  Branches    43977    43991    +14     
========================================
+ Hits       250306   250434   +128     
- Misses      62607    62618    +11     
- Partials     6377     6385     +8     

def get_current_release_version_of_group(
group: Group, follows_semver: bool = False
) -> Release | None:
def get_current_release_version_of_group(group: Group, follows_semver: bool = False) -> str | None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add stronger typing enforcement here. It returns a string.

@@ -140,13 +138,12 @@ def get_current_release_version_of_group(
try:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes in this block besides some minor refactoring to help comprehension.

"organizations:releases-resolve-next-release-semver-fix",
project.organization,
):
resolving_release_version = get_latest_release(projects[0]).version
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix.

if project is None:
project = self.project
if "substatus" not in kwargs:
kwargs["substatus"] = GroupSubStatus.NEW
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor improvement. You could see a logged error when this is not set.

@@ -328,7 +328,11 @@ def test_resolved_in_next_release_non_semver(self):
project = self.create_project()
project.flags.has_releases = True
project.save()
group = self.create_group(project=project)
# Using store_event() instead of create_group() produces GroupRelease objects
# which is considered during the update_groups() call
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change helps the test go through the ingestion pipeline, thus, creating GroupRelease objects.

Entrypoint:

_get_or_create_release_many(jobs, projects)

Where is used:

def get_current_release_version_of_group(
group: Group, follows_semver: bool = False
) -> Release | None:
"""
Function that returns the latest release version associated with a Group, and by latest we
mean either most recent (date) or latest in semver versioning scheme
Inputs:
* group: Group of the issue
* follows_semver: flag that determines whether the project of the group follows semantic
versioning or not.
Returns:
current_release_version
"""
current_release_version = None
if follows_semver:
try:
# This sets current_release_version to the latest semver version associated with a group
order_by_semver_desc = [f"-{col}" for col in Release.SEMVER_COLS]
current_release_version = (
Release.objects.filter_to_semver()
.filter(
id__in=GroupRelease.objects.filter(
project_id=group.project.id, group_id=group.id
).values_list("release_id"),
)

# For semver projects, we consider resolution based on an expression rather than a specific release,
# thus, it is considered resolved in the release that has the highest semver
assert group_resolution.type == GroupResolution.Type.in_release
assert group_resolution.status == GroupResolution.Status.resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is evidence that we're going through the same code path as reported by Dropbox.

# In semver projects, and thereby semver releases, we determine
# resolutions by comparing against an expression rather than a
# specific release (i.e. >current_release_version). Consequently,
# at this point we can consider this GroupResolution as resolved
# in release
resolution_params.update(
{
"type": GroupResolution.Type.in_release,
"status": GroupResolution.Status.resolved,
}

@@ -351,17 +355,22 @@ def test_resolved_in_next_release_non_semver(self):
assert group_resolution.release.version == most_recent_version.version

# XXX: Remove this test once the feature flag is removed
def test_resolved_in_next_release_semver_without_feature_flag(self):
def test_resolved_in_next_release_semver_no_flag_and_first_release(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have added one more test (one without setting the release), however, we're moving away from this logic, thus, I do not deem it necessary.

tests/sentry/issues/endpoints/test_group_details.py Outdated Show resolved Hide resolved
)
and follows_semver
):
current_release_version = get_latest_release(projects[0]).version
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix.

new_release = Release.get_or_create(version="[email protected]+0", project=project)
# A lesser release than 2.x but created more recently than 3.x
old_version = Release.get_or_create(version="[email protected]+0", project=project)
for release in releases + [old_version]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, only [email protected]+0 would not unresolve.

Copy link
Member

@snigdhas snigdhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@@ -419,9 +416,19 @@ def update_groups(
release_version=release.version,
)

current_release_version = get_current_release_version_of_group(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should look to remove this as a follow-up

current_release_version = get_current_release_version_of_group(
group=group, follows_semver=follows_semver
)
and I think that actually that code path should have the same fix you're adding in here. So might be worth also adding the fix there as part of this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed-up here: #80821

@armenzg armenzg enabled auto-merge (squash) November 15, 2024 13:04
@armenzg armenzg merged commit a087bb8 into master Nov 15, 2024
50 checks passed
@armenzg armenzg deleted the ref/releases_code/armenzg branch November 15, 2024 13:32
armenzg added a commit that referenced this pull request Nov 15, 2024
In #80737 we provided a fix within `get_latest_release()` but it makes more sense to include inside of `get_current_release_version_of_group()` for it will make it available to other parts of the codebase. For example:
https://github.com/getsentry/sentry/blob/c0797226ec0dc304d766796713121a880df38811/src/sentry/integrations/tasks/sync_status_inbound.py#L112-L114
armenzg added a commit that referenced this pull request Nov 15, 2024
In #80737 we provided a fix within `get_latest_release()` but it makes more sense to include inside of `get_current_release_version_of_group()` for it will make it available to other parts of the codebase. For example:
https://github.com/getsentry/sentry/blob/c0797226ec0dc304d766796713121a880df38811/src/sentry/integrations/tasks/sync_status_inbound.py#L112-L114
armenzg added a commit that referenced this pull request Nov 15, 2024
armenzg added a commit that referenced this pull request Nov 18, 2024
…p() (#80821)

In #80737 we provided a fix within `get_latest_release()` but it makes
more sense to include it inside of
`get_current_release_version_of_group()` for it will make it available
to other parts of the codebase. For example:
https://github.com/getsentry/sentry/blob/c0797226ec0dc304d766796713121a880df38811/src/sentry/integrations/tasks/sync_status_inbound.py#L112-L114
@armenzg
Copy link
Member Author

armenzg commented Nov 29, 2024

I will enable this for GA next week.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: Releases Product Area: Releases Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants