diff --git a/internal/file/file_manager_service.go b/internal/file/file_manager_service.go index af0e67a91..7e260c168 100644 --- a/internal/file/file_manager_service.go +++ b/internal/file/file_manager_service.go @@ -214,6 +214,7 @@ func (fms *FileManagerService) ClearCache() { clear(fms.fileActions) clear(fms.previousManifestFiles) + slog.Debug("File manager service cleared successfully") } //nolint:revive,cyclop // cognitive-complexity of 13 max is 12, loop is needed cant be broken up @@ -441,6 +442,12 @@ func (fms *FileManagerService) UpdateManifestFile(ctx context.Context, slog.DebugContext(ctx, "Updating manifest file", "current_files", currentFiles, "referenced", referenced) currentManifestFiles, _, readError := fms.manifestFile() + slog.DebugContext(ctx, "Current manifest file") + for _, file := range currentManifestFiles { + slog.DebugContext(ctx, "Manifest File: ", "file", file.ManifestFileMeta.Name, "hash", + file.ManifestFileMeta.Hash, "unmanaged", file.ManifestFileMeta.Unmanaged) + } + // When agent is first started the manifest is updated when an NGINX instance is found, but the manifest file // will be empty leading to previousManifestFiles being empty. This was causing issues if the first config // apply failed leading to the manifest file being rolled back to an empty file. @@ -461,10 +468,17 @@ func (fms *FileManagerService) UpdateManifestFile(ctx context.Context, updatedFiles := make(map[string]*model.ManifestFile) manifestFiles := fms.convertToManifestFileMap(currentFiles, referenced) + slog.DebugContext(ctx, "Files being updated") + for _, file := range currentFiles { + slog.DebugContext(ctx, "Updated File: ", "file", file.GetFileMeta().GetName(), "hash", + file.GetFileMeta().GetHash(), "unmanaged", file.GetUnmanaged()) + } + // During a config apply every file is set to unreferenced // When a new NGINX config context is detected // we update the files in the manifest by setting the referenced bool to true if currentManifestFiles != nil && referenced { + slog.DebugContext(ctx, "Referenced set to ture, add current files to updated files ") for _, currentManifestFile := range currentManifestFiles { // if file from manifest file is unreferenced add it to updatedFiles map if !currentManifestFile.ManifestFileMeta.Referenced { diff --git a/internal/file/file_plugin.go b/internal/file/file_plugin.go index a9747b7b3..650fbd6d8 100644 --- a/internal/file/file_plugin.go +++ b/internal/file/file_plugin.go @@ -182,6 +182,7 @@ func (fp *FilePlugin) handleConfigApplyComplete(ctx context.Context, msg *bus.Me fp.messagePipe.Process(ctx, &bus.Message{Topic: bus.DataPlaneResponseTopic, Data: response}) fp.fileManagerService.ClearCache() + slog.DebugContext(ctx, "File manager service cleared successfully, enabling watchers after config apply complete") fp.enableWatchers(ctx, &model.NginxConfigContext{}, response.GetInstanceId()) } diff --git a/internal/watcher/file/file_watcher_service.go b/internal/watcher/file/file_watcher_service.go index 3779d8c99..9d5740b77 100644 --- a/internal/watcher/file/file_watcher_service.go +++ b/internal/watcher/file/file_watcher_service.go @@ -83,7 +83,11 @@ func (fws *FileWatcherService) Watch(ctx context.Context, ch chan<- FileUpdateMe return case <-instanceWatcherTicker.C: - fws.checkForUpdates(ctx, ch) + if fws.enabled.Load() { + fws.checkForUpdates(ctx, ch) + } else { + slog.DebugContext(ctx, "Skipping check for file updates, file watcher is disabled") + } } if fws.watcher != nil { @@ -110,6 +114,7 @@ func (fws *FileWatcherService) DisableWatcher(ctx context.Context) { } } fws.enabled.Store(false) + slog.DebugContext(ctx, "Successfully disabled file watcher") } func (fws *FileWatcherService) EnableWatcher(ctx context.Context) { @@ -118,6 +123,7 @@ func (fws *FileWatcherService) EnableWatcher(ctx context.Context) { fws.addWatchers(ctx) } fws.enabled.Store(true) + slog.DebugContext(ctx, "Successfully Enabled file watcher") } func (fws *FileWatcherService) Update(ctx context.Context, nginxConfigContext *model.NginxConfigContext) { @@ -166,6 +172,7 @@ func (fws *FileWatcherService) addWatchers(ctx context.Context) { if err != nil { slog.DebugContext(ctx, "Failed to add file watcher", "directory", directory, "error", err) } else { + slog.DebugContext(ctx, "Successfully added file watcher", "directory", directory) fws.filesChanged.Store(true) } } @@ -185,6 +192,7 @@ func (fws *FileWatcherService) removeWatchers(ctx context.Context) { fws.filesChanged.Store(true) } else if _, ok := fws.directoriesToWatch[directoryBeingWatched]; !ok { fws.removeWatcher(ctx, directoryBeingWatched) + slog.DebugContext(ctx, "Successfully removed file watcher", "directory", directoryBeingWatched) fws.filesChanged.Store(true) } } diff --git a/internal/watcher/watcher_plugin.go b/internal/watcher/watcher_plugin.go index 834c7283f..1af1de68a 100644 --- a/internal/watcher/watcher_plugin.go +++ b/internal/watcher/watcher_plugin.go @@ -173,6 +173,7 @@ func (w *Watcher) handleEnableWatchers(ctx context.Context, msg *bus.Message) { // if config apply ended in a reload there is no need to reparse the config so an empty config context is sent // from the file plugin if configContext.InstanceID != "" { + slog.DebugContext(ctx, "Empty instance ID in enable watchers") w.instanceWatcherService.HandleNginxConfigContextUpdate(ctx, instanceID, configContext) } @@ -213,8 +214,10 @@ func (w *Watcher) handleConfigApplyRequest(ctx context.Context, msg *bus.Message defer w.watcherMutex.Unlock() w.instancesWithConfigApplyInProgress = append(w.instancesWithConfigApplyInProgress, instanceID) + slog.DebugContext(ctx, "Watcher plugin disabling watchers for config apply request") w.fileWatcherService.DisableWatcher(ctx) w.instanceWatcherService.SetEnabled(false) + slog.DebugContext(ctx, "Watcher plugin successfully disabled watchers for config apply request") } func (w *Watcher) handleHealthRequest(ctx context.Context) { diff --git a/lefthook.yml b/lefthook.yml index 0888c9e0f..8754b6dd1 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,15 +1,15 @@ -# see https://github.com/evilmartians/lefthook for references -pre-push: - follow: true - piped: true # Stop if one of the steps fail - commands: - 1_generate: - run: make generate - 2_lint: - run: make lint - 3_format: - run: make format - 4_check_mod_change: - run: go mod tidy - 5_check_local_changes: - run: make no-local-changes +## see https://github.com/evilmartians/lefthook for references +#pre-push: +# follow: true +# piped: true # Stop if one of the steps fail +# commands: +# 1_generate: +# run: make generate +# 2_lint: +# run: make lint +# 3_format: +# run: make format +# 4_check_mod_change: +# run: go mod tidy +# 5_check_local_changes: +# run: make no-local-changes