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

Sync Mode drift detection #70811

Merged
merged 10 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/sentry/runner/commands/configoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _attempt_update(
last_update_channel = options.get_last_update_channel(key)
if db_value == value:
# This script is making changes with UpdateChannel.AUTOMATOR
# channel. Thus, if the laast update channel was already
# channel. Thus, if the last update channel was already
# UpdateChannel.AUTOMATOR, and the value we are trying to set
# is the same as the value already stored we do nothing.
if last_update_channel is None:
Expand Down Expand Up @@ -273,11 +273,18 @@ def sync(ctx: click.Context) -> None:
)
presenter_delegator.flush()
raise

presenter_delegator.unset(opt.name)
else:
presenter_delegator.drift(opt.name, "")
drift_found = True
if (
kneeyo1 marked this conversation as resolved.
Show resolved Hide resolved
options.can_update(
Copy link
Contributor Author

@kneeyo1 kneeyo1 May 14, 2024

Choose a reason for hiding this comment

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

if an option is passed into configoptions, and it is set on disk, we check for it here (when we call attempt_update on line 244) https://github.com/getsentry/sentry/blob/fix/options-on-disk/src/sentry/options/manager.py#L188-L200

otherwise, if it is set on disk but not defined in the automator, since options.get() and options.isset() will still return true,(even if the options DNE in the DB) we again check to see if the option is on disk. if it is, we continue.

opt.name, options.get(opt.name), options.UpdateChannel.AUTOMATOR
)
== options.NotWritableReason.OPTION_ON_DISK
):
continue
else:
presenter_delegator.drift(opt.name, options.get(opt.name))
drift_found = True

if invalid_options:
status = "update_failed"
Expand Down
2 changes: 2 additions & 0 deletions tests/sentry/runner/commands/badsync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
options:
set_on_disk_option: 'hello'
26 changes: 25 additions & 1 deletion tests/sentry/runner/commands/test_configoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
from pathlib import Path

import pytest
from django.conf import settings

from sentry import options
from sentry.options.manager import FLAG_AUTOMATOR_MODIFIABLE, FLAG_IMMUTABLE, UpdateChannel
from sentry.options.manager import (
FLAG_AUTOMATOR_MODIFIABLE,
FLAG_IMMUTABLE,
FLAG_PRIORITIZE_DISK,
UpdateChannel,
)
from sentry.runner.commands.configoptions import configoptions
from sentry.runner.commands.presenters.consolepresenter import ConsolePresenter
from sentry.testutils.cases import CliTestCase
Expand All @@ -24,6 +30,12 @@ def register_options(self) -> Generator[None, None, None]:
options.register("change_channel_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
options.register("to_unset_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
options.register("invalid_type", default=15, flags=FLAG_AUTOMATOR_MODIFIABLE)
options.register(
"set_on_disk_option",
default="",
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
)
settings.SENTRY_OPTIONS["set_on_disk_option"] = "test"

yield

Expand All @@ -36,6 +48,8 @@ def register_options(self) -> Generator[None, None, None]:
options.unregister("change_channel_option")
options.unregister("to_unset_option")
options.unregister("invalid_type")
options.unregister("set_on_disk_option")
del settings.SENTRY_OPTIONS["set_on_disk_option"]

@pytest.fixture(autouse=True)
def set_options(self) -> None:
Expand Down Expand Up @@ -184,6 +198,16 @@ def test_sync(self):

assert not options.isset("to_unset_option")

def test_bad_sync(self):
rv = self.invoke(
"-f",
"tests/sentry/runner/commands/badsync.yaml",
"sync",
)
assert rv.exit_code == 2, rv.output

assert ConsolePresenter.ERROR_MSG % ("set_on_disk_option", "option_on_disk") in rv.output

def test_bad_patch(self):
rv = self.invoke(
"--file=tests/sentry/runner/commands/badpatch.yaml",
Expand Down
Loading