-
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,4 +72,13 @@ metrics: | |
| prometheus: | ||
| listenAddress: "0.0.0.0:9090" | ||
| # This enables profiling with the default config and port | ||
| profiling: {} | ||
| profiling: {} | ||
| logConfigs: | ||
| adminservice: | ||
| throttleMaxRPS: 10 | ||
| testexample: | ||
| throttleMaxRPS: 11 | ||
| adminstreams: | ||
| throttleMaxRPS: 12 | ||
|
||
| testdisabled: | ||
| disabled: true | ||
| 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, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package logging | ||
|
|
||
| import ( | ||
| "go.temporal.io/server/common/log" | ||
| "go.temporal.io/server/common/log/tag" | ||
|
|
||
| "github.com/temporalio/s2s-proxy/config" | ||
| ) | ||
|
|
||
| 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 | ||
| } | ||
| ) | ||
|
|
||
| func NewLoggerProvider(root log.Logger, config config.ConfigProvider) LoggerProvider { | ||
| logConfigs := config.GetS2SProxyConfig().LogConfigs | ||
| globalRootThrottle := log.NewThrottledLogger(root, config.GetS2SProxyConfig().Logging.GetThrottleMaxRPS) | ||
| loggersByComponent := make(map[LogComponentName]log.Logger, len(logConfigs)) | ||
| for component, logConfig := range logConfigs { | ||
| if logConfig.Disabled { | ||
| loggersByComponent[LogComponentName(component)] = log.NewNoopLogger() | ||
| } else { | ||
| loggersByComponent[LogComponentName(component)] = log.NewThrottledLogger(globalRootThrottle, logConfig.GetThrottleMaxRPS) | ||
| } | ||
| } | ||
| return &loggerProvider{ | ||
| root: root, | ||
| loggers: loggersByComponent, | ||
| } | ||
| } | ||
|
|
||
| func (l *loggerProvider) Get(component LogComponentName) log.Logger { | ||
| logger, exists := l.loggers[component] | ||
| if !exists { | ||
| logger = l.root | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| 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...), | ||
| } | ||
| } | ||
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.
can RPS be < 1?
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, will update to demonstrate it