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

Remove logrus #50829

Merged
merged 5 commits into from
Jan 9, 2025
Merged

Remove logrus #50829

merged 5 commits into from
Jan 9, 2025

Conversation

rosstimothy
Copy link
Contributor

@rosstimothy rosstimothy commented Jan 7, 2025

The only remaining use of logrus is from integrations, which is unfortunately imported by teleport.e, and prevents logrus from being moved to an indirect dependency. The logrus formatter and initialization of the logrus logger will remain in place until integrations is using slog. To prevent any accidental inclusions of logrus within the teleport module the depguard rules have been updated to prohibit importing logrus. The rules also include prohibit a few common log packages that tools like gopls might automatically import.

$ go mod why github.com/sirupsen/logrus
# github.com/sirupsen/logrus
github.com/gravitational/teleport/integrations/access/common/auth
github.com/sirupsen/logrus

Includes https://github.com/gravitational/teleport.e/pull/5807
Depends on #50805

@rosstimothy rosstimothy added the no-changelog Indicates that a PR does not require a changelog entry label Jan 7, 2025
@rosstimothy rosstimothy force-pushed the tross/remove_config_logrus branch 2 times, most recently from 737af4b to 7bcf7bb Compare January 7, 2025 18:44
Base automatically changed from tross/config_slog to master January 7, 2025 20:29
@rosstimothy rosstimothy force-pushed the tross/remove_config_logrus branch 5 times, most recently from 0a31c37 to 9ed50e3 Compare January 8, 2025 14:19
@@ -114,13 +113,6 @@ func (s *handleState) appendAttr(a slog.Attr) bool {
}
}
return nonEmpty
case logrus.Fields:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing including these fields in slog output so this is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was moved into utils/log/slog.go

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 items deleted were moved into lib/utils/log/slog.go to facilitate removing this file in the future.

)

// TODO(tross/noah): Remove once go-spiff has a slog<->workloadapi.Logger adapter.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI @strideynet. If you have a better solution to this in the short term I'm all ears.

Copy link
Contributor

@strideynet strideynet Jan 8, 2025

Choose a reason for hiding this comment

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

I have a ticket w/ go-spiffe to add slog support - spiffe/go-spiffe#281 - perhaps link this ticket here?

What you've done here is good for now!

@rosstimothy rosstimothy force-pushed the tross/remove_config_logrus branch 4 times, most recently from d02cea6 to f9c7fa5 Compare January 8, 2025 17:47
@rosstimothy rosstimothy marked this pull request as ready for review January 8, 2025 18:05
@github-actions github-actions bot added machine-id size/sm tctl tctl - Teleport admin tool tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Jan 8, 2025
@github-actions github-actions bot requested review from bl-nero and strideynet January 8, 2025 18:06
Copy link
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

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

Nice! We are almost 100% logrus-free!

.golangci.yml Outdated Show resolved Hide resolved
e Outdated Show resolved Hide resolved
lib/utils/log/slog.go Show resolved Hide resolved
lib/utils/log/slog.go Show resolved Hide resolved
Comment on lines +39 to +40
//nolint:sloglint // msg cannot be constant
l.l.DebugContext(context.Background(), fmt.Sprintf(format, args...))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe:

	l.log(slog.LevelDebug, format, args...)

and implement the l.log function so it centralized the nolint / fmt.Sprintf logic?

tool/tbot/spiffe.go Show resolved Hide resolved
tool/teleport/common/teleport.go Outdated Show resolved Hide resolved
The only remaining use of logrus is from integrations, which is
unfortunately imported by teleport.e, and prevents logrus from
being moved to an indirect dependency. The logrus formatter and
initialization of the logrus logger will remain in place until
integrations is using slog. To prevent any accidental inclusions
of logrus within the teleport module the depguard rules have been
updated to prohibit importing logrus. The rules also include
prohibit a few common log packages that tools like gopls might
automatically import.
@rosstimothy rosstimothy force-pushed the tross/remove_config_logrus branch from f9c7fa5 to e0433c8 Compare January 8, 2025 21:27
Consolidates configuring of global loggers to a single function.
This is mainly to facilitate configuring the logger for
teleport scp, but will also allow us to remove the copy of logger
initialization that currently exists in integrations/lib/logger.
@rosstimothy rosstimothy force-pushed the tross/remove_config_logrus branch from c31858f to 839b31b Compare January 8, 2025 23:38
// sharedWriter is an [io.Writer] implementation that protects
// writes with a mutex. This allows a single [io.Writer] to be shared
// by both logrus and slog without their output clobbering each other.
type sharedWriter struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

So what hapeened / will happen to lib/utils/log.SharedWriter? Is it being moved here? Why don't I see it being deleted in this PR?

(Also, since this file is already huge, can this struct remain in a separate one?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

log.SharedWriter is going to be removed with the logrus formatter once we are no longer using logrus. I opted to copy it locally here preemptively since a little bit of copying is better than a little bit of dependency.

cfg.Console = io.Discard // disable console printing
case "stdout", "out", "1":
w = os.Stdout
case "stderr", "error", "2", "stdout", "out", "1":
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 having a hard time understanding what's going on here. Why do we disable console printing when the user wants to print to the console? I know it wasn't commented in the original code either, but I still think it warrants a word or two.

The documentation comments of Config.Console and Config.Logger don't help too much, either, as they both sound like serving roughly the same purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at Console more closely, I don't actually see it being used anywhere. For now I'm going to leave this as is and in a follow up PR I will remove it entirely.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe keep the cases for "" and teleport.Syslog in the meantime? Is the case for teleport.Syslog obsolete too?

Copy link
Contributor Author

@rosstimothy rosstimothy Jan 9, 2025

Choose a reason for hiding this comment

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

"" and teleport.Syslog are handled by log.Initialize.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tool/teleport/common/teleport.go Show resolved Hide resolved
cfg.Console = io.Discard // disable console printing
case "stdout", "out", "1":
w = os.Stdout
case "stderr", "error", "2", "stdout", "out", "1":
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe keep the cases for "" and teleport.Syslog in the meantime? Is the case for teleport.Syslog obsolete too?

lib/utils/log/log.go Outdated Show resolved Hide resolved
lib/utils/log/log.go Outdated Show resolved Hide resolved
integrations/lib/logger/logger.go Show resolved Hide resolved

// ValidateFields ensures the provided fields map to the allowed fields. An error
// is returned if any of the fields are invalid.
func ValidateFields(formatInput []string) (result []string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be made private and made a responsibility of Initialize? Perhaps after the duplicated code on integrations/ is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly. I will look into it once the integrations changes are made.

tool/teleport/common/teleport.go Outdated Show resolved Hide resolved
@rosstimothy rosstimothy added this pull request to the merge queue Jan 9, 2025
Merged via the queue into master with commit 2aed5bf Jan 9, 2025
42 checks passed
@rosstimothy rosstimothy deleted the tross/remove_config_logrus branch January 9, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
machine-id no-changelog Indicates that a PR does not require a changelog entry size/sm tctl tctl - Teleport admin tool tsh tsh - Teleport's command line tool for logging into nodes running Teleport.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants