Skip to content

Commit 90cca0d

Browse files
authored
Throttle log messages (#134)
1 parent 5dafb3c commit 90cca0d

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

config/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const (
1616
ConfigPathFlag = "config"
1717
LogLevelFlag = "level"
1818

19-
DefaultPProfAddress = "localhost:6060"
19+
DefaultPProfAddress = "localhost:6060"
20+
DefaultLoggingThrottleMaxRPS = 10.0
2021
)
2122

2223
type TransportType string
@@ -115,6 +116,7 @@ type (
115116
SearchAttributeTranslation SATranslationConfig `yaml:"searchAttributeTranslation"`
116117
Metrics *MetricsConfig `yaml:"metrics"`
117118
ProfilingConfig ProfilingConfig `yaml:"profiling"`
119+
Logging LoggingConfig `yaml:"logging"`
118120
}
119121

120122
SATranslationConfig struct {
@@ -167,6 +169,10 @@ type (
167169
MetricsConfig struct {
168170
Prometheus PrometheusConfig `yaml:"prometheus"`
169171
}
172+
173+
LoggingConfig struct {
174+
ThrottleMaxRPS float64 `yaml:"throttleMaxRPS"`
175+
}
170176
)
171177

172178
func (c ProxyClientConfig) IsMux() bool {
@@ -369,3 +375,10 @@ func (s SATranslationConfig) ToMaps(inBound bool) (map[string]map[string]string,
369375
}
370376
return reqMap, respMap
371377
}
378+
379+
func (l LoggingConfig) GetThrottleMaxRPS() float64 {
380+
if l.ThrottleMaxRPS > 0 {
381+
return l.ThrottleMaxRPS
382+
}
383+
return DefaultLoggingThrottleMaxRPS
384+
}

proxy/proxy.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ func NewProxy(
255255
proxy := &Proxy{
256256
config: s2sConfig,
257257
transManager: transManager,
258-
logger: logger,
258+
logger: log.NewThrottledLogger(
259+
logger,
260+
func() float64 {
261+
return s2sConfig.Logging.GetThrottleMaxRPS()
262+
},
263+
),
259264
}
260265

261266
// Proxy consists of two grpc servers: inbound and outbound. The flow looks like the following:
@@ -272,7 +277,7 @@ func NewProxy(
272277
Config: s2sConfig,
273278
},
274279
transManager,
275-
logger,
280+
proxy.logger,
276281
)
277282
}
278283

@@ -284,7 +289,7 @@ func NewProxy(
284289
Config: s2sConfig,
285290
},
286291
transManager,
287-
logger,
292+
proxy.logger,
288293
)
289294
}
290295

0 commit comments

Comments
 (0)