-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fsoc 24 #145
Fsoc 24 #145
Conversation
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #145 +/- ##
==========================================
- Coverage 32.34% 31.69% -0.65%
==========================================
Files 27 28 +1
Lines 3568 3641 +73
==========================================
Hits 1154 1154
- Misses 2323 2396 +73
Partials 91 91
|
cmd/root.go
Outdated
@@ -93,6 +102,7 @@ func init() { | |||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable detailed output") | |||
rootCmd.PersistentFlags().Bool("curl", false, "Log curl equivalent for platform API calls (implies --verbose)") | |||
rootCmd.PersistentFlags().String("log", path.Join(os.TempDir(), "fsoc.log"), "determines the location of the fsoc log file") | |||
rootCmd.PersistentFlags().Bool("no-update-warning", false, "Removes daily warning for updates") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rootCmd.PersistentFlags().Bool("no-update-warning", false, "Removes daily warning for updates") | |
rootCmd.PersistentFlags().Bool("no-version-check", false, "Removes daily check for new versions of fsoc") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that what we're skipping is the whole check, not just the warning. If this flag is set, none of the actions should be taken (no reading the timestamp file, no reading the latest version, no updating the timestamp file). This is useful in restricted environments (e.g., CI), where outgoing access is not possible or there is no need to perform the check; as well as in cases when the check is causing problems.
cmd/root.go
Outdated
@@ -222,6 +232,35 @@ func preExecHook(cmd *cobra.Command, args []string) { | |||
log.Fatalf("fsoc is not configured, please use \"fsoc config set\" to configure an initial context") | |||
} | |||
} | |||
|
|||
// Do version checking | |||
noUpdateWarning, _ := cmd.Flags().GetBool("no-update-warning") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please check if FSOC_NO_VERSION_CHECK (matches the flag name, prefixed with FSOC_ and uppercased) environment variable is set. For some cases, such as CI, it is more convenient to set the env var once rather than add the flag to every command.
cmd/root.go
Outdated
|
||
// Do version checking | ||
noUpdateWarning, _ := cmd.Flags().GetBool("no-update-warning") | ||
updateChecked := int(time.Now().Unix())-getRecentTimestamp() > int(secondInDay) && !noUpdateWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this code must be conditional on whether we're doing the check. If the --no-version-check flag is set (or env var), there is no need to check timestamps. You can leave the channel as nil, and then in the post hook, omit reading if it's nil
cmd/root.go
Outdated
_ = os.Remove(os.TempDir() + "fsoc.timestamp") | ||
_, err = os.Create(os.TempDir() + "fsoc.timestamp") | ||
if err != nil { | ||
log.Errorf(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a warning and there should be some context to the error, such as "failed to create version check timestamp file, check will be performed next time", and then the error info. This way a warning that says that, for example, a directory is not writeable, will be in context of what we were trying to do; otherwise, users will wonder why we are trying to write to a file when they are asking for a solution list, for example.
Also, when formatting an error, it's recommended to use "%w" format and the err
value itself, rather than just the string err.Error()
. This allows for unwrapping the error).
cmd/root.go
Outdated
} | ||
} | ||
|
||
func getRecentTimestamp() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func getRecentTimestamp() int { | |
func getLastVersionCheckTime() int { |
cmd/version/version.go
Outdated
currentVersion := GetVersion() | ||
currentVersionSemVer := ConvertVerToSemVar(currentVersion) | ||
newerVersionAvailable := currentVersionSemVer.Compare(newestVersionSemVar) == -1 | ||
var debugFields = log.Fields{"newerVersionAvailable": newerVersionAvailable, "oldVersion": currentVersionSemVer.String(), "newVersion": newestVersionSemVar.String()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should include the newerVersionAvailable field. This should be--and is--part of the message: a newer version is available.
Also, instead of "old" and "new" version field names, it will be more helpful to call them "current" (i.e., this is what your current fsoc that is running is) and "latest" (i.e., this is what is available / you should run)
cmd/version/version.go
Outdated
if newerVersionAvailable { | ||
log.WithFields(debugFields).Warnf("There is a newer version of FSOC available, please upgrade from version %s to version %s", currentVersionSemVer.String(), newestVersionSemVar.String()) | ||
} else { | ||
log.WithFields(debugFields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to log this; but it we do, I propose we just log the version values
cmd/version/version.go
Outdated
var debugFields = log.Fields{"newerVersionAvailable": newerVersionAvailable, "oldVersion": currentVersionSemVer.String(), "newVersion": newestVersionSemVar.String()} | ||
|
||
if newerVersionAvailable { | ||
log.WithFields(debugFields).Warnf("There is a newer version of FSOC available, please upgrade from version %s to version %s", currentVersionSemVer.String(), newestVersionSemVar.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already include the versions in the fields, I don't think we need to include them in the message as well. Just say "There is a newer version of fsoc available, please upgrade soon"
cmd/version/version.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider moving this to a versioncheck.go. Even though the file is short, it is quite dense and I think it will be better to separate the code related to the latest-version check.
cmd/root.go
Outdated
if updateChecked { | ||
go version.CheckForUpdate(updateChannel) | ||
} else { | ||
go func() { updateChannel <- version.ConvertVerToSemVar(version.GetVersion()) }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the purpose of this is just to not do (skip) the check, isn't there a better way?
@pnickolov it is great to have the ability to check for available updates. Can we make this to not be the default behavior. This kind of hidden work raises some questions, in most cases would be undesirable and AFAIK it is somewhat unorthodox for an OSS CLI tool. On top of being a bad practice (IMO), I have a few practical cases where it would be undesirable:
Here are some suggestions on how to make it less intrusive, ordered by my preference:
|
In reply to @pavel-georgiev : I agree with some of the issues but we still expect significant changes and making sure the latest version is in use is important. We're trying to follow the pip approach (except warn no more than once a day). I think @GDW1 has addressed most of the issues:
|
Description
Every 24 hours, FSOC will check if there is a update available. It will create a temp file that holds the most recent timestep
Type of Change
Checklist