Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiments: Switch to filewatcher/v2 #655

Merged
merged 1 commit into from
May 24, 2024
Merged
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
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
Loading