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

fix: offline mode would spam logs when file changes #406

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions internal/filedata/archive_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (am *ArchiveManager) monitorForChanges(original os.FileInfo) {

prevInfo := original

am.loggers.Infof("Monitoring %s for changes (every %s) (size=%d, mtime=%s)", am.filePath, am.monitoringInterval, original.Size(), original.ModTime())
am.loggers.Infof(logMsgMonitoringStarted, am.filePath, am.monitoringInterval, original.Size(), original.ModTime())

for {
select {
Expand All @@ -104,27 +104,29 @@ func (am *ArchiveManager) monitorForChanges(original os.FileInfo) {
nextInfo, err := os.Stat(am.filePath)
if err != nil {
if os.IsNotExist(err) {
am.loggers.Errorf("File %s not found", am.filePath)
am.loggers.Errorf(logMsgReloadFileStatNotFound, am.filePath)
} else {
am.loggers.Errorf("Error: %s", err)
am.loggers.Errorf(logMsgReloadFileStatUnknownError, err)
}
continue
}
if fileMayHaveChanged(prevInfo, nextInfo) {
am.loggers.Infof("File %s has changed (size=%d, mtime=%s)", am.filePath, nextInfo.Size(), nextInfo.ModTime())
am.loggers.Infof(logMsgFileChanged, am.filePath, nextInfo.Size(), nextInfo.ModTime())
reader, err := newArchiveReader(am.filePath)
if err != nil {
// A failure here might be a real failure, or it might be that the file is being copied
// over non-atomically so that we're seeing an invalid partial state.
am.loggers.Warnf(logMsgReloadError, err.Error())
continue
}
am.loggers.Warnf("Reloaded data from %s", am.filePath)
am.loggers.Warnf(logMsgReloadedData, am.filePath)
am.updatedArchive(reader)
reader.Close()
} else {
am.loggers.Debugf("File %s has not changed (size=%d, mtime=%s)", am.filePath, nextInfo.Size(), nextInfo.ModTime())
am.loggers.Debugf(logMsgFileNotChanged, am.filePath, nextInfo.Size(), nextInfo.ModTime())
}

prevInfo = nextInfo
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions internal/filedata/errors_and_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import "fmt"
// except for debug logging.

const (
logMsgAddEnv = "Added environment %s (%s)"
logMsgUpdateEnv = "Updated environment %s (%s)"
logMsgDeleteEnv = "Removed environment %s (%s)"
logMsgNoEnvs = "The data file does not contain any environments; check your configuration"
logMsgBadEnvData = "Found invalid data for environment %s; skipping this environment"
logMsgReloadedData = "Reloaded data from %s"
logMsgReloadFileNotFound = "Data file reload failed; file not found"
logMsgReloadError = "Data file reload failed; file is invalid or possibly incomplete (error: %s)"
logMsgReloadUnchangedRetry = "Data file has not changed since last failure, will wait in case it is still being copied"
logMsgReloadUnchangedNoMoreRetries = "Data file reload failed, and no further changes were detected; giving up until next change (error: %s)"
logMsgReloadWillRetry = "Will retry in %s"
logMsgAddEnv = "Added environment %s (%s)"
logMsgUpdateEnv = "Updated environment %s (%s)"
logMsgDeleteEnv = "Removed environment %s (%s)"
logMsgNoEnvs = "The data file does not contain any environments; check your configuration"
logMsgBadEnvData = "Found invalid data for environment %s; skipping this environment"
logMsgReloadedData = "Reloaded data from %s"
logMsgMonitoringStarted = "Monitoring data file %s for changes (every %s) (size=%d, mtime=%s)"
logMsgReloadFileStatNotFound = "Data file stat failed; file %s not found"
logMsgReloadFileStatUnknownError = "Data file stat failed: %v"
logMsgReloadError = "Data file reload failed; file is invalid or possibly incomplete (error: %s)"
logMsgFileChanged = "Data file %s has changed (size=%d, mtime=%s)"
logMsgFileNotChanged = "Data file %s has not changed (size=%d, mtime=%s)"
)

func errBadItemJSON(key, namespace string) error {
Expand Down
Loading