diff --git a/docs/reference/flagd-cli/flagd_start.md b/docs/reference/flagd-cli/flagd_start.md index d67aab67b..f468ccfb8 100644 --- a/docs/reference/flagd-cli/flagd_start.md +++ b/docs/reference/flagd-cli/flagd_start.md @@ -11,23 +11,18 @@ flagd start [flags] ### Options ``` - -b, --bearer-token string DEPRECATED: Superseded by --sources. - -C, --cors-origin strings CORS allowed origins, * will allow all origins - -e, --evaluator string DEPRECATED: Set an evaluator e.g. json, yaml/yml.Please note that yaml/yml and json evaluations work the same (yaml/yml files are converted to json internally) (default "json") - -h, --help help for start - -z, --log-format string Set the logging format, e.g. console or json (default "console") - -m, --management-port int32 Port for management operations (default 8014) - -t, --metrics-exporter string Set the metrics exporter. Default(if unset) is Prometheus. Can be override to otel - OpenTelemetry metric exporter. Overriding to otel require otelCollectorURI to be present - --metrics-port int32 DEPRECATED: Superseded by --management-port. (default 8014) - -o, --otel-collector-uri string Set the grpc URI of the OpenTelemetry collector for flagd runtime. If unset, the collector setup will be ignored and traces will not be exported. - -p, --port int32 Port to listen on (default 8013) - -c, --server-cert-path string Server side tls certificate path - -k, --server-key-path string Server side tls key path - -d, --socket-path string Flagd socket path. With grpc the service will become available on this address. With http(s) the grpc-gateway proxy will use this address internally. - -s, --sources string JSON representation of an array of SourceConfig objects. This object contains 2 required fields, uri (string) and provider (string). Documentation for this object: https://github.com/open-feature/flagd/blob/main/docs/configuration/configuration.md#sync-provider-customisation - -y, --sync-provider string DEPRECATED: Set a sync provider e.g. filepath or remote - -a, --sync-provider-args stringToString DEPRECATED: Sync provider arguments as key values separated by = (default []) - -f, --uri .yaml/.yml/.json Set a sync provider uri to read data from, this can be a filepath, URL (HTTP and gRPC) or FeatureFlag custom resource. When flag keys are duplicated across multiple providers the merge priority follows the index of the flag arguments, as such flags from the uri at index 0 take the lowest precedence, with duplicated keys being overwritten by those from the uri at index 1. Please note that if you are using filepath, flagd only supports files with .yaml/.yml/.json extension. + -C, --cors-origin strings CORS allowed origins, * will allow all origins + -h, --help help for start + -z, --log-format string Set the logging format, e.g. console or json (default "console") + -m, --management-port int32 Port for management operations (default 8014) + -t, --metrics-exporter string Set the metrics exporter. Default(if unset) is Prometheus. Can be override to otel - OpenTelemetry metric exporter. Overriding to otel require otelCollectorURI to be present + -o, --otel-collector-uri string Set the grpc URI of the OpenTelemetry collector for flagd runtime. If unset, the collector setup will be ignored and traces will not be exported. + -p, --port int32 Port to listen on (default 8013) + -c, --server-cert-path string Server side tls certificate path + -k, --server-key-path string Server side tls key path + -d, --socket-path string Flagd socket path. With grpc the service will become available on this address. With http(s) the grpc-gateway proxy will use this address internally. + -s, --sources string JSON representation of an array of SourceConfig objects. This object contains 2 required fields, uri (string) and provider (string). Documentation for this object: https://github.com/open-feature/flagd/blob/main/docs/configuration/configuration.md#sync-provider-customisation + -f, --uri .yaml/.yml/.json Set a sync provider uri to read data from, this can be a filepath, URL (HTTP and gRPC) or FeatureFlag custom resource. When flag keys are duplicated across multiple providers the merge priority follows the index of the flag arguments, as such flags from the uri at index 0 take the lowest precedence, with duplicated keys being overwritten by those from the uri at index 1. Please note that if you are using filepath, flagd only supports files with .yaml/.yml/.json extension. ``` ### Options inherited from parent commands diff --git a/flagd-proxy/cmd/start.go b/flagd-proxy/cmd/start.go index 0e2ea472b..8c0be5145 100644 --- a/flagd-proxy/cmd/start.go +++ b/flagd-proxy/cmd/start.go @@ -23,10 +23,8 @@ import ( const ( logFormatFlagName = "log-format" - metricsPortFlagName = "metrics-port" // deprecated managementPortFlagName = "management-port" portFlagName = "port" - defaultManagementPort = 8016 ) func init() { @@ -34,12 +32,10 @@ func init() { // allows environment variables to use _ instead of - flags.Int32P(portFlagName, "p", 8015, "Port to listen on") - flags.Int32(metricsPortFlagName, defaultManagementPort, "DEPRECATED: Superseded by --management-port.") - flags.Int32P(managementPortFlagName, "m", defaultManagementPort, "Management port") + flags.Int32P(managementPortFlagName, "m", 8016, "Management port") flags.StringP(logFormatFlagName, "z", "console", "Set the logging format, e.g. console or json") _ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName)) - _ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName)) _ = viper.BindPFlag(managementPortFlagName, flags.Lookup(managementPortFlagName)) _ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName)) } @@ -64,29 +60,15 @@ var startCmd = &cobra.Command{ } logger := logger.NewLogger(l, Debug) - if viper.GetUint16(metricsPortFlagName) != defaultManagementPort { - logger.Warn("DEPRECATED: The --metrics-port flag has been deprecated and is superseded by --management-port.") - } - ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) syncStore := subscriptions.NewManager(ctx, logger) s := syncServer.NewServer(logger, syncStore) - // If --management-port is set use that value. If not and - // --metrics-port is set use that value. Otherwise use the default - // value. - managementPort := uint16(defaultManagementPort) - if viper.GetUint16(managementPortFlagName) != defaultManagementPort { - managementPort = viper.GetUint16(managementPortFlagName) - } else if viper.GetUint16(metricsPortFlagName) != defaultManagementPort { - managementPort = viper.GetUint16(metricsPortFlagName) - } - cfg := service.Configuration{ ReadinessProbe: func() bool { return true }, Port: viper.GetUint16(portFlagName), - ManagementPort: managementPort, + ManagementPort: viper.GetUint16(managementPortFlagName), } errChan := make(chan error, 1) diff --git a/flagd/cmd/start.go b/flagd/cmd/start.go index b8a1fda0a..845ee028f 100644 --- a/flagd/cmd/start.go +++ b/flagd/cmd/start.go @@ -16,26 +16,18 @@ import ( ) const ( - bearerTokenFlagName = "bearer-token" corsFlagName = "cors-origin" - evaluatorFlagName = "evaluator" logFormatFlagName = "log-format" metricsExporter = "metrics-exporter" - metricsPortFlagName = "metrics-port" // deprecated managementPortFlagName = "management-port" otelCollectorURI = "otel-collector-uri" portFlagName = "port" - providerArgsFlagName = "sync-provider-args" serverCertPathFlagName = "server-cert-path" serverKeyPathFlagName = "server-key-path" socketPathFlagName = "socket-path" sourcesFlagName = "sources" - syncProviderFlagName = "sync-provider" uriFlagName = "uri" docsLinkConfiguration = "https://flagd.dev/reference/flagd-cli/flagd_start/" - - defaultServicePort = 8013 - defaultManagementPort = 8014 ) func init() { @@ -44,18 +36,13 @@ func init() { // allows environment variables to use _ instead of - viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) // sync-provider-args becomes SYNC_PROVIDER_ARGS viper.SetEnvPrefix("FLAGD") // port becomes FLAGD_PORT - flags.Int32(metricsPortFlagName, defaultManagementPort, "DEPRECATED: Superseded by --management-port.") - flags.Int32P(managementPortFlagName, "m", defaultManagementPort, "Port for management operations") - flags.Int32P(portFlagName, "p", defaultServicePort, "Port to listen on") + flags.Int32P(managementPortFlagName, "m", 8014, "Port for management operations") + flags.Int32P(portFlagName, "p", 8013, "Port to listen on") flags.StringP(socketPathFlagName, "d", "", "Flagd socket path. "+ "With grpc the service will become available on this address. "+ "With http(s) the grpc-gateway proxy will use this address internally.") - flags.StringP(evaluatorFlagName, "e", "json", "DEPRECATED: Set an evaluator e.g. json, yaml/yml."+ - "Please note that yaml/yml and json evaluations work the same (yaml/yml files are converted to json internally)") flags.StringP(serverCertPathFlagName, "c", "", "Server side tls certificate path") flags.StringP(serverKeyPathFlagName, "k", "", "Server side tls key path") - flags.StringToStringP(providerArgsFlagName, - "a", nil, "DEPRECATED: Sync provider arguments as key values separated by =") flags.StringSliceP( uriFlagName, "f", []string{}, "Set a sync provider uri to read data from, this can be a filepath,"+ " URL (HTTP and gRPC) or FeatureFlag custom resource. When flag keys are duplicated across multiple providers the "+ @@ -63,12 +50,7 @@ func init() { "lowest precedence, with duplicated keys being overwritten by those from the uri at index 1. "+ "Please note that if you are using filepath, flagd only supports files with `.yaml/.yml/.json` extension.", ) - flags.StringP( - bearerTokenFlagName, "b", "", "DEPRECATED: Superseded by --sources.") flags.StringSliceP(corsFlagName, "C", []string{}, "CORS allowed origins, * will allow all origins") - flags.StringP( - syncProviderFlagName, "y", "", "DEPRECATED: Set a sync provider e.g. filepath or remote", - ) flags.StringP( sourcesFlagName, "s", "", "JSON representation of an array of SourceConfig objects. This object contains "+ "2 required fields, uri (string) and provider (string). Documentation for this object: "+ @@ -81,20 +63,15 @@ func init() { flags.StringP(otelCollectorURI, "o", "", "Set the grpc URI of the OpenTelemetry collector "+ "for flagd runtime. If unset, the collector setup will be ignored and traces will not be exported.") - _ = viper.BindPFlag(bearerTokenFlagName, flags.Lookup(bearerTokenFlagName)) _ = viper.BindPFlag(corsFlagName, flags.Lookup(corsFlagName)) - _ = viper.BindPFlag(evaluatorFlagName, flags.Lookup(evaluatorFlagName)) _ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName)) _ = viper.BindPFlag(metricsExporter, flags.Lookup(metricsExporter)) - _ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName)) _ = viper.BindPFlag(managementPortFlagName, flags.Lookup(managementPortFlagName)) _ = viper.BindPFlag(otelCollectorURI, flags.Lookup(otelCollectorURI)) _ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName)) - _ = viper.BindPFlag(providerArgsFlagName, flags.Lookup(providerArgsFlagName)) _ = viper.BindPFlag(serverCertPathFlagName, flags.Lookup(serverCertPathFlagName)) _ = viper.BindPFlag(serverKeyPathFlagName, flags.Lookup(serverKeyPathFlagName)) _ = viper.BindPFlag(socketPathFlagName, flags.Lookup(socketPathFlagName)) - _ = viper.BindPFlag(syncProviderFlagName, flags.Lookup(syncProviderFlagName)) _ = viper.BindPFlag(sourcesFlagName, flags.Lookup(sourcesFlagName)) _ = viper.BindPFlag(uriFlagName, flags.Lookup(uriFlagName)) } @@ -122,26 +99,6 @@ var startCmd = &cobra.Command{ rtLogger.Info(fmt.Sprintf("flagd version: %s (%s), built at: %s", Version, Commit, Date)) - if viper.GetString(syncProviderFlagName) != "" { - rtLogger.Warn("DEPRECATED: The --sync-provider flag has been deprecated, see: " + - docsLinkConfiguration) - } - - if viper.GetString(evaluatorFlagName) != "json" { - rtLogger.Warn("DEPRECATED: The --evaluator flag has been deprecated, see: " + - docsLinkConfiguration) - } - - if viper.GetString(providerArgsFlagName) != "" { - rtLogger.Warn("DEPRECATED: The --sync-provider-args flag has been deprecated, see: " + - docsLinkConfiguration) - } - - if viper.GetUint16(metricsPortFlagName) != defaultManagementPort { - rtLogger.Warn("DEPRECATED: The --metrics-port flag has been deprecated, see: " + - docsLinkConfiguration) - } - syncProviders, err := syncbuilder.ParseSyncProviderURIs(viper.GetStringSlice(uriFlagName)) if err != nil { log.Fatal(err) @@ -161,30 +118,15 @@ var startCmd = &cobra.Command{ } syncProviders = append(syncProviders, syncProvidersFromConfig...) - // If --management-port is set use that value. If not and - // --metrics-port is set use that value. Otherwise use the default - // value. - managementPort := uint16(defaultManagementPort) - if viper.GetUint16(managementPortFlagName) != defaultManagementPort { - managementPort = viper.GetUint16(managementPortFlagName) - } else if viper.GetUint16(metricsPortFlagName) != defaultManagementPort { - managementPort = viper.GetUint16(metricsPortFlagName) - } - // Build Runtime ----------------------------------------------------------- rt, err := runtime.FromConfig(logger, Version, runtime.Config{ - CORS: viper.GetStringSlice(corsFlagName), - MetricExporter: viper.GetString(metricsExporter), - ManagementPort: managementPort, - OtelCollectorURI: viper.GetString(otelCollectorURI), - ServiceCertPath: viper.GetString(serverCertPathFlagName), - ServiceKeyPath: viper.GetString(serverKeyPathFlagName), - ServicePort: getPortValueOrDefault( - portFlagName, - viper.GetUint16(portFlagName), - defaultServicePort, - rtLogger, - ), + CORS: viper.GetStringSlice(corsFlagName), + MetricExporter: viper.GetString(metricsExporter), + ManagementPort: viper.GetUint16(managementPortFlagName), + OtelCollectorURI: viper.GetString(otelCollectorURI), + ServiceCertPath: viper.GetString(serverCertPathFlagName), + ServiceKeyPath: viper.GetString(serverKeyPathFlagName), + ServicePort: viper.GetUint16(portFlagName), ServiceSocketPath: viper.GetString(socketPathFlagName), SyncProviders: syncProviders, }) @@ -197,12 +139,3 @@ var startCmd = &cobra.Command{ } }, } - -func getPortValueOrDefault(flagName string, flagValue, defaultValue uint16, logger *logger.Logger) uint16 { - if flagValue == 0 { - logger.Warn(fmt.Sprintf("Could not parse value for flag '%s'. "+ - "Falling back to default value %d", flagName, defaultValue)) - return defaultValue - } - return flagValue -} diff --git a/flagd/cmd/start_test.go b/flagd/cmd/start_test.go deleted file mode 100644 index 2cf19d142..000000000 --- a/flagd/cmd/start_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package cmd - -import ( - "log" - "testing" - - "github.com/open-feature/flagd/core/pkg/logger" - "github.com/spf13/viper" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -func Test_getPort(t *testing.T) { - logger := getLogger() - type args struct { - flagName string - value uint16 - defaultValue uint16 - } - tests := []struct { - name string - args args - want uint16 - envVarValue string - envVar string - }{ - { - name: "get provided value", - args: args{ - flagName: portFlagName, - value: 1234, - defaultValue: defaultServicePort, - }, - want: 1234, - }, - { - name: "get provided value", - args: args{ - flagName: portFlagName, - value: 0, - defaultValue: defaultServicePort, - }, - want: defaultServicePort, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - t.Setenv("FLAGD_PORT", tt.envVarValue) - if got := getPortValueOrDefault(tt.args.flagName, tt.args.value, tt.args.defaultValue, logger); got != tt.want { - t.Errorf("getPort() = %v, want %v", got, tt.want) - } - }) - } -} - -func getLogger() *logger.Logger { - l, err := logger.NewZapLogger(zapcore.DebugLevel, viper.GetString(logFormatFlagName)) - if err != nil { - log.Fatalf("can't initialize zap logger: %v", err) - } - logger := logger.NewLogger(l, Debug) - rtLogger := logger.WithFields(zap.String("component", "start")) - return rtLogger -}