Skip to content
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
24 changes: 14 additions & 10 deletions cmd/ff-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func init() {
flag.StringVar(&redisPassword, redisPasswordFlag, "", "Optional. Redis password")
flag.IntVar(&redisDB, redisDBFlag, 0, "Database to be selected after connecting to the server.")
flag.Var(&apiKeys, apiKeysFlag, "API keys to connect with ff-server for each environment")
flag.IntVar(&targetPollDuration, targetPollDurationFlag, 60, "How often in seconds the proxy polls feature flags for Target changes")
flag.IntVar(&targetPollDuration, targetPollDurationFlag, 60, "How often in seconds the proxy polls feature flags for Target changes. Set to 0 to disable.")
flag.IntVar(&metricPostDuration, metricPostDurationFlag, 60, "How often in seconds the proxy posts metrics to Harness. Set to 0 to disable.")
flag.IntVar(&heartbeatInterval, heartbeatIntervalFlag, 60, "How often in seconds the proxy polls pings it's health function")
flag.BoolVar(&pprofEnabled, pprofEnabledFlag, false, "enables pprof on port 6060")
Expand Down Expand Up @@ -388,6 +388,7 @@ func main() {
adminService,
config.WithLogger(logger),
config.WithConcurrency(20),
config.WithFetchTargets(targetPollDuration != 0), // don't fetch targets if poll duration is 0
)
if err != nil {
logger.Error("error(s) encountered fetching config from FeatureFlags, startup will continue but the Proxy may be missing required config", "errors", err)
Expand Down Expand Up @@ -514,17 +515,20 @@ func main() {

if !offline {
// start target polling ticker
go func() {
ticker := time.NewTicker(time.Duration(targetPollDuration) * time.Second)
defer ticker.Stop()
// don't poll for targets if duration is 0
if targetPollDuration != 0 {
go func() {
ticker := time.NewTicker(time.Duration(targetPollDuration) * time.Second)
defer ticker.Stop()

logger.Info(fmt.Sprintf("polling for new targets every %d seconds", targetPollDuration))
for targetConfig := range remoteConfig.PollTargets(ctx, ticker.C) {
for key, values := range targetConfig {
tr.DeltaAdd(ctx, key, values...)
logger.Info(fmt.Sprintf("polling for new targets every %d seconds", targetPollDuration))
for targetConfig := range remoteConfig.PollTargets(ctx, ticker.C) {
for key, values := range targetConfig {
tr.DeltaAdd(ctx, key, values...)
}
}
}
}()
}()
}

// start metric sending ticker
if metricPostDuration != 0 {
Expand Down
16 changes: 15 additions & 1 deletion config/remote_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func WithLogger(l log.Logger) RemoteOption {
}
}

// WithFetchTargets specifies if the RemoteConfig instance should fetch targets or not
func WithFetchTargets(fetchTargets bool) RemoteOption {
return func(r *RemoteConfig) {
r.fetchTargets = fetchTargets
}
}

type adminClient interface {
PageProjects(ctx context.Context, input services.PageProjectsInput) (services.PageProjectsResult, error)
PageTargets(ctx context.Context, input services.PageTargetsInput) (services.PageTargetsResult, error)
Expand All @@ -50,7 +57,8 @@ type RemoteConfig struct {
// we store project and environment info after the initial load so that the
// PollTargets functioncan use it and not have to make GetProjects and
// GetEnvironments requests every time
projEnvInfo map[string]configPipeline
projEnvInfo map[string]configPipeline
fetchTargets bool
}

// NewRemoteConfig creates a RemoteConfig and retrieves the configuration for
Expand All @@ -68,6 +76,7 @@ func NewRemoteConfig(ctx context.Context, accountIdentifer string, orgIdentifier
accountIdentifer: accountIdentifer,
orgIdentifier: orgIdentifier,
allowedAPIKeys: allowedAPIKeys,
fetchTargets: true,
}

for _, opt := range opts {
Expand Down Expand Up @@ -446,6 +455,11 @@ func (r RemoteConfig) addTargetConfig(ctx context.Context, inputs <-chan configP
defer close(out)

for input := range inputs {
// if we don't watch to fetch targets just skip
if !r.fetchTargets {
sendOrDone(ctx, out, input)
continue
}
// If an earlier stage in the pipeline has failed there's no point
// trying to execute this stage. We still pass the event on so the
// caller can get the original error
Expand Down
11 changes: 5 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ Some corporate networks may be highly restrictive on allowing sse connections. I
### Adjust timings
Adjust how often certain actions are performed.

| Environment Variable | Flag | Description | Type | Default |
|----------------------|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|---------|
| TARGET_POLL_DURATION | target-poll-duration | How often in seconds the proxy polls feature flags for Target changes | int | 60 |
| METRIC_POST_DURATION | metric-post-duration | How often in seconds the proxy posts metrics to Harness. Set to 0 to disable. | int | 60 |
| HEARTBEAT_INTERVAL | heartbeat-interval | How often in seconds the proxy polls pings it's health function | int | 60 |

| Environment Variable | Flag | Description | Type | Default |
|----------------------|----------------------|---------------------------------------------------------------------------------------------|------|---------|
| TARGET_POLL_DURATION | target-poll-duration | How often in seconds the proxy polls feature flags for Target changes. Set to 0 to disable. | int | 60 |
| METRIC_POST_DURATION | metric-post-duration | How often in seconds the proxy posts metrics to Harness. Set to 0 to disable. | int | 60 |
| HEARTBEAT_INTERVAL | heartbeat-interval | How often in seconds the proxy polls pings it's health function | int | 60 |

### Harness URLs
You may need to adjust these if you pass all your traffic through a filter or proxy rather than sending the requests directly.
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/testhelpers/setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ ADMIN_SERVICE_TOKEN=%s
API_KEYS=%s
AUTH_SECRET=my_secret
REDIS_ADDRESS=redis:6379
PORT=9000`
PORT=9000
TARGET_POLL_DURATION=0`

var generateOfflineConfigTemplate = `ACCOUNT_IDENTIFIER=%s
ORG_IDENTIFIER=%s
Expand Down