Skip to content

Commit

Permalink
chore: fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangnv-bkhn committed Jan 3, 2025
1 parent 9f732ca commit 870c7f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
24 changes: 12 additions & 12 deletions exporter/data_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ const (
)

// ExporterConfig holds the configuration for an individual exporter
type ExporterConfig struct {
type Config struct {
Exporter CommonExporter
FlushInterval time.Duration
MaxEventInMemory int64
}

// ExporterState maintains the state for a single exporter
type ExporterState struct {
config ExporterConfig
type State struct {
config Config
ticker *time.Ticker
lastIndex int // Index of the last processed event
}

// Scheduler handles data collection for one or more exporters
type Scheduler struct {
sharedCache []FeatureEvent
bulkExporters map[CommonExporter]*ExporterState // Only bulk exporters that need periodic flushing
directExporters []CommonExporter // Non-bulk exporters that flush immediately
bulkExporters map[CommonExporter]*State // Only bulk exporters that need periodic flushing
directExporters []CommonExporter // Non-bulk exporters that flush immediately
mutex sync.Mutex
daemonChan chan struct{}
logger *fflog.FFLogger
Expand All @@ -46,22 +46,22 @@ func NewScheduler(ctx context.Context, flushInterval time.Duration, maxEventInMe
exp CommonExporter, logger *fflog.FFLogger,
) *Scheduler {
// Convert single exporter parameters to ExporterConfig
config := ExporterConfig{
config := Config{
Exporter: exp,
FlushInterval: flushInterval,
MaxEventInMemory: maxEventInMemory,
}
return NewMultiScheduler(ctx, []ExporterConfig{config}, logger)
return NewMultiScheduler(ctx, []Config{config}, logger)
}

// NewMultiScheduler creates a scheduler that handles multiple exporters
func NewMultiScheduler(ctx context.Context, exporterConfigs []ExporterConfig, logger *fflog.FFLogger,
func NewMultiScheduler(ctx context.Context, exporterConfigs []Config, logger *fflog.FFLogger,
) *Scheduler {
if ctx == nil {
ctx = context.Background()
}

bulkExporters := make(map[CommonExporter]*ExporterState)
bulkExporters := make(map[CommonExporter]*State)
directExporters := make([]CommonExporter, 0)

for _, config := range exporterConfigs {
Expand All @@ -73,7 +73,7 @@ func NewMultiScheduler(ctx context.Context, exporterConfigs []ExporterConfig, lo
}

if config.Exporter.IsBulk() {
state := &ExporterState{
state := &State{
config: config,
lastIndex: -1,
ticker: time.NewTicker(config.FlushInterval),
Expand Down Expand Up @@ -130,15 +130,15 @@ func (s *Scheduler) AddEvent(event FeatureEvent) {
}

// getPendingEvents returns events that haven't been processed by this exporter
func (s *Scheduler) getPendingEvents(state *ExporterState) []FeatureEvent {
func (s *Scheduler) getPendingEvents(state *State) []FeatureEvent {
if state.lastIndex+1 >= len(s.sharedCache) {
return nil
}
return s.sharedCache[state.lastIndex+1:]
}

// flushExporter sends pending events to the specified exporter
func (s *Scheduler) flushExporter(state *ExporterState) {
func (s *Scheduler) flushExporter(state *State) {
pendingEvents := s.getPendingEvents(state)
if len(pendingEvents) == 0 {
return
Expand Down
4 changes: 2 additions & 2 deletions feature_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func New(config Config) (*GoFeatureFlag, error) {
)
} else {
// Multiple exporters case
exporterConfigs := make([]exporter.ExporterConfig, len(dataExporters))
exporterConfigs := make([]exporter.Config, len(dataExporters))
for i, de := range dataExporters {
exporterConfigs[i] = exporter.ExporterConfig{
exporterConfigs[i] = exporter.Config{
Exporter: de.Exporter,
FlushInterval: de.FlushInterval,
MaxEventInMemory: de.MaxEventInMemory,
Expand Down
1 change: 1 addition & 0 deletions testutils/mock/exporter_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (m *Exporter) Export(ctx context.Context, _ *fflog.FFLogger, events []expor
m.ExportedEvents = append(m.ExportedEvents, events...)
if m.Err != nil {
if m.ExpectedNumberErr > m.CurrentNumberErr {
m.ExportedEvents = m.ExportedEvents[:len(m.ExportedEvents)-len(events)]
m.CurrentNumberErr++
return m.Err
}
Expand Down

0 comments on commit 870c7f8

Please sign in to comment.