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

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

merged 19 commits into from Dec 9, 2019

Conversation

bharathi-tenneti
Copy link
Contributor

@bharathi-tenneti bharathi-tenneti commented Nov 20, 2019

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

@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 20, 2019
Copy link
Member

@joelanford joelanford left a 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

@@ -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)
Copy link
Member

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.

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))

Copy link
Member

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.

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a 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 🥇

@camilamacedo86
Copy link
Contributor

+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:

Unable to find a value for %v". Then, using the default value for the environment variable %d", envVar, defValue))

@camilamacedo86 camilamacedo86 added the kind/bug Categorizes issue or PR as related to a bug. label Nov 21, 2019
@bharathi-tenneti bharathi-tenneti changed the title Changed log.info to tidy up using fmt.sprintf WIP: Changed log.info to tidy up using fmt.sprintf Nov 21, 2019
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2019
@openshift-ci-robot openshift-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 21, 2019
Bharathi Tenneti and others added 8 commits November 21, 2019 10:45
* 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
Copy link
Contributor

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

@@ -297,7 +294,7 @@ func getAnsibleVerbosity(gvk schema.GroupVersionKind, defValue int) int {
))
ansibleVerbosity, err := strconv.Atoi(os.Getenv(envVar))
Copy link
Member

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.

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?

CHANGELOG.md Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 4, 2019
go.mod Outdated Show resolved Hide resolved
} else {
val = i
}
} else if ok==false {
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
} else if ok==false {
} else if !ok {

Copy link
Member

@joelanford joelanford left a 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.

@@ -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.
Copy link
Member

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.

val = i
}
} else if !ok {
log.Info("environment variable not set; using default value", "envVar", envVar, "default", defValue)
Copy link
Member

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...

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
as well.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 6, 2019
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

@joelanford
Copy link
Member

@bharathi-tenneti Looks like a go fmt issue. You should be able to run make format to fix it.

Most editors have a Go plugin that can be configured to automatically run go fmt on save, which I find pretty helpful.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 6, 2019
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approved
when the CI issue be fixed

Tested locally:
Screenshot 2019-12-07 at 00 50 11

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 7, 2019
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 9, 2019
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@joelanford joelanford changed the title WIP: Changed log.info to tidy up using fmt.sprintf Changed log.info to tidy up using fmt.sprintf Dec 9, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 9, 2019
@bharathi-tenneti bharathi-tenneti merged commit 82bc6e7 into operator-framework:master Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error Failed to parse %v from environment. is faced when we start the Ansible Operators upgraded to 0.12
5 participants