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

Add a fs watcher based reloader for PathOrContent #17

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

douglascamata
Copy link
Contributor

Signed-off-by: Douglas Camata 159076+douglascamata@users.noreply.github.com

Extracting the filesystem based reloader for PathOrContent from thanos-io/thanos#5673 into the extkingpin package here so that it can be more easily reused by other projects and even in Thanos itself (where it was originally created).

Copy link

@philipgough philipgough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🌟

Maybe you can add a section in docs.go and update the readme https://github.com/efficientgo/tools#module-githubcomefficientgotoolsextkingpin?

@douglascamata
Copy link
Contributor Author

@saswatamcode suuuure, working on it. 💪

Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com>
Copy link
Collaborator

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@douglascamata
Copy link
Contributor Author

@saswatamcode when do you think we can merge this? 😬

Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good overall, just some usability suggestions.

// Copyright (c) The EfficientGo Authors.
// Licensed under the Apache License 2.0.

// Taken from Thanos project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Path() string
}

// PathContentReloader starts a file watcher that monitors the file indicated by pathOrContent.Path() and runs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a note this can run forever if not cancelled?

Also I wonder if it wouldn't be cleaner to make it sync. Otherwise it looks like a function that just leaks things when you are not careful. So either make it sync so others would run it in go routine or return closer?

// the debounce timer. By default the debouncer timer is 1 second.
// To ensure renames and deletes are properly handled, the file watcher is put at the file's parent folder. See
// https://github.com/fsnotify/fsnotify/issues/214 for more details.
func PathContentReloader(ctx context.Context, fileContent pathOrContent, debugLogger logger, errorLogger logger, reloadFunc func(), debounceTime time.Duration) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func PathContentReloader(ctx context.Context, fileContent pathOrContent, debugLogger logger, errorLogger logger, reloadFunc func(), debounceTime time.Duration) error {
func StartPathContentReloader(ctx context.Context, fileContent pathOrContent, debugLogger logger, errorLogger logger, reloadFunc func(), debounceTime time.Duration) error {

I think we need verb to tell what's going on 🤔

@douglascamata
Copy link
Contributor Author

@bwplotka this PR is now severely outdated. I made the reloader independent of fs watchers due to problems with k8s secrets and configmaps (see thanos-io/thanos#6503). Will update the PR here when I get some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants