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

Fix logging output for teleport configure commands. #38257

Merged
merged 5 commits into from
Feb 21, 2024

Conversation

AntonAM
Copy link
Contributor

@AntonAM AntonAM commented Feb 15, 2024

This PR fixes printing of the log output to the user when they are running most teleport configure ... commands. Log package used was wrong and also log level needed to be adjusted for those commands.

As an alternative fix, we can just turn all log.Printf() usage in codepath of those commands into fmt.Pritnf(), but it doesn't feel that good to use fmt.Printf() inside /lib/integrations/awsoidc code. On the other hand, log output looks better for user in that case (no INFO label and no filename:linenumber stuff at the end) and we already do it for the externalauditstorage command, which I didn't touch.

Changelog: Fix logging output for teleport configure ... commands.

@AntonAM AntonAM force-pushed the anton/configure-fix-logging branch from 567c130 to 93e71bd Compare February 15, 2024 14:34

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/gravitational/trace"
log "github.com/sirupsen/logrus"
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't alias the import and require using logrus.Debugf explicitly it'd be a bit more obvious that we were using the wrong log package.

Suggested change
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -958,6 +958,9 @@ func onJoinOpenSSH(clf config.CommandLineFlags, conf *servicecfg.Config) error {
func onIntegrationConfDeployService(params config.IntegrationConfDeployServiceIAM) error {
ctx := context.Background()

// Ensure we print output to the user. LogLevel at this point was set to Error.
log.SetLevel(log.InfoLevel)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we respect -d?

Copy link
Contributor

Choose a reason for hiding this comment

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

can't we reuse the same logger as teleport and change only if debug is set?
Not sure if users want to see info related logs when running something on cloud shell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought -d was global, but we actually don't have -d for integration commands. But I changed setting of the level to be flexible, so if the future there will be -d it will not get overwritten.

And I think showing those logs by default is helpful for the user, it tells useful information (policies names).

@@ -108,6 +108,6 @@ func ConfigureAccessGraphSyncIAM(ctx context.Context, clt AccessGraphIAMConfigur
return trace.Wrap(err)
}

log.Printf("IntegrationRole: IAM Policy %q added to Role %q\n", req.IntegrationRoleTAGPolicy, req.IntegrationRole)
logrus.Printf("IntegrationRole: IAM Policy %q added to Role %q\n", req.IntegrationRoleTAGPolicy, req.IntegrationRole)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Use Infof instead of Printf to be consistent with the rest of our logging code. Same suggestion for other commands below.

Suggested change
logrus.Printf("IntegrationRole: IAM Policy %q added to Role %q\n", req.IntegrationRoleTAGPolicy, req.IntegrationRole)
logrus.Infof("IntegrationRole: IAM Policy %q added to Role %q\n", req.IntegrationRoleTAGPolicy, req.IntegrationRole)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 8789535

@@ -958,6 +958,9 @@ func onJoinOpenSSH(clf config.CommandLineFlags, conf *servicecfg.Config) error {
func onIntegrationConfDeployService(params config.IntegrationConfDeployServiceIAM) error {
ctx := context.Background()

// Ensure we print output to the user. LogLevel at this point was set to Error.
utils.InitLogger(utils.LoggingForDaemon, slog.LevelInfo)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rosstimothy done as discussed 0ea804f

tool/teleport/common/teleport.go Outdated Show resolved Hide resolved
@AntonAM AntonAM added this pull request to the merge queue Feb 21, 2024
Merged via the queue into master with commit 941b8e9 Feb 21, 2024
35 of 36 checks passed
@AntonAM AntonAM deleted the anton/configure-fix-logging branch February 21, 2024 15:39
@public-teleport-github-review-bot

@AntonAM See the table below for backport results.

Branch Result
branch/v13 Failed
branch/v14 Failed
branch/v15 Failed

AntonAM added a commit that referenced this pull request Feb 21, 2024
* Fix logging output for 'teleport configure' commands.

* Change imported log package name and don't overwrite debug level.

* Use Infof() instead of Printf()

* Use InitLogger to reset loglevel

* Remove unneeded code.
AntonAM added a commit that referenced this pull request Feb 21, 2024
* Fix logging output for 'teleport configure' commands.

* Change imported log package name and don't overwrite debug level.

* Use Infof() instead of Printf()

* Use InitLogger to reset loglevel

* Remove unneeded code.
AntonAM added a commit that referenced this pull request Feb 21, 2024
* Fix logging output for 'teleport configure' commands.

* Change imported log package name and don't overwrite debug level.

* Use Infof() instead of Printf()

* Use InitLogger to reset loglevel

* Remove unneeded code.
github-merge-queue bot pushed a commit that referenced this pull request Feb 21, 2024
* Fix logging output for 'teleport configure' commands.

* Change imported log package name and don't overwrite debug level.

* Use Infof() instead of Printf()

* Use InitLogger to reset loglevel

* Remove unneeded code.
github-merge-queue bot pushed a commit that referenced this pull request Feb 21, 2024
* Fix logging output for 'teleport configure' commands.

* Change imported log package name and don't overwrite debug level.

* Use Infof() instead of Printf()

* Use InitLogger to reset loglevel

* Remove unneeded code.
github-merge-queue bot pushed a commit that referenced this pull request Feb 21, 2024
* Fix logging output for 'teleport configure' commands.

* Change imported log package name and don't overwrite debug level.

* Use Infof() instead of Printf()

* Use InitLogger to reset loglevel

* Remove unneeded code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants