Skip to content

Commit

Permalink
remove flag and enable flag syncs by default
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan committed Mar 11, 2024
1 parent 4e4e4df commit 1c330ff
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 33 deletions.
1 change: 0 additions & 1 deletion docs/reference/flagd-cli/flagd_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ flagd start [flags]
-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://flagd.dev/reference/sync-configuration/#source-configuration
-e, --sync-enabled Enables the gRPC sync service from flagd. This is disabled by default
-g, --sync-port int32 gRPC Sync port (default 8015)
-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.
```
Expand Down
1 change: 0 additions & 1 deletion docs/reference/grpc-sync-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: flagd as a gRPC sync service
# Overview

flagd can expose a gRPC sync service, allowing in-process providers to obtain their flag definitions.
This mode is **disabled** by default, and you can enable it by using startup flag `--sync-enabled` (or `-e` shorthand flag).
The gRPC sync stream contains flag definitions currently configured at flagd as [sync-configurations](./sync-configuration.md).

```mermaid
Expand Down
6 changes: 0 additions & 6 deletions flagd/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (
serverKeyPathFlagName = "server-key-path"
socketPathFlagName = "socket-path"
sourcesFlagName = "sources"
syncEnabledFlagName = "sync-enabled"
syncPortFlagName = "sync-port"
uriFlagName = "uri"
)
Expand Down Expand Up @@ -67,9 +66,6 @@ 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.")

flags.BoolP(syncEnabledFlagName, "e", false, "Enables the gRPC sync service from flagd. "+
"This is disabled by default")

_ = viper.BindPFlag(corsFlagName, flags.Lookup(corsFlagName))
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
_ = viper.BindPFlag(metricsExporter, flags.Lookup(metricsExporter))
Expand All @@ -82,7 +78,6 @@ func init() {
_ = viper.BindPFlag(sourcesFlagName, flags.Lookup(sourcesFlagName))
_ = viper.BindPFlag(uriFlagName, flags.Lookup(uriFlagName))
_ = viper.BindPFlag(syncPortFlagName, flags.Lookup(syncPortFlagName))
_ = viper.BindPFlag(syncEnabledFlagName, flags.Lookup(syncEnabledFlagName))
}

// startCmd represents the start command
Expand Down Expand Up @@ -138,7 +133,6 @@ var startCmd = &cobra.Command{
ServicePort: viper.GetUint16(portFlagName),
ServiceSocketPath: viper.GetString(socketPathFlagName),
SyncServicePort: viper.GetUint16(syncPortFlagName),
WithSyncService: viper.GetBool(syncEnabledFlagName),
SyncProviders: syncProviders,
})
if err != nil {
Expand Down
20 changes: 8 additions & 12 deletions flagd/pkg/runtime/from_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Config struct {
ServicePort uint16
ServiceSocketPath string
SyncServicePort uint16
WithSyncService bool

SyncProviders []sync.SourceConfig
CORS []string
Expand Down Expand Up @@ -84,17 +83,14 @@ func FromConfig(logger *logger.Logger, version string, config Config) (*Runtime,
recorder)

// flag sync service
var flagSyncService flagsync.ISyncService = &flagsync.NoopSyncService{}
if config.WithSyncService {
flagSyncService, err = flagsync.NewSyncService(flagsync.SvcConfigurations{
Logger: logger.WithFields(zap.String("component", "FlagSyncService")),
Port: config.SyncServicePort,
Sources: sources,
Store: s,
})
if err != nil {
return nil, fmt.Errorf("error creating sync service: %w", err)
}
flagSyncService, err := flagsync.NewSyncService(flagsync.SvcConfigurations{
Logger: logger.WithFields(zap.String("component", "FlagSyncService")),
Port: config.SyncServicePort,
Sources: sources,
Store: s,
})
if err != nil {
return nil, fmt.Errorf("error creating sync service: %w", err)
}

// build sync providers
Expand Down
13 changes: 0 additions & 13 deletions flagd/pkg/service/flag-sync/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,3 @@ func (t *syncTracker) trackAndUpdate(source string) {
close(t.doneChan)
}
}

// NoopSyncService as a filler implementation of the sync service.
// This can be used as a default implementation and avoid unnecessary null checks or service enabled checks in runtime.
type NoopSyncService struct{}

func (n *NoopSyncService) Start(context.Context) error {
// NOOP
return nil
}

func (n *NoopSyncService) Emit(bool, string) {
// NOOP
}

0 comments on commit 1c330ff

Please sign in to comment.