Skip to content

Allow manual specification of filewatcher behavior #29

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

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions cmd/localstack/awsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ func RunDNSRewriter(opts *LsOpts, ctx context.Context) {
log.Debugln("DNS server stopped")
}

func RunHotReloadingListener(server *CustomInteropServer, targetPaths []string, ctx context.Context) {
func RunHotReloadingListener(server *CustomInteropServer, targetPaths []string, ctx context.Context, fileWatcher string) {
if len(targetPaths) == 1 && targetPaths[0] == "" {
log.Debugln("Hot reloading disabled.")
return
}
defaultDebouncingDuration := 500 * time.Millisecond
log.Infoln("Hot reloading enabled, starting filewatcher.", targetPaths)
changeListener, err := NewChangeListener(defaultDebouncingDuration)
changeListener, err := NewChangeListener(defaultDebouncingDuration, fileWatcher)
if err != nil {
log.Errorln("Hot reloading disabled due to change listener error.", err)
return
Expand Down
20 changes: 17 additions & 3 deletions cmd/localstack/filenotify/filenotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,28 @@ func shouldUseEventWatcher() bool {
}

// New tries to use a fs-event watcher, and falls back to the poller if there is an error
func New(interval time.Duration) (FileWatcher, error) {
func New(interval time.Duration, fileWatcher string) (FileWatcher, error) {
if fileWatcher != "" {
log.Debugln("Forced usage of filewatcher: ", fileWatcher)
if fileWatcher == "event" {
if watcher, err := NewEventWatcher(); err == nil {
return watcher, nil
} else {
log.Fatalln("Event based filewatcher is selected, but unable to start. Please try setting the filewatcher to polling. Error: ", err)
}
} else if fileWatcher == "polling" {
return NewPollingWatcher(interval), nil
} else {
log.Fatalf("Invalid filewatcher setting %s. Only event and polling are allowed.\n", fileWatcher)
}
}
if shouldUseEventWatcher() {
if watcher, err := NewEventWatcher(); err == nil {
log.Debugln("Using event based filewatcher")
log.Debugln("Using event based filewatcher (autodetected)")
return watcher, nil
}
}
log.Debugln("Using polling based filewatcher")
log.Debugln("Using polling based filewatcher (autodetected)")
return NewPollingWatcher(interval), nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/localstack/hotreloading.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type ChangeListener struct {
watchedFolders []string
}

func NewChangeListener(debouncingInterval time.Duration) (*ChangeListener, error) {
watcher, err := filenotify.New(200 * time.Millisecond)
func NewChangeListener(debouncingInterval time.Duration, fileWatcher string) (*ChangeListener, error) {
watcher, err := filenotify.New(200*time.Millisecond, fileWatcher)
Copy link
Member

Choose a reason for hiding this comment

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

Should we maybe make the interval configurable as well while we're at it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am kind of conflicted. On the one hand, it might make sense to do, if they want to increase it when running huge folders. On the other hand, I am not sure how much it will really impact.

if err != nil {
log.Errorln("Cannot create change listener due to filewatcher error.", err)
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion cmd/localstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type LsOpts struct {
User string
CodeArchives string
HotReloadingPaths []string
FileWatcher string
EnableDnsServer string
LocalstackIP string
InitLogLevel string
Expand Down Expand Up @@ -50,6 +51,7 @@ func InitLsOpts() *LsOpts {
// optional or empty
CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"),
HotReloadingPaths: strings.Split(GetenvWithDefault("LOCALSTACK_HOT_RELOADING_PATHS", ""), ","),
FileWatcher: os.Getenv("LOCALSTACK_FILE_WATCHER"),
EnableDnsServer: os.Getenv("LOCALSTACK_ENABLE_DNS_SERVER"),
EnableXRayTelemetry: os.Getenv("LOCALSTACK_ENABLE_XRAY_TELEMETRY"),
LocalstackIP: os.Getenv("LOCALSTACK_HOSTNAME"),
Expand Down Expand Up @@ -225,7 +227,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
go RunHotReloadingListener(interopServer, lsOpts.HotReloadingPaths, fileWatcherContext)
go RunHotReloadingListener(interopServer, lsOpts.HotReloadingPaths, fileWatcherContext, lsOpts.FileWatcher)

// start runtime init. It is important to start `InitHandler` synchronously because we need to ensure the
// notification channels and status fields are properly initialized before `AwaitInitialized`
Expand Down