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

Changed log.info to tidy up using fmt.sprintf #2246

Merged
merged 19 commits into from
Dec 9, 2019
Merged
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
Prev Previous commit
Next Next commit
logic added
Bharathi Tenneti committed Nov 21, 2019
commit bd4d60a7a48df05a1b286a061a1c3d1d6eab568c
13 changes: 0 additions & 13 deletions pkg/ansible/watches/watches.go
Original file line number Diff line number Diff line change
@@ -272,23 +272,10 @@ func getMaxWorkers(gvk schema.GroupVersionKind, defValue int) int {
"_",
-1,
))
/*maxWorkers, err := strconv.Atoi(os.Getenv(envVar))
if err != nil {
// we don't care why we couldn't parse it just use default
//log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue)
log.Info(fmt.Sprintf("Using default value for workers %d", defValue))
return defValue
}

if maxWorkers <= 0 {
log.Info("Value %v not valid. Using default %v", maxWorkers, defValue)
return defValue
}*/
maxWorkers := defValue
if val, ok := os.LookupEnv(envVar); ok {
if i, err := strconv.Atoi(val); err != nil {
log.Info(fmt.Sprintf("Unable to find a value for %v. Using default value for maxWorkers %d", envVar, defValue))
Copy link
Member

Choose a reason for hiding this comment

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

I could be wrong, but I think @camilamacedo86 was suggesting that we should log a separate message if we use the default when the environment variable is not set. I would also suggest we follow the structured logging conventions of the logr.Logger.

So here, we can use the following since we have encountered an error trying to parse the string as an integer.

log.Info("could not parse environment variable as an integer; using default value", "envVar", envVar, "default", defValue)

For @camilamacedo86's suggestion, if we do the os.LookupEnv() and ok == false, that means the environment variable was not set. In think in that case, we could log this message:

log.Info("environment variable not set; using default value", "envVar", envVar, "default", defValue)

@camilamacedo86 @jmrodri @bharathi-tenneti WDYT?


} else {
maxWorkers = i
}