Skip to content

Fix logging output for teleport configure commands.#38257

Merged
AntonAM merged 5 commits intomasterfrom
anton/configure-fix-logging
Feb 21, 2024
Merged

Fix logging output for teleport configure commands.#38257
AntonAM merged 5 commits intomasterfrom
anton/configure-fix-logging

Conversation

@AntonAM
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Comment thread tool/teleport/common/teleport.go Outdated
ctx := context.Background()

// Ensure we print output to the user. LogLevel at this point was set to Error.
log.SetLevel(log.InfoLevel)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

}

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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done 8789535

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
Copy Markdown
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

Comment thread tool/teleport/common/teleport.go Outdated
@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
@AntonAM AntonAM deleted the anton/configure-fix-logging branch February 21, 2024 15:39
@public-teleport-github-review-bot
Copy link
Copy Markdown

@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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants