This commit is contained in:
DullJZ
2025-09-13 22:29:48 +08:00
parent 61eeba03ac
commit 4268f6238d
7 changed files with 141 additions and 2 deletions
+12
View File
@@ -43,6 +43,18 @@ func (h *S3Handler) handleBucketOperations(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r)
bucketName := vars["bucket"]
// 记录操作指标
start := time.Now()
method := r.Method
var status = "success"
defer func() {
if h.metrics != nil {
duration := time.Since(start).Seconds()
h.metrics.RecordS3Operation(method, bucketName, status)
h.metrics.RecordS3OperationDuration(method, bucketName, duration)
}
}()
switch r.Method {
case "GET":
h.handleListObjects(w, r, bucketName)
+12
View File
@@ -18,6 +18,18 @@ func (h *S3Handler) handleObjectOperations(w http.ResponseWriter, r *http.Reques
bucketName := vars["bucket"]
key := vars["key"]
// 记录操作指标
start := time.Now()
method := r.Method
var status = "success"
defer func() {
if h.metrics != nil {
duration := time.Since(start).Seconds()
h.metrics.RecordS3Operation(method, bucketName, status)
h.metrics.RecordS3OperationDuration(method, bucketName, duration)
}
}()
switch r.Method {
case "GET":
h.handleGetObject(w, r, bucketName, key)
+4
View File
@@ -3,6 +3,7 @@ package api
import (
"github.com/DullJZ/s3-balance/internal/balancer"
"github.com/DullJZ/s3-balance/internal/bucket"
"github.com/DullJZ/s3-balance/internal/metrics"
"github.com/DullJZ/s3-balance/internal/storage"
"github.com/DullJZ/s3-balance/pkg/presigner"
"github.com/gorilla/mux"
@@ -16,6 +17,7 @@ type S3Handler struct {
storage *storage.Service
accessKey string
secretKey string
metrics *metrics.Metrics
}
// NewS3Handler 创建新的S3兼容API处理器
@@ -26,6 +28,7 @@ func NewS3Handler(
storage *storage.Service,
accessKey string,
secretKey string,
metrics *metrics.Metrics,
) *S3Handler {
return &S3Handler{
bucketManager: bucketManager,
@@ -34,6 +37,7 @@ func NewS3Handler(
storage: storage,
accessKey: accessKey,
secretKey: secretKey,
metrics: metrics,
}
}