Skip to content

Commit

Permalink
ref(uptiem): Replace autodetection flag w/ option
Browse files Browse the repository at this point in the history
Since we don't need to be as granular now and would like to reduce the
number of feature flags we have, we can move this behind an option.
  • Loading branch information
evanpurkhiser committed Oct 18, 2024
1 parent 0ecd4fa commit 8165154
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,14 @@
flags=FLAG_ALLOW_EMPTY | FLAG_AUTOMATOR_MODIFIABLE,
)

# Disables URL autodetection during post-process
register(
"uptime.disable_auto_detection",
type=Bool,
default=False,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"releases.no_snuba_for_release_creation",
type=Bool,
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/uptime/detectors/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING

from sentry import features
from sentry import options
from sentry.uptime.detectors.ranking import (
add_base_url_to_rank,
should_detect_for_organization,
Expand All @@ -19,11 +19,11 @@ def detect_base_url_for_project(project: Project, url: str) -> None:
# Note: We might end up removing the `should_detect_for_project` check here if/when we decide to use detected
# urls as suggestions as well.
if (
not features.has("organizations:uptime-automatic-hostname-detection", project.organization)
options.get("uptime.disable_auto_detection")
or not should_detect_for_project(project)
or not should_detect_for_organization(project.organization)
):
metrics.incr("uptime.detectors.url_add_skipped_due_to_feature_flag")
metrics.incr("uptime.detectors.url_add_skipped")
return

base_url = extract_base_url(url)
Expand Down
2 changes: 0 additions & 2 deletions tests/sentry/tasks/test_post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,6 @@ def assert_organization_key(self, organization: Organization, exists: bool) -> N
cluster = _get_cluster()
assert exists == cluster.sismember(key, str(organization.id))

@with_feature("organizations:uptime-automatic-hostname-detection")
def test_uptime_detection_feature_url(self):
event = self.create_event(
data={"request": {"url": "http://sentry.io"}},
Expand All @@ -2171,7 +2170,6 @@ def test_uptime_detection_feature_url(self):
)
self.assert_organization_key(self.organization, True)

@with_feature("organizations:uptime-automatic-hostname-detection")
def test_uptime_detection_feature_no_url(self):
event = self.create_event(
data={},
Expand Down
9 changes: 3 additions & 6 deletions tests/sentry/uptime/detectors/test_detector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from sentry.models.organization import Organization
from sentry.testutils.cases import UptimeTestCase
from sentry.testutils.helpers import with_feature
from sentry.uptime.detectors.detector import detect_base_url_for_project
from sentry.uptime.detectors.ranking import _get_cluster, get_organization_bucket_key

Expand All @@ -11,22 +10,20 @@ def assert_organization_key(self, organization: Organization, exists: bool) -> N
cluster = _get_cluster()
assert exists == cluster.sismember(key, str(organization.id))

@with_feature("organizations:uptime-automatic-hostname-detection")
def test(self):
detect_base_url_for_project(self.project, "https://sentry.io")
self.assert_organization_key(self.organization, True)

def test_no_feature(self):
detect_base_url_for_project(self.project, "https://sentry.io")
def test_killswitch(self):
with self.options({"uptime.disable_auto_detection": True}):
detect_base_url_for_project(self.project, "https://sentry.io")
self.assert_organization_key(self.organization, False)

@with_feature("organizations:uptime-automatic-hostname-detection")
def test_disabled_for_project(self):
self.project.update_option("sentry:uptime_autodetection", False)
detect_base_url_for_project(self.project, "https://sentry.io")
self.assert_organization_key(self.organization, False)

@with_feature("organizations:uptime-automatic-hostname-detection")
def test_disabled_for_organization(self):
self.organization.update_option("sentry:uptime_autodetection", False)
detect_base_url_for_project(self.project, "https://sentry.io")
Expand Down

0 comments on commit 8165154

Please sign in to comment.