Skip to content

Commit

Permalink
experiments: Switch to filewatcher/v2
Browse files Browse the repository at this point in the history
Note: secrets package is not switching because
filewatcher.MockFileWatcher is part of its API so switching to v2 will
be a breaking change for secrets package.
  • Loading branch information
fishy committed May 22, 2024
1 parent 126d45b commit 52168a3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions experiments/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/reddit/baseplate.go/filewatcher"
"github.com/reddit/baseplate.go/filewatcher/v2"
"github.com/reddit/baseplate.go/internal/prometheusbpint"
"github.com/reddit/baseplate.go/log"
"github.com/reddit/baseplate.go/timebp"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (e MissingBucketKeyError) Error() string {
// the experiment configuration fetcher daemon. It will automatically reload
// the cache when changed.
type Experiments struct {
watcher filewatcher.FileWatcher
watcher filewatcher.FileWatcher[document]
eventLogger EventLogger
}

Expand All @@ -76,7 +76,7 @@ type Experiments struct {
// Context should come with a timeout otherwise this might block forever, i.e.
// if the path never becomes available.
func NewExperiments(ctx context.Context, path string, eventLogger EventLogger, logger log.Wrapper) (*Experiments, error) {
parser := func(r io.Reader) (interface{}, error) {
parser := func(r io.Reader) (document, error) {
var doc document
err := json.NewDecoder(r).Decode(&doc)
if err != nil {
Expand All @@ -86,11 +86,8 @@ func NewExperiments(ctx context.Context, path string, eventLogger EventLogger, l
}
result, err := filewatcher.New(
ctx,
filewatcher.Config{
Path: path,
Parser: parser,
Logger: logger,
},
path,
parser,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -128,7 +125,7 @@ func (e *Experiments) Variant(name string, args map[string]interface{}, bucketin
func (e *Experiments) Expose(ctx context.Context, experimentName string, event ExperimentEvent) error {
exposeTotalRequests.Inc()

doc := e.watcher.Get().(document)
doc := e.watcher.Get()
experiment, ok := doc[experimentName]
if !ok {
return UnknownExperimentError(experimentName)
Expand All @@ -141,7 +138,7 @@ func (e *Experiments) Expose(ctx context.Context, experimentName string, event E
}

func (e *Experiments) experiment(name string) (*SimpleExperiment, error) {
doc := e.watcher.Get().(document)
doc := e.watcher.Get()
experiment, ok := doc[name]
if !ok {
return nil, UnknownExperimentError(name)
Expand Down

0 comments on commit 52168a3

Please sign in to comment.