-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changed log.info to tidy up using fmt.sprintf #2246
Conversation
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.
@bharathi-tenneti @jmrodri @camilamacedo86 Do you think it would make sense to do this instead:
maxWorkers := defValue
if val, ok := os.LookupEnv(envVar); ok {
if i, err := strconv.Atoi(val); err != nil {
log.Info(fmt.Sprintf("Failed to parse %v from environment. Using default %v", envVar, defValue))
} else {
maxWorkers = i
}
}
return maxWorkers
pkg/ansible/watches/watches.go
Outdated
@@ -275,7 +275,8 @@ func getMaxWorkers(gvk schema.GroupVersionKind, defValue int) int { | |||
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("Failed to parse %v from environment. Using default %v", envVar, defValue) |
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.
No need to keep this line around anymore.
Ditto for ansibleVerbosity.
pkg/ansible/watches/watches.go
Outdated
log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue) | ||
//log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue) | ||
log.Info(fmt.Sprintf("Using default value for ansible verbosity %d", defValue)) | ||
|
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.
Nit: this extraneous empty line can be removed.
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.
Just the same nits and all shows fine.
Good work 🥇
+1 for the @joelanford suggestion. Just the text that I'd recommend not use the word error or failed, keep the env var for the user know how to change that and the info. So, something as:
|
* leader election bugfix: Delete evicted leader pods Before this patch, when the leader pod is hard evicted but not deleted the leader lock configmap is not garbage collected and subsequent operator pods can never become leader. With this patch, an operator attempting to become the leader is able to delete evicted leader pods triggering garbage collection and allowing leader election to continue. Sometimes, evicted operator pods will remain, even with this patch. This occurs when the leader operator pod is evicted and a new operator pod is created on the same node. In this case, the new pod will also be evicted. When an operator pod is created on a non-failing node, leader election will delete only the evicted leader pod, leaving any evicted operator pods that were not the leader. To replicate the evicted state, I used a `kind` cluster with 2 worker nodes with altered kubelet configuration and a memory-hog version of the memcached operator. See the [altered operator docs](https://github.com/asmacdo/go-memcahced-operator/blob/explosive-operator/README.md)
go.mod
Outdated
@@ -16,6 +16,7 @@ require ( | |||
github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect | |||
github.com/fatih/camelcase v1.0.0 // indirect |
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.
required revert the changes in the go.mod
pkg/ansible/watches/watches.go
Outdated
@@ -297,7 +294,7 @@ func getAnsibleVerbosity(gvk schema.GroupVersionKind, defValue int) int { | |||
)) | |||
ansibleVerbosity, err := strconv.Atoi(os.Getenv(envVar)) |
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 think we should use the same logic for the ansible verbosity operator.
Since the logic is identical, I think it would make sense to define a new function with this signature:
func getIntegerEnvWithDefault(envVar string, defValue int) int
The call it for both maxWorkers
and ansibleVerbosity
.
pkg/ansible/watches/watches.go
Outdated
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)) |
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 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)
pkg/ansible/watches/watches.go
Outdated
} else { | ||
val = i | ||
} | ||
} else if ok==false { |
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.
Nit:
} else if ok==false { | |
} else if !ok { |
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.
A couple more fixes. LGTM once sanity tests pass.
pkg/ansible/watches/watches.go
Outdated
@@ -312,3 +297,18 @@ func getAnsibleVerbosity(gvk schema.GroupVersionKind, defValue int) int { | |||
} | |||
return ansibleVerbosity | |||
} | |||
|
|||
// Returns value for MaxWorkers/Ansibleverbosity based on if envVar is set or a defvalue is used. |
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.
Nit: Go doc convention is to use the identifier name (in this case the function name) as the first word of the comment. Not a huge deal since this function is unexported, but a good habit nonetheless.
pkg/ansible/watches/watches.go
Outdated
val = i | ||
} | ||
} else if !ok { | ||
log.Info("environment variable not set; using default value", "envVar", envVar, "default", defValue) |
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.
Looks like the sanity test is complaining that these log.Info
messages don't start with an upper case letter.
So we need:
Could not parse environment variable...
and Environment variable not set...
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.
/lgtm
as well.
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.
Not passing in the sanity; https://travis-ci.org/operator-framework/operator-sdk/jobs/621627642#L844
@bharathi-tenneti Looks like a Most editors have a Go plugin that can be configured to automatically run |
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.
New changes are detected. LGTM label has been removed. |
Description of the change:
Modified log,Info in watches.go file to print message that doesn't necessarily state failure.
Motivation for the change:
The log should be info because it is not a failure but information
CLOSES: #2186