-
Notifications
You must be signed in to change notification settings - Fork 101
refactor: replace go-kit logger with slog #1450
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
base: main
Are you sure you want to change the base?
Conversation
There was also a significant effort to migrate Prometheus to |
if len(dsErrors) != 0 { | ||
//nolint:errcheck | ||
level.Error(logger).Log("msg", fmt.Sprintf("Failed to update Grafana data source uids: %s", dsErrors)) | ||
logger.Error(fmt.Sprintf("Failed to update Grafana data source uids: %s", dsErrors)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can fixed to eliminate the fmt.Sprintf()
.
logger.Error(fmt.Sprintf("Failed to update Grafana data source uids: %s", dsErrors)) | |
logger.Error("Failed to update Grafana data source uids", "error", dsErrors) |
This make sense code wise, but speaking to the team, we see a need to make sure the output is compatible with the old JSON. Is this feasible to ensure? Looks like it's mostly For level being upper case / lower case I think that's fine too. |
The Prometheus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM for slog on Go API side. For output, we need to maintain some compatibility though.
Now I recall Prometheus team wrote a compatibility layer utils for this. We can import and use it from here: https://github.com/prometheus/common/blob/main/promslog/slog.go#L242
Should we adopt this? Also I assume we do component by component?
Yea I just found too 🙈 , thanks |
We have a diamond dependency problem with the frontend and using
There is only toil and sadness ahead trying to unwind these dependency issues. |
Isn't this simple to unwind? Promlog is for go-kit so frontend will have to move to slog to and it's solved, no? But I agree it's painful, like every change that touches literally every file (logging) 🙈 |
FYI, we wrote a bash script to help automate the conversion from go-kit to slog. |
0c38d0a
to
0829e21
Compare
No. Everything is related. Just as one example of a tricky situation for us, some places we pass a go-kit logger to prometheus/prometheus. So, we either have to have both loggers or upgrade to v3. On a related note, this is officially an unforking task now, too. |
FYI: This is still needed after 0.17 - especially when we upgrade our fork to 3.5 |
Since Go 1.22, there is a structure logger
slog
in the standard library. Compared togo-kit/log
, the logger we are currently using, it offers several advantages:We have configured
go-kit
to output logs that look like this:slog
outputs logs that look like this, with minimal configuration:It is possible to modify slog output to match previous logging. However, it seems likely that slog conventions will likely see increased adoption over time. In addition,
slog
took cues from OpenTelemetry, like the log level values.When the standard library did not include structured logging, many different logging libraries proliferated, and it was difficult to choose a good solution. Over time, it has become clear that
go-kit/log
has seen limited adoption. For instance, go-kit has 187 stars on GitHub, compared to 22.7K for zap, 25.1K for logrus, and 11K for zerolog.