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

feat: Skip syncing on start if flag set #485

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

tvarney13
Copy link
Member

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues
https://launchdarkly.atlassian.net/browse/FUN-447

Describe the solution you've provided

Added a should-sync flag to the server startup command that sets model.InitialProjectSettings.Enable which controls whether this function no-ops or not.

Using the no-op made sense for the persistent volumes use case, since all the project and env data will already exist locally, but open to being more surgical if so desired.

Describe alternatives you've considered

We could skip the UpdateProject call specifically in the CreateOrSyncProject function, which does the sync bit. Then we'd have to decide if we still want to do the overrides.

Additional context

Add any other context about the pull request here.

@tvarney13 tvarney13 requested a review from dmashuda February 3, 2025 17:08
@tvarney13 tvarney13 self-assigned this Feb 3, 2025
@tvarney13 tvarney13 requested a review from a team February 3, 2025 17:08
@@ -55,7 +58,7 @@ func startServer(client dev_server.Client) func(*cobra.Command, []string) error
if viper.IsSet(cliflags.ProjectFlag) && viper.IsSet(SourceEnvironmentFlag) {

initialSetting = model.InitialProjectSettings{
Enabled: true,
Enabled: viper.GetBool(cliflags.SyncOnStartFlag),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are looking for behavior that is "only sync 1 time".

that way a customer could do:

ldcli dev-server start --project default --source staging --project default --source staging --sync-once true

That way the consumer does not need to vary their input for starting the server (without resyncing if the project/env exists)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. However, if we can make the cli flag be --sync-once instead of --sync-once true, I will be happier 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

@mike-zorn I looked into it, it looks like the default behavior is what you want. However to achieve that Cobra has some quirks.

tl;dr to set the flag to false you either have to not include the flag at all or use an = e.g. --sync-once=false which makes bool flags unique among other Cobra flags. What I'm seeing in the code itself backs that up.

Comment on lines 33 to 35
if !errors.Is(createError, ErrAlreadyExists) {
return createError
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the logic around to clean up the logic and hopefully make it easier to grok

Comment on lines 36 to 41
if settings.SyncOnce {
log.Printf("Project [%s] exists, but --sync-once flag is set, skipping refresh", settings.ProjectKey)
} else {
log.Printf("Project [%s] exists, refreshing data", settings.ProjectKey)
var updateErr error
project, updateErr = UpdateProject(ctx, settings.ProjectKey, settings.Context, &settings.EnvKey)
_, updateErr = UpdateProject(ctx, settings.ProjectKey, settings.Context, &settings.EnvKey)
Copy link
Member Author

Choose a reason for hiding this comment

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

Going to add a unit test for this

internal/dev_server/model/sync.go Outdated Show resolved Hide resolved
@tvarney13 tvarney13 requested a review from mike-zorn February 4, 2025 13:48
@tvarney13 tvarney13 enabled auto-merge (squash) February 4, 2025 13:48
@@ -10,6 +10,7 @@ Supported settings:
- `output`: Command response output format in either JSON or plain text
- `port`: Port for the dev server to run on
- `project`: Default project key
- `sync-once`: Only sync new projects. Existing projects will not be resynced on startup
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `sync-once`: Only sync new projects. Existing projects will not be resynced on startup
- `sync-once`: Only sync new projects. Existing projects will neither be resynced nor have overrides specified by CLI flags applied.

@tvarney13 tvarney13 merged commit d85b862 into main Feb 4, 2025
9 checks passed
@tvarney13 tvarney13 deleted the FUN-447-start-n-sync-dont-blow-away-existing-db branch February 4, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants