Commit d8563adc authored by 陈曦's avatar 陈曦
Browse files

nfs写入加log

parent 065e4782
Pipeline #82293 passed with stage
in 3 minutes and 21 seconds
...@@ -63,6 +63,11 @@ func NewRequestCaptureService(repo RequestCaptureLogRepository, cfg *config.Conf ...@@ -63,6 +63,11 @@ func NewRequestCaptureService(repo RequestCaptureLogRepository, cfg *config.Conf
if cfg != nil { if cfg != nil {
nfsPath = cfg.RequestCapture.NFSPath nfsPath = cfg.RequestCapture.NFSPath
} }
if nfsPath != "" {
logger.L().Info("request_capture: NFS storage enabled", zap.String("nfs_path", nfsPath))
} else {
logger.L().Info("request_capture: NFS storage disabled (nfs_path not configured), DB-only mode")
}
return &RequestCaptureService{ return &RequestCaptureService{
repo: repo, repo: repo,
nfsPath: nfsPath, nfsPath: nfsPath,
...@@ -86,6 +91,10 @@ func (s *RequestCaptureService) Capture( ...@@ -86,6 +91,10 @@ func (s *RequestCaptureService) Capture(
nfsFilePath = s.buildNFSFilePath(apiKeyID, requestID, now) nfsFilePath = s.buildNFSFilePath(apiKeyID, requestID, now)
bodyCopy := make([]byte, len(body)) bodyCopy := make([]byte, len(body))
copy(bodyCopy, body) copy(bodyCopy, body)
logger.L().Debug("request_capture: launching nfs request write",
zap.Int64("api_key_id", apiKeyID),
zap.String("nfs_file", nfsFilePath),
)
go s.writeToNFS(nfsFilePath, apiKeyID, userID, requestID, path, method, ipAddr, bodyCopy, now) go s.writeToNFS(nfsFilePath, apiKeyID, userID, requestID, path, method, ipAddr, bodyCopy, now)
} }
...@@ -141,6 +150,10 @@ func (s *RequestCaptureService) CaptureResponse(captureID int64, responseBody st ...@@ -141,6 +150,10 @@ func (s *RequestCaptureService) CaptureResponse(captureID int64, responseBody st
// NFS 响应文件:与请求文件同目录,文件名加 _response 后缀 // NFS 响应文件:与请求文件同目录,文件名加 _response 后缀
if nfsFilePath != "" { if nfsFilePath != "" {
respPath := nfsResponseFilePath(nfsFilePath) respPath := nfsResponseFilePath(nfsFilePath)
logger.L().Debug("request_capture: launching nfs response write",
zap.Int64("capture_id", captureID),
zap.String("nfs_file", respPath),
)
s.writeResponseToNFS(respPath, captureID, responseBody) s.writeResponseToNFS(respPath, captureID, responseBody)
} }
}() }()
...@@ -202,6 +215,8 @@ func (s *RequestCaptureService) writeToNFS( ...@@ -202,6 +215,8 @@ func (s *RequestCaptureService) writeToNFS(
zap.String("file", filePath), zap.String("file", filePath),
zap.Error(err), zap.Error(err),
) )
} else {
logger.L().Debug("request_capture: nfs request file written", zap.String("file", filePath))
} }
} }
...@@ -254,5 +269,7 @@ func (s *RequestCaptureService) writeResponseToNFS(filePath string, captureID in ...@@ -254,5 +269,7 @@ func (s *RequestCaptureService) writeResponseToNFS(filePath string, captureID in
zap.String("file", filePath), zap.String("file", filePath),
zap.Error(err), zap.Error(err),
) )
} else {
logger.L().Debug("request_capture: nfs response file written", zap.String("file", filePath))
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment