FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow manual specification of filewatcher behavior by dfangl · Pull Request #29 · localstack/lambda-runtime-init · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions cmd/localstack/awsutil.go
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
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, fileWatcherStrategy 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, fileWatcherStrategy)
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
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
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, fileWatcherStrategy string) (FileWatcher, error) {
if fileWatcherStrategy != "" {
log.Debugln("Forced usage of filewatcher strategy: ", fileWatcherStrategy)
if fileWatcherStrategy == "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 fileWatcherStrategy == "polling" {
return NewPollingWatcher(interval), nil
} else {
log.Fatalf("Invalid filewatcher strategy %s. Only event and polling are allowed.\n", fileWatcherStrategy)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would it make sense to crash the init binary rather than just log here?
Currently, it just hangs until a timeout kills the container :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A fatal log should indeed crash the init binary

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I see.
Then it's likely one of the error cases we do not (yet) handle actively in the init. Reporting back to LocalStack would be nice in the future to short-circuit the timeout (which is likely high when debugging).

}
}
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
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
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, fileWatcherStrategy string) (*ChangeListener, error) {
watcher, err := filenotify.New(200*time.Millisecond, fileWatcherStrategy)
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
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
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
FileWatcherStrategy 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", ""), ","),
FileWatcherStrategy: os.Getenv("LOCALSTACK_FILE_WATCHER_STRATEGY"),
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.FileWatcherStrategy)

// 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

Back | FazBrowse Home | New Git URL