Skip to content

[common/log] Unify logger package #6779

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

Merged
merged 4 commits into from
Apr 2, 2025

Conversation

3vilhamster
Copy link
Contributor

@3vilhamster 3vilhamster commented Apr 2, 2025

What changed?
Merge loggerimpl package with log.

Why?
As part of FX integration, I need components to have fewer dependencies, which will lower the chances of having circular dependencies.
Merging these packages eliminated the redundancy of two implementations of Noop loggers and provided clear responsibility for the log package.
I also had to touch the quotas package and move dynamic configurable quotas to their package.

How did you test it?
Unit tests

Potential risks
None

Release notes
Refactoring of the log package may require import updates.

Documentation Changes

Copy link
Member

@jakobht jakobht left a comment

Choose a reason for hiding this comment

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

Really nice, this is so much cleaner!

Added a few comments/questions

@@ -20,23 +20,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

//go:generate mockgen -package=$GOPACKAGE -destination=limiterfactory_mock.go github.com/uber/cadence/common/quotas LimiterFactory

package quotas
Copy link
Member

Choose a reason for hiding this comment

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

Is it to avoid a circulair dependency we are moving this to the dynamicconfig package. It feels a bit strange, the ratelimiters does not have anything to do with dynamic config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they use dynamic config and log and introduce circular dependency :(

Copy link
Member

Choose a reason for hiding this comment

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

yeah, well everything uses dynamic config.. but I guess it's very tied to these loggers, so maybe it's ok

const skipForThrottleLogger = 6

// NewThrottledLogger returns an implementation of logger that throttles the
// log messages being emitted. The underlying implementation uses a token bucket
// ratelimiter and stops emitting logs once the bucket runs out of tokens
//
// Fatal/Panic logs are always emitted without any throttling
func NewThrottledLogger(logger log.Logger, rps dynamicconfig.IntPropertyFn) log.Logger {
var log log.Logger
func NewThrottledLogger(logger Logger, rps func() int) Logger {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's better to have a naked function than the "sematic" dynamicconfig.IntPropertyFn

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 introduces circular dependency - dynamic config use log.Logger, so log package is not allowed to have dependency on the dynamicconfig. Also, rps is always called without params, so the annotation of IntPropertyFn does not help.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree it does not help. It says it's a property from dynamic config and not just a random function that returns an int.

I see the issue with the cyclic dependency. That's probably why it was split :) I think it's ok since we have the issue.

Copy link
Member

@Groxx Groxx Apr 2, 2025

Choose a reason for hiding this comment

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

kinda looks like the underlying issue is that we have multiple complex implementations in dynamicconfig itself, which are importing other stuff in what's otherwise a leaf-node package that everything uses (aside from common/types). might be worth making e.g. dynamicconfig/fileconfig and dynamicconfig/collection packages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I will follow up with a PR that moves parts of dynamicconfig and can restore this use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented the move in #6780

@3vilhamster 3vilhamster enabled auto-merge (squash) April 2, 2025 19:24
@3vilhamster 3vilhamster merged commit f7d936d into cadence-workflow:master Apr 2, 2025
22 checks passed
@3vilhamster 3vilhamster deleted the simplify-log branch April 2, 2025 20:38
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.

3 participants