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

Getting rid of sirupsen/logrus and log.Interface #359

Merged
merged 8 commits into from
Aug 17, 2023

Conversation

duricanikolic
Copy link
Contributor

@duricanikolic duricanikolic commented Aug 13, 2023

What this PR does:
Recently some parts of weaveworks/common have been migrated to dskit (PR). That migration included into dskit also the log.Interface interface that 'unifies' gokit logging and logrus logging.
On the other hand, all Loki, Tempo, Mimir and Pyroscope use only gokit, and neither from them uses logrus directly. Therefore, this PR removes the usage of lrogus and log.Interface from dskit.

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@duricanikolic duricanikolic self-assigned this Aug 13, 2023
@duricanikolic duricanikolic force-pushed the yuri/rate-limit-log branch 5 times, most recently from 7852e6d to 598d45b Compare August 13, 2023 17:17
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

I just did a very high level pass.

log/global.go Outdated Show resolved Hide resolved
log/format.go Outdated Show resolved Hide resolved
log/gokit.go Show resolved Hide resolved
middleware/logging.go Outdated Show resolved Hide resolved
user/logging.go Outdated Show resolved Hide resolved
middleware/logging.go Outdated Show resolved Hide resolved
@duricanikolic duricanikolic requested a review from pracucci August 14, 2023 10:28
@duricanikolic duricanikolic force-pushed the yuri/rate-limit-log branch 2 times, most recently from 62c7d10 to 1d4cd9e Compare August 14, 2023 13:57
@zalegrala
Copy link
Contributor

Are users meant to use go-kit instead of the log.Interface here? I was looking in this area the other day and wondering which pattern users were meant to use.

middleware/grpc_logging.go Outdated Show resolved Hide resolved
middleware/grpc_logging.go Outdated Show resolved Hide resolved
middleware/grpc_logging.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
log/logging.go Outdated Show resolved Hide resolved
log/logging.go Outdated Show resolved Hide resolved
log/gokit_test.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
@duricanikolic
Copy link
Contributor Author

Are users meant to use go-kit instead of the log.Interface here? I was looking in this area the other day and wondering which pattern users were meant to use.

Hi @zalegrala,
The main goal of this PR is to remove the log.Interface interface, and the usage of logrus, so the only supported logger would be go-kit Logger.

I will ask all the teams that use dskit what they think about this idea, and if they all agree, we can merge this PR.

Copy link
Contributor

@simonswine simonswine left a comment

Choose a reason for hiding this comment

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

I am okay with the proposed change, but in case we wanted to appeal to projects (external/internal) which don't use log-kit, this interface is useful and in theory could be developed into compatibility with slog, which is in the stdlib from 1.21.

In any way I am not seeing any blockers from a consumer perspective of grafana/pyroscope

@duricanikolic
Copy link
Contributor Author

I am okay with the proposed change, but in case we wanted to appeal to projects (external/internal) which don't use log-kit, this interface is useful and in theory could be developed into compatibility with slog, which is in the stdlib from 1.21.

In any way I am not seeing any blockers from a consumer perspective of grafana/pyroscope

Hi @simonswine,
Thank you for the feedback. Your remark about keeping log.Interface because it is compatible with other loggers sounds interesting. For the time being no project actually uses it, so I thought about removing it. To be more clear, since all Loki, Tempo, Pyroscope and Mimir use `go-kit' Logger, instead of doing

logger := GoKit(log) // this wraps the go-kit logger into log.Interface
logger.Infof("There are %d projects", 4)

they simply do (not exactly, this is just an example)

level.Info(log).Log("msg", fmt.Sprintf("There are %d projects", 4))

So, we can, for the moment, remove the interface, and if at a point there will be a need to move to another logger (e.g., slog) we will revert the change and put log.Interface back. That change will not be breaking, and projects will not need to change anything, unless they want to migrate to log.Interface. WDYT?

@simonswine
Copy link
Contributor

@duricanikolic the original ambition for dskit was to be generic and adopted inside and outside of Grafana Labs by people building distributed services. This is obviously not the reality today (and might never be). This is in no way blocking or a strongly held opinion, but I think this gets us further from that vision.

@duricanikolic duricanikolic force-pushed the yuri/rate-limit-log branch 6 times, most recently from f564a9d to a995ee0 Compare August 15, 2023 23:02
@duricanikolic
Copy link
Contributor Author

This branch show the changes needed to be done in Loki if this draft PR gets merged.

This branch show the changes needed to be done in Tempo if this draft PR gets merged.

@duricanikolic
Copy link
Contributor Author

@duricanikolic the original ambition for dskit was to be generic and adopted inside and outside of Grafana Labs by people building distributed services. This is obviously not the reality today (and might never be). This is in no way blocking or a strongly held opinion, but I think this gets us further from that vision.

@simonswine if we decide to keep log.Interface how feasible do you think it is that the teams will actually decide to use it and to switch from gokit.Logger to log.Interface?

For example, all occurrences of

level.Info(logger).Log(...)

will have to be replaced with

wrappedLog := GoKit(logger) // wraps gokit.Logger into log.Interface
wrappedLog.Infoln(...)

Moreover, the interface has some disadvantages: for example, if we want to log

level.Info(logger).Log("key1", "value1", "key2", "value2", "msg", "abc")

we need to do

wrappedLog.WithField("key1", "value1").WithField("key2", "value2").Infoln("abc") // Infoln and Infof implicitly add the "msg" key and print the argument as its value

but the calls to WithField are expensive.

@pracucci
Copy link
Contributor

I see @simonswine comment about the log.Interface, however I would like to share different perspective.

This PR is not a regression in that regards: dskit doesn't use log.Interface. The interface was imported 2 weeks ago when copying weaveworks/common into dskit (PR). Dskit itself wasn't using the interface before and neither after, given the interface is only used by the code copied from weaveworks/common.

Do we want to be less opinionated and support a generic log interface for all the logging done by dskit? Maybe. Is this the main blocker to dskit wide adoption? I doubt (e.g. the lack of any doc may be a bigger blocker). Personally, I would defer the discussion about a generic logging interface until we'll have a proof that's the blocker for an adoption outside Grafana Labs.

log/logging.go Outdated Show resolved Hide resolved
log/ratelimit.go Show resolved Hide resolved
middleware/grpc_logging.go Outdated Show resolved Hide resolved
middleware/path_rewrite.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Nikolic <[email protected]>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM, modulo one last fix

server/server.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Nikolic <[email protected]>
Copy link
Contributor

@zalegrala zalegrala left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me.

@duricanikolic
Copy link
Contributor Author

This looks reasonable to me.

@zalegrala could you please approve the PR?

Copy link
Contributor

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

Looks good from Loki team. Thanks!

log/gokit.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

I hope I haven't missed anything. LGTM! (I just left a last nit)

log/gokit.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
log/gokit.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Nikolic <[email protected]>
@duricanikolic duricanikolic merged commit 90d7ee0 into main Aug 17, 2023
@duricanikolic duricanikolic deleted the yuri/rate-limit-log branch August 17, 2023 13:46
chaudum pushed a commit to grafana/loki that referenced this pull request Sep 4, 2023
…#10434)

This PR removes unnecessary code used to convert the dereleased `dslog.Interface` (see grafana/dskit#359) into `go-kit.Logger`.
Additionally, it modifies the signature and implementation of `pkg/util/log/log.go`'s `InitLogger` as follows:

- previous signature 
  ```
  InitLogger(*server.Config, prometheus.Registerer, bool, bool)
  ```
  has been replaced with 
  ```
InitLogger(*server.Config, prometheus.Registerer, bool, bool) log.Logger
  ```
Namely, the new `InitLogger` initialises the global logger and returns
it.
- the new implementation initializes the global logger, but it does not override the default logger for the server. This is now done by the callers of `InitLogger`. Previously, it was done inside `InitLogger` for convenience, since the types of the 2 loggers were not the same.

Signed-off-by: Yuri Nikolic <[email protected]>
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
…grafana#10434)

This PR removes unnecessary code used to convert the dereleased `dslog.Interface` (see grafana/dskit#359) into `go-kit.Logger`.
Additionally, it modifies the signature and implementation of `pkg/util/log/log.go`'s `InitLogger` as follows:

- previous signature 
  ```
  InitLogger(*server.Config, prometheus.Registerer, bool, bool)
  ```
  has been replaced with 
  ```
InitLogger(*server.Config, prometheus.Registerer, bool, bool) log.Logger
  ```
Namely, the new `InitLogger` initialises the global logger and returns
it.
- the new implementation initializes the global logger, but it does not override the default logger for the server. This is now done by the callers of `InitLogger`. Previously, it was done inside `InitLogger` for convenience, since the types of the 2 loggers were not the same.

Signed-off-by: Yuri Nikolic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants