Skip to content

Commit 12c073b

Browse files
Configure cleanQueueInterval
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 7e8ab80 commit 12c073b

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

cmd/relayproxy/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ type Config struct {
259259
// Exporters is the exact same things than Exporter but allows to give more than 1 exporter at the time.
260260
Exporters *[]ExporterConf `mapstructure:"exporters" koanf:"exporters"`
261261

262+
// ExporterCleanQueueInterval (optional) is the duration between each cleaning of the queue by the thread in charge
263+
// of removing the old events.
264+
// Default: 1 minute
265+
ExporterCleanQueueInterval time.Duration `mapstructure:"exporterCleanQueueInterval" koanf:"exportercleanqueueinterval"`
266+
262267
// Notifiers is the configuration on where to notify a flag change
263268
Notifiers []NotifierConf `mapstructure:"notifier" koanf:"notifier"`
264269

config.go

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ type Config struct {
7878
// Multiple exporters can be used to send data to multiple destinations in parallel without interference.
7979
DataExporters []DataExporter
8080

81+
// ExporterCleanQueueInterval (optional) is the duration between each cleaning of the queue by the thread in charge
82+
// of removing the old events.
83+
// Default: 1 minute
84+
ExporterCleanQueueInterval time.Duration
85+
8186
// StartWithRetrieverError (optional) If true, the SDK will start even if we did not get any flags from the retriever.
8287
// It will serve only default values until all the retrievers returns the flags.
8388
// The init method will not return any error if the flag file is unreachable.

exporter/event_store.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ type eventStoreImpl[T any] struct {
2020
lastOffset int64
2121
// stopPeriodicCleaning is a channel to stop the periodic cleaning goroutine
2222
stopPeriodicCleaning chan struct{}
23-
// cleanQueueDuration is the duration between each cleaning
24-
cleanQueueDuration time.Duration
23+
// cleanQueueInterval is the duration between each cleaning
24+
cleanQueueInterval time.Duration
2525
}
2626

27-
func NewEventStore[T any](cleanQueueDuration time.Duration) EventStore[T] {
27+
func NewEventStore[T any](cleanQueueInterval time.Duration) EventStore[T] {
2828
store := &eventStoreImpl[T]{
2929
events: make([]Event[T], 0),
3030
mutex: sync.RWMutex{},
3131
lastOffset: minOffset,
3232
stopPeriodicCleaning: make(chan struct{}),
33-
cleanQueueDuration: cleanQueueDuration,
33+
cleanQueueInterval: cleanQueueInterval,
3434
consumers: make(map[string]*consumer),
3535
}
3636
go store.periodicCleanQueue()
@@ -166,7 +166,7 @@ func (e *eventStoreImpl[T]) cleanQueue() {
166166

167167
// periodicCleanQueue periodically cleans the queue
168168
func (e *eventStoreImpl[T]) periodicCleanQueue() {
169-
ticker := time.NewTicker(e.cleanQueueDuration)
169+
ticker := time.NewTicker(e.cleanQueueInterval)
170170
defer ticker.Stop()
171171
for {
172172
select {

exporter/manager.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ type managerImpl[T any] struct {
2020
eventStore *EventStore[T]
2121
}
2222

23-
func NewManager[T any](ctx context.Context, exporters []Config, logger *fflog.FFLogger) Manager[T] {
23+
func NewManager[T any](ctx context.Context, exporters []Config, ExporterCleanQueueInterval time.Duration, logger *fflog.FFLogger) Manager[T] {
2424
if ctx == nil {
2525
ctx = context.Background()
2626
}
2727

28-
evStore := NewEventStore[T](30 * time.Second)
28+
if ExporterCleanQueueInterval == 0 {
29+
// default value for the exporterCleanQueueDuration is 1 minute
30+
ExporterCleanQueueInterval = 1 * time.Minute
31+
}
32+
33+
evStore := NewEventStore[T](ExporterCleanQueueInterval)
2934
consumers := make([]DataExporter[T], len(exporters))
3035
for index, exporter := range exporters {
3136
consumerID := uuid.New().String()

feature_flag.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func New(config Config) (*GoFeatureFlag, error) {
133133
MaxEventInMemory: exp.MaxEventInMemory,
134134
}
135135
}
136-
goFF.dataExporter =
137-
exporter.NewManager[exporter.FeatureEvent](config.Context, expConfigs, goFF.config.internalLogger)
136+
goFF.dataExporter = exporter.NewManager[exporter.FeatureEvent](
137+
config.Context, expConfigs, config.ExporterCleanQueueInterval, goFF.config.internalLogger)
138138
go goFF.dataExporter.Start()
139139
}
140140
}

0 commit comments

Comments
 (0)