Skip to content

Conversation

@nirarg
Copy link
Contributor

@nirarg nirarg commented Feb 2, 2022

What this PR does / why we need it:

cmd/log/log.go was added in PR #832
Change all cmd modules to use this cmd logger
This is done following to the discussion here:
#832 (comment)

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

@openshift-ci openshift-ci bot requested review from alvaroaleman and csrwng February 2, 2022 08:21
@enxebre
Copy link
Member

enxebre commented Feb 2, 2022

/lgtm
PTAL @ironcladlou

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 2, 2022
cmd/log/log.go Outdated

func Info(msg string, keysAndValues ...interface{}) {
log.Info(msg, keysAndValues...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason log is private and the methods are re-exported from this package? Why not make log public and delete the Error and Info functions?

Copy link
Contributor Author

@nirarg nirarg Feb 2, 2022

Choose a reason for hiding this comment

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

I see two reasons for that:

  1. This way we can call the logger with log.Info(...) instead of log.Log.Info(...)
  2. This will allow future modifications for the logger, without changing all the callers (change only inside the wrapper functions)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see two reasons for that:

  1. This way we can call the logger with log.Info(...) instead of log.Log.Info(...)

This can already be effectively achieved if Log is public. Users can specify a dot import alias:

import (
  . "github.com/openshift/hypershift/cmd/log"
)

func foo() {
  Log.Info(...)
}

The user could also alias it to whatever package name they want.

  1. This will allow future modifications for the logger, without changing all the callers (change only inside the wrapper functions)

What you're describing sounds like a logging interface. There's already a history of competing logging interfaces for Go, and we're currently not using any of them. Instead, we're just linking directly to Zap. If we wanted to switch to an interface, I think we need design consensus from the team, and we would first probably want to investigate using https://github.com/go-logr/logr, which is the interface controller-runtime is using (and we're tightly coupled to controller-runtime). But part of the reason to link directly to Zap is to take advantage of its specific features instead of using a lowest common denominator interface, so there's definitely a discussion to be had.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will change it now
This will require to change all lines using the logger from log. to Log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The make verify doesn't allow dot imports:
cmd/bastion/aws/create.go:13:2: should not use dot imports (ST1001)

Copy link
Contributor

@ironcladlou ironcladlou Feb 2, 2022

Choose a reason for hiding this comment

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

The linter isn't always the final arbiter of style here, have to get more feedback from the rest of the team. Another option would be for users to declare a local logger, like:

import (
  logger "github.com/openshift/hypershift/cmd/log"
)

var log = logger.Log

But I can't speak for everyone on the team. This is really subjective.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of underscore imports either, because the compiler can't detect when they become unused. Both using log.Log or declaring a package-level variable like in your comment above seems fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Declaring a package-level variable is actually how it was before this PR
In each package defined log.go file and defined the package variable in it
Do you prefer to keep the code this way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either that or changing the log calls to log.Log.${Method}, both are fine with me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the code in this PR call: log.Log.${Method}
In case you prefer to use the package-level variable we can keep the previous implementation and close this PR

cmd/log/log.go was added in PR openshift#832
Change all cmd modules to use this cmd logger
This is done following to the discussion here:
openshift#832 (comment)
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 8, 2022
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 8, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 8, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, nirarg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 8, 2022
@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 8, 2022

@nirarg: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit 1f64572 into openshift:main Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants