-
Notifications
You must be signed in to change notification settings - Fork 6
Allow log throttles to be configured per component #181
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
+247
−125
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package logging | ||
|
|
||
| import "go.uber.org/fx" | ||
|
|
||
| var Module = fx.Provide( | ||
| NewLoggerProvider, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package logging | ||
|
|
||
| import ( | ||
| "go.temporal.io/server/common/log" | ||
| "go.temporal.io/server/common/log/tag" | ||
|
|
||
| "github.com/temporalio/s2s-proxy/config" | ||
| ) | ||
|
|
||
| const ( | ||
| AdminService = "adminService" | ||
| WorkflowService = "workflowService" | ||
| ReplicationStreams = "replicationStreams" | ||
| ShardManager = "shardManager" | ||
| ShardRouting = "shardRouting" | ||
| ) | ||
|
|
||
| type ( | ||
| LogComponentName string | ||
| // LoggerProvider provides customized loggers for different components. | ||
| // Based on the component name, different throttling levels can be applied. | ||
| // Right now, any tags stored with the LoggerProvider with With() will be applied to all loggers returned by Get(). | ||
| LoggerProvider interface { | ||
| // Get returns a logger for the given component. If there is no custom config, the root logger will be returned. | ||
| Get(component LogComponentName) log.Logger | ||
| // With returns a new logger provider with the given tags added to all loggers. | ||
| With(tags ...tag.Tag) LoggerProvider | ||
| } | ||
| loggerProvider struct { | ||
| root log.Logger | ||
| loggers map[LogComponentName]log.Logger | ||
| tags []tag.Tag | ||
| } | ||
| ) | ||
|
|
||
| var defaultLoggers = map[LogComponentName]config.LoggingConfig{ | ||
| AdminService: {ThrottleMaxRPS: 3.0}, | ||
| ReplicationStreams: {ThrottleMaxRPS: 3.0 / 60.0}, | ||
| ShardManager: {ThrottleMaxRPS: 3.0}, | ||
| ShardRouting: {ThrottleMaxRPS: 3.0 / 60.0}, | ||
| } | ||
|
|
||
| func NewLoggerProvider(root log.Logger, config config.ConfigProvider) LoggerProvider { | ||
| logConfigs := config.GetS2SProxyConfig().LogConfigs | ||
| throttledRootLog := log.NewThrottledLogger(root, config.GetS2SProxyConfig().Logging.GetThrottleMaxRPS) | ||
| loggersByComponent := make(map[LogComponentName]log.Logger, max(len(logConfigs), len(defaultLoggers))) | ||
| for component, defaultConfig := range defaultLoggers { | ||
| loggersByComponent[component] = loggerForConfig(throttledRootLog, defaultConfig) | ||
| } | ||
| for component, logConfig := range logConfigs { | ||
| loggersByComponent[LogComponentName(component)] = loggerForConfig(throttledRootLog, logConfig) | ||
| } | ||
| return &loggerProvider{ | ||
| root: root, | ||
| loggers: loggersByComponent, | ||
| } | ||
| } | ||
|
|
||
| func loggerForConfig(logger log.Logger, config config.LoggingConfig) log.Logger { | ||
| if config.Disabled { | ||
| return log.NewNoopLogger() | ||
| } | ||
| return log.NewThrottledLogger(logger, config.GetThrottleMaxRPS) | ||
| } | ||
|
|
||
| func (l *loggerProvider) Get(component LogComponentName) log.Logger { | ||
| logger, exists := l.loggers[component] | ||
| if !exists { | ||
| logger = l.root | ||
| } | ||
| return log.With(logger, l.tags...) | ||
| } | ||
|
|
||
| func (l *loggerProvider) With(tags ...tag.Tag) LoggerProvider { | ||
| return &loggerProvider{ | ||
| root: l.root, | ||
| loggers: l.loggers, | ||
| tags: append(l.tags, tags...), | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so if component doesn't exist, then the default behavior is to use root which means always log right?
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.
Yes, though the default logger can be set with a throttle as well.