aboutsummaryrefslogtreecommitdiff
path: root/weed/s3api/s3api_object_handlers.go
diff options
context:
space:
mode:
authorHadi Zamani <130847170+hadizamani021@users.noreply.github.com>2025-01-16 19:53:35 +0330
committerGitHub <noreply@github.com>2025-01-16 08:23:35 -0800
commitc7ae969c06476655bcb0268ca2fd8061bbd6e975 (patch)
treefc597a76c76db8c5f3caea1900684860f383f68d /weed/s3api/s3api_object_handlers.go
parentaa299462f2c4ea857ee6997ec25eedd812904212 (diff)
downloadseaweedfs-c7ae969c06476655bcb0268ca2fd8061bbd6e975.tar.xz
seaweedfs-c7ae969c06476655bcb0268ca2fd8061bbd6e975.zip
Add bucket's traffic metrics (#6444)
* Add bucket's traffic metrics * Add bucket traffic to dashboards * Fix bucket metrics help messages * Fix variable names
Diffstat (limited to 'weed/s3api/s3api_object_handlers.go')
-rw-r--r--weed/s3api/s3api_object_handlers.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go
index 54d6cc69e..8e5008219 100644
--- a/weed/s3api/s3api_object_handlers.go
+++ b/weed/s3api/s3api_object_handlers.go
@@ -135,7 +135,7 @@ func (s3a *S3ApiServer) HeadObjectHandler(w http.ResponseWriter, r *http.Request
s3a.proxyToFiler(w, r, destUrl, false, passThroughResponse)
}
-func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, destUrl string, isWrite bool, responseFn func(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int)) {
+func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, destUrl string, isWrite bool, responseFn func(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int, bytesTransferred int64)) {
glog.V(3).Infof("s3 proxying %s to %s", r.Method, destUrl)
start := time.Now()
@@ -190,7 +190,7 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
if r.Method == http.MethodDelete {
if resp.StatusCode == http.StatusNotFound {
// this is normal
- responseStatusCode := responseFn(resp, w)
+ responseStatusCode, _ := responseFn(resp, w)
s3err.PostLog(r, responseStatusCode, s3err.ErrNone)
return
}
@@ -202,7 +202,7 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
TimeToFirstByte(r.Method, start, r)
if resp.Header.Get(s3_constants.SeaweedFSIsDirectoryKey) == "true" {
- responseStatusCode := responseFn(resp, w)
+ responseStatusCode, _ := responseFn(resp, w)
s3err.PostLog(r, responseStatusCode, s3err.ErrNone)
return
}
@@ -233,7 +233,9 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
setUserMetadataKeyToLowercase(resp)
- responseStatusCode := responseFn(resp, w)
+ responseStatusCode, bytesTransferred := responseFn(resp, w)
+ BucketTrafficSent(bytesTransferred, r)
+
s3err.PostLog(r, responseStatusCode, s3err.ErrNone)
}
@@ -246,7 +248,7 @@ func setUserMetadataKeyToLowercase(resp *http.Response) {
}
}
-func passThroughResponse(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int) {
+func passThroughResponse(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int, bytesTransferred int64) {
for k, v := range proxyResponse.Header {
w.Header()[k] = v
}
@@ -259,8 +261,9 @@ func passThroughResponse(proxyResponse *http.Response, w http.ResponseWriter) (s
w.WriteHeader(statusCode)
buf := mem.Allocate(128 * 1024)
defer mem.Free(buf)
- if n, err := io.CopyBuffer(w, proxyResponse.Body, buf); err != nil {
- glog.V(1).Infof("passthrough response read %d bytes: %v", n, err)
+ bytesTransferred, err := io.CopyBuffer(w, proxyResponse.Body, buf)
+ if err != nil {
+ glog.V(1).Infof("passthrough response read %d bytes: %v", bytesTransferred, err)
}
- return statusCode
+ return statusCode, bytesTransferred
}