Skip to content

Commit 032ddf2

Browse files
authored
feat(uptime): Add feature flag to prevent creating issue platform issues for uptime (#74530)
This adds a flag to control whether uptime monitors will create issues in the issue platform
1 parent f7d53d7 commit 032ddf2

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/sentry/features/temporary.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ def register_temporary_features(manager: FeatureManager):
469469
manager.add("organizations:uptime-automatic-subscription-creation", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE)
470470
# Enabled returning uptime monitors from the rule api
471471
manager.add("organizations:uptime-rule-api", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE)
472+
# Enable creating issues via the issue platform
473+
manager.add("organizations:uptime-create-issues", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE)
472474
# Enables uptime related settings for projects and orgs
473475
manager.add('organizations:uptime-settings', OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE)
474476
manager.add("organizations:use-metrics-layer", OrganizationFeature, FeatureHandlerStrategy.REMOTE)

src/sentry/uptime/consumers/results_consumer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
CheckResult,
1111
)
1212

13+
from sentry import features
1314
from sentry.conf.types.kafka_definition import Topic
1415
from sentry.remote_subscriptions.consumers.result_consumer import (
1516
ResultProcessor,
@@ -175,13 +176,19 @@ def handle_result_for_project_active_mode(
175176
project_subscription.uptime_status == UptimeStatus.OK
176177
and result["status"] == CHECKSTATUS_FAILURE
177178
):
178-
create_issue_platform_occurrence(result, project_subscription)
179+
if features.has(
180+
"organizations:uptime-create-issues", project_subscription.project.organization
181+
):
182+
create_issue_platform_occurrence(result, project_subscription)
179183
project_subscription.update(uptime_status=UptimeStatus.FAILED)
180184
elif (
181185
project_subscription.uptime_status == UptimeStatus.FAILED
182186
and result["status"] == CHECKSTATUS_SUCCESS
183187
):
184-
resolve_uptime_issue(project_subscription)
188+
if features.has(
189+
"organizations:uptime-create-issues", project_subscription.project.organization
190+
):
191+
resolve_uptime_issue(project_subscription)
185192
project_subscription.update(uptime_status=UptimeStatus.OK)
186193

187194

tests/sentry/uptime/consumers/test_results_consumers.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def send_result(self, result: CheckResult):
6464

6565
def test(self):
6666
result = self.create_uptime_result(self.subscription.subscription_id)
67-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
67+
with mock.patch(
68+
"sentry.uptime.consumers.results_consumer.metrics"
69+
) as metrics, self.feature("organizations:uptime-create-issues"):
6870
self.send_result(result)
6971
metrics.incr.assert_has_calls(
7072
[
@@ -81,12 +83,33 @@ def test(self):
8183
self.project_subscription.refresh_from_db()
8284
assert self.project_subscription.uptime_status == UptimeStatus.FAILED
8385

86+
def test_no_create_issues_feature(self):
87+
result = self.create_uptime_result(self.subscription.subscription_id)
88+
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
89+
self.send_result(result)
90+
metrics.incr.assert_has_calls(
91+
[
92+
call(
93+
"uptime.result_processor.handle_result_for_project",
94+
tags={"status": CHECKSTATUS_FAILURE, "mode": "auto_detected_active"},
95+
),
96+
]
97+
)
98+
99+
hashed_fingerprint = md5(str(self.project_subscription.id).encode("utf-8")).hexdigest()
100+
with pytest.raises(Group.DoesNotExist):
101+
Group.objects.get(grouphash__hash=hashed_fingerprint)
102+
self.project_subscription.refresh_from_db()
103+
assert self.project_subscription.uptime_status == UptimeStatus.FAILED
104+
84105
def test_resolve(self):
85106
result = self.create_uptime_result(
86107
self.subscription.subscription_id,
87108
scheduled_check_time=datetime.now() - timedelta(minutes=5),
88109
)
89-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
110+
with mock.patch(
111+
"sentry.uptime.consumers.results_consumer.metrics"
112+
) as metrics, self.feature("organizations:uptime-create-issues"):
90113
self.send_result(result)
91114
metrics.incr.assert_has_calls(
92115
[
@@ -109,7 +132,9 @@ def test_resolve(self):
109132
status=CHECKSTATUS_SUCCESS,
110133
scheduled_check_time=datetime.now() - timedelta(minutes=4),
111134
)
112-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
135+
with mock.patch(
136+
"sentry.uptime.consumers.results_consumer.metrics"
137+
) as metrics, self.feature("organizations:uptime-create-issues"):
113138
self.send_result(result)
114139
metrics.incr.assert_has_calls(
115140
[
@@ -127,7 +152,9 @@ def test_resolve(self):
127152
def test_no_subscription(self):
128153
subscription_id = uuid.uuid4().hex
129154
result = self.create_uptime_result(subscription_id)
130-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
155+
with mock.patch(
156+
"sentry.uptime.consumers.results_consumer.metrics"
157+
) as metrics, self.feature("organizations:uptime-create-issues"):
131158
self.send_result(result)
132159
metrics.incr.assert_has_calls([call("uptime.result_processor.subscription_not_found")])
133160

@@ -137,7 +164,9 @@ def test_skip_already_processed(self):
137164
build_last_update_key(self.project_subscription),
138165
int(result["scheduled_check_time_ms"]),
139166
)
140-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
167+
with mock.patch(
168+
"sentry.uptime.consumers.results_consumer.metrics"
169+
) as metrics, self.feature("organizations:uptime-create-issues"):
141170
self.send_result(result)
142171
metrics.incr.assert_has_calls(
143172
[
@@ -163,6 +192,7 @@ def test_missed(self):
163192
with (
164193
mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics,
165194
mock.patch("sentry.uptime.consumers.results_consumer.logger") as logger,
195+
self.feature("organizations:uptime-create-issues"),
166196
):
167197
self.send_result(result)
168198
metrics.incr.assert_called_once_with(
@@ -189,7 +219,9 @@ def test_onboarding_failure(self):
189219
redis = _get_cluster()
190220
key = build_onboarding_failure_key(self.project_subscription)
191221
assert redis.get(key) is None
192-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
222+
with mock.patch(
223+
"sentry.uptime.consumers.results_consumer.metrics"
224+
) as metrics, self.feature("organizations:uptime-create-issues"):
193225
self.send_result(result)
194226
metrics.incr.assert_has_calls(
195227
[
@@ -216,6 +248,7 @@ def test_onboarding_failure(self):
216248
"sentry.uptime.consumers.results_consumer.ONBOARDING_FAILURE_THRESHOLD", new=2
217249
),
218250
self.tasks(),
251+
self.feature("organizations:uptime-create-issues"),
219252
):
220253
self.send_result(result)
221254
metrics.incr.assert_has_calls(
@@ -251,7 +284,9 @@ def test_onboarding_success_ongoing(self):
251284
redis = _get_cluster()
252285
key = build_onboarding_failure_key(self.project_subscription)
253286
assert redis.get(key) is None
254-
with mock.patch("sentry.uptime.consumers.results_consumer.metrics") as metrics:
287+
with mock.patch(
288+
"sentry.uptime.consumers.results_consumer.metrics"
289+
) as metrics, self.feature("organizations:uptime-create-issues"):
255290
self.send_result(result)
256291
metrics.incr.assert_has_calls(
257292
[
@@ -284,7 +319,7 @@ def test_onboarding_success_graduate(self):
284319
assert redis.get(key) is None
285320
with mock.patch(
286321
"sentry.uptime.consumers.results_consumer.metrics"
287-
) as metrics, self.tasks():
322+
) as metrics, self.tasks(), self.feature("organizations:uptime-create-issues"):
288323
self.send_result(result)
289324
metrics.incr.assert_has_calls(
290325
[

0 commit comments

Comments
 (0)