refactor(traffic): replace package-vars with Scheduler interface and struct - #28
Merged
Merged
Conversation
…struct
Move pkg/traffic from package-level mutable state to a proper
struct-based design with an exported Scheduler interface.
Changes:
- Add Opts struct (Logger, WorkerLimit, SampleTolerancePerc)
- Add Scheduler interface with Run/Stop methods
- Add unexported scheduler struct implementing Scheduler
- Add New(opts *Opts) Scheduler constructor with defaulting
- Remove package-level Run(), Stop() functions and all package vars
(reporter, workloads, stopChan, logger, SampleTolerancePerc)
- Inject reporter, stopChan, logger into workload struct fields
- workload.worker uses parent.logger instead of package-level logger
- Update arbiter.go to create traffic.New(&traffic.Opts{...}) and
call sched.Run() / sched.Stop() on the instance
- Update all tests to instantiate via New() and call methods on instance
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors
pkg/trafficto eliminate all package-level mutable state, replacing it with a proper struct-based design backed by an exportedSchedulerinterface.Changes
pkg/traffic/scheduler.goOptsstruct withLogger,WorkerLimit,SampleTolerancePercfieldsSchedulerinterface withRun(ctx, metadata, reporter) errorandStop() errormethodsschedulerstruct implementingSchedulerNew(opts *Opts) Schedulerconstructor with defaultingreporter,workloads,stopChan,logger,SampleTolerancePercRun()andStop()functionspkg/traffic/workload.goreporter,stopChan,loggeras injected struct fieldsreporter,stopChan, andloggerpkg/traffic/worker.gologger.Xcalls withworker.parent.logger.Xpkg/traffic/scheduler_test.gonewTestScheduler()helper usingNew(&Opts{...}).Run()/.Stop()on the scheduler instancearbiter.gosched := traffic.New(&traffic.Opts{Logger: logger, WorkerLimit: ...})at the start ofrun()traffic.Run()/traffic.Stop()calls withsched.Run()/sched.Stop()Validation
make validatepasses: lint clean, all unit tests green, sample example runs successfully.