proxyd: Parameterize full RPC request logging (#3110)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
68cdd2ec8f
commit
cd0afa3176
@ -18,6 +18,9 @@ type ServerConfig struct {
|
|||||||
TimeoutSeconds int `toml:"timeout_seconds"`
|
TimeoutSeconds int `toml:"timeout_seconds"`
|
||||||
|
|
||||||
MaxUpstreamBatchSize int `toml:"max_upstream_batch_size"`
|
MaxUpstreamBatchSize int `toml:"max_upstream_batch_size"`
|
||||||
|
|
||||||
|
EnableRequestLog bool `toml:"enable_request_log"`
|
||||||
|
MaxRequestBodyLogLen int `toml:"max_request_body_log_len"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheConfig struct {
|
type CacheConfig struct {
|
||||||
|
@ -222,6 +222,8 @@ func Start(config *Config) (func(), error) {
|
|||||||
secondsToDuration(config.Server.TimeoutSeconds),
|
secondsToDuration(config.Server.TimeoutSeconds),
|
||||||
config.Server.MaxUpstreamBatchSize,
|
config.Server.MaxUpstreamBatchSize,
|
||||||
rpcCache,
|
rpcCache,
|
||||||
|
config.Server.EnableRequestLog,
|
||||||
|
config.Server.MaxRequestBodyLogLen,
|
||||||
)
|
)
|
||||||
|
|
||||||
if config.Metrics.Enabled {
|
if config.Metrics.Enabled {
|
||||||
|
@ -28,7 +28,7 @@ const (
|
|||||||
MaxBatchRPCCalls = 100
|
MaxBatchRPCCalls = 100
|
||||||
cacheStatusHdr = "X-Proxyd-Cache-Status"
|
cacheStatusHdr = "X-Proxyd-Cache-Status"
|
||||||
defaultServerTimeout = time.Second * 10
|
defaultServerTimeout = time.Second * 10
|
||||||
maxLogLength = 2000
|
maxRequestBodyLogLen = 2000
|
||||||
defaultMaxUpstreamBatchSize = 10
|
defaultMaxUpstreamBatchSize = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,6 +40,8 @@ type Server struct {
|
|||||||
wsMethodWhitelist *StringSet
|
wsMethodWhitelist *StringSet
|
||||||
rpcMethodMappings map[string]string
|
rpcMethodMappings map[string]string
|
||||||
maxBodySize int64
|
maxBodySize int64
|
||||||
|
enableRequestLog bool
|
||||||
|
maxRequestBodyLogLen int
|
||||||
authenticatedPaths map[string]string
|
authenticatedPaths map[string]string
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
maxUpstreamBatchSize int
|
maxUpstreamBatchSize int
|
||||||
@ -60,6 +62,8 @@ func NewServer(
|
|||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
maxUpstreamBatchSize int,
|
maxUpstreamBatchSize int,
|
||||||
cache RPCCache,
|
cache RPCCache,
|
||||||
|
enableRequestLog bool,
|
||||||
|
maxRequestBodyLogLen int,
|
||||||
) *Server {
|
) *Server {
|
||||||
if cache == nil {
|
if cache == nil {
|
||||||
cache = &NoopRPCCache{}
|
cache = &NoopRPCCache{}
|
||||||
@ -87,6 +91,8 @@ func NewServer(
|
|||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
maxUpstreamBatchSize: maxUpstreamBatchSize,
|
maxUpstreamBatchSize: maxUpstreamBatchSize,
|
||||||
cache: cache,
|
cache: cache,
|
||||||
|
enableRequestLog: enableRequestLog,
|
||||||
|
maxRequestBodyLogLen: maxRequestBodyLogLen,
|
||||||
upgrader: &websocket.Upgrader{
|
upgrader: &websocket.Upgrader{
|
||||||
HandshakeTimeout: 5 * time.Second,
|
HandshakeTimeout: 5 * time.Second,
|
||||||
},
|
},
|
||||||
@ -169,11 +175,13 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
RecordRequestPayloadSize(ctx, len(body))
|
RecordRequestPayloadSize(ctx, len(body))
|
||||||
|
|
||||||
|
if s.enableRequestLog {
|
||||||
log.Info("Raw RPC request",
|
log.Info("Raw RPC request",
|
||||||
"body", truncate(string(body)),
|
"body", truncate(string(body), s.maxRequestBodyLogLen),
|
||||||
"req_id", GetReqID(ctx),
|
"req_id", GetReqID(ctx),
|
||||||
"auth", GetAuthCtx(ctx),
|
"auth", GetAuthCtx(ctx),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if IsBatch(body) {
|
if IsBatch(body) {
|
||||||
reqs, err := ParseBatchRPCReq(body)
|
reqs, err := ParseBatchRPCReq(body)
|
||||||
@ -527,9 +535,13 @@ func (n *NoopRPCCache) PutRPC(context.Context, *RPCReq, *RPCRes) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func truncate(str string) string {
|
func truncate(str string, maxLen int) string {
|
||||||
if len(str) > maxLogLength {
|
if maxLen == 0 {
|
||||||
return str[:maxLogLength] + "..."
|
maxLen = maxRequestBodyLogLen
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(str) > maxLen {
|
||||||
|
return str[:maxLen] + "..."
|
||||||
} else {
|
} else {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user