Skip to content

Commit 8a47397

Browse files
committed
scripts/list-tasks: Rework missing-flags logic
The main purpose of thise flag is so that when doing a bulk flag flip in production, one can go and re-pull just tasks that still needh to be modified. And my reasoning is that if I'm going and setting a flag like `no_foobar` in prod, there are three cases: - A task has no feature flag setting for `foobar`. These are the ones we want to modify. - A task has setting `no_foobar`. These don't need to be touched since they already have the value we want. - A task has setting `foobar`. These _really_ shouldn't be touched since somebody has explicitly indicated that they want the opposite of what we're doing. Previously the 'missing flag' logic was written such that one might go `--missing=no_foobar` to get all tasks without the specific flag setting `no_foobar` in their feature flags. And since that's still the typical desire and it's weird to have to write `--missing=foobar` and then `--set_flag=no_foobar` for different commands and one could easily screw that up, the logic also normalizes so `--missing=no_foobar` and `--missing=foobar` do the same thing.
1 parent 620ba0c commit 8a47397

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

scripts/list-tasks/main.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"os"
2727
"os/exec"
2828
"path"
29-
"slices"
3029
"sort"
3130
"strings"
3231

@@ -48,7 +47,7 @@ var (
4847
taskType = flag.String("type", "", "The type of catalog spec to list (typically 'capture' or 'materialization'). If unspecified the task listing will not be filtered by type.")
4948
imageName = flag.String("connector", "", "The connector image name to filter on. Can be a full URL like 'ghcr.io/estuary/source-mysql' or a short name like 'source-mysql', and in the latter case the name will be expanded into a full URL including all variants. If unspecified the task list will not be filtered by connector.")
5049
namePrefix = flag.String("prefix", "", "The task name prefix to filter on. If unspecified the task listing will not be filtered by name.")
51-
missingFlags = flag.String("missing", "", "A comma-separated list of feature flag settings. If specified only tasks missing one or more flag settings will be listed/pulled.")
50+
missingFlags = flag.String("missing", "", "A comma-separated list of feature flags. If specified only tasks with one or more flags unset will be listed/pulled.")
5251

5352
addToDraft = flag.Bool("draft", false, "When true, all listed tasks will be added to the active flowctl draft.")
5453

@@ -96,11 +95,11 @@ func performListing(ctx context.Context) error {
9695
for _, task := range tasks {
9796
if *missingFlags != "" {
9897
// Check whether the task spec already has all of the specified settings, and if so skip this task.
99-
var flagSettings = strings.Split(*missingFlags, ",")
100-
if hasAllFlags, err := checkForMissingFlags(task.Spec, flagSettings); err != nil {
98+
var flagNames = strings.Split(*missingFlags, ",")
99+
if hasAllFlags, err := hasSettingsForAllFlags(task.Spec, flagNames); err != nil {
101100
return fmt.Errorf("error checking flag settings for task %q: %w", task.CatalogName, err)
102101
} else if hasAllFlags {
103-
log.WithField("task", task.CatalogName).Debug("task already has all specified flags")
102+
log.WithField("task", task.CatalogName).Info("task already has settings for all flags, skipping")
104103
continue
105104
}
106105
}
@@ -216,13 +215,23 @@ func flowctl(ctx context.Context, args ...string) error {
216215
return err
217216
}
218217

219-
func checkForMissingFlags(spec json.RawMessage, flagSettings []string) (hasAllFlags bool, err error) {
218+
func hasSettingForFlag(flagsSetting string, flagName string) bool {
219+
flagName = strings.TrimPrefix(flagName, "no_")
220+
for _, flag := range strings.Split(flagsSetting, ",") {
221+
flag = strings.TrimSpace(flag)
222+
if flag == flagName || flag == "no_"+flagName {
223+
return true
224+
}
225+
}
226+
return false
227+
}
228+
229+
func hasSettingsForAllFlags(spec json.RawMessage, flagNames []string) (hasAllFlags bool, err error) {
220230
// Extract the 'endpoint.connector.config.advanced.feature_flags' string property from the task spec,
221-
// split into individual flag settings, and check if all of the specified settings are present.
222-
var taskFlagsProperty = extractStringProperty(spec, "endpoint", "connector", "config", "advanced", "feature_flags")
223-
var taskFlags = strings.Split(taskFlagsProperty, ",")
224-
for _, setting := range flagSettings {
225-
if !slices.Contains(taskFlags, setting) {
231+
// and check if it contains a setting for all specified flag names.
232+
var taskFlags = extractStringProperty(spec, "endpoint", "connector", "config", "advanced", "feature_flags")
233+
for _, flagName := range flagNames {
234+
if !hasSettingForFlag(taskFlags, flagName) {
226235
return false, nil
227236
}
228237
}

0 commit comments

Comments
 (0)