From cd87baa54c222cce639a51bcf510b0a65e5aa1d4 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Fri, 18 Aug 2023 16:24:28 -0700 Subject: [PATCH] feat(issues): Add environment to regression activity We're storing the release version and if the project is using semver. This stores the event's environment. It can be helpful to know which of your environments caused a regression. --- src/sentry/event_manager.py | 2 + .../event_manager/test_event_manager.py | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/sentry/event_manager.py b/src/sentry/event_manager.py index d5b51fc6d4af5..428c2c323acb3 100644 --- a/src/sentry/event_manager.py +++ b/src/sentry/event_manager.py @@ -1979,9 +1979,11 @@ def _handle_regression(group: Group, event: Event, release: Optional[Release]) - ) if is_regression: + environment_name = event.get_tag("environment") activity_data: dict[str, str | bool] = { "event_id": event.event_id, "version": release.version if release else "", + "environment": environment_name if environment_name else "", } if resolved_in_activity and release: activity_data.update( diff --git a/tests/sentry/event_manager/test_event_manager.py b/tests/sentry/event_manager/test_event_manager.py index fde16c4a69a25..5861450aa3be6 100644 --- a/tests/sentry/event_manager/test_event_manager.py +++ b/tests/sentry/event_manager/test_event_manager.py @@ -342,6 +342,44 @@ def test_marks_as_unresolved_with_new_release( mock_send_activity_notifications_delay.assert_called_once_with(activity.id) + @mock.patch("sentry.event_manager.plugin_is_regression") + def test_sets_regression_environment(self, plugin_is_regression): + plugin_is_regression.return_value = True + manager = EventManager( + make_event( + event_id="a" * 32, + checksum="a" * 32, + timestamp=time() - 50000, # need to work around active_at + ) + ) + event = manager.save(self.project.id) + + assert event.group is not None + group = event.group + + group.update(status=GroupStatus.RESOLVED, substatus=None) + + activity = Activity.objects.create( + group=group, + project=group.project, + type=ActivityType.SET_RESOLVED_IN_RELEASE.value, + data={"version": ""}, + ) + + manager = EventManager( + make_event( + event_id="c" * 32, checksum="a" * 32, timestamp=time(), environment="staging" + ) + ) + event = manager.save(self.project.id) + assert event.group_id == group.id + + group = Group.objects.get(id=group.id) + assert group.status == GroupStatus.UNRESOLVED + + activity = Activity.objects.get(group=group, type=ActivityType.SET_REGRESSION.value) + assert activity.data["environment"] == "staging" + @mock.patch("sentry.tasks.activity.send_activity_notifications.delay") @mock.patch("sentry.event_manager.plugin_is_regression") def test_that_release_in_latest_activity_prior_to_regression_is_not_overridden(