diff options
| author | SmsS4 <36403983+SmsS4@users.noreply.github.com> | 2023-08-21 11:12:39 +0330 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-21 00:42:39 -0700 |
| commit | f61490966f70ade813b7cb1d21a24df93fe172b2 (patch) | |
| tree | 011a414b4ef14f27a344162faa4f26a6072247d5 /weed/s3api | |
| parent | 3650e5adda604dc7507ba3f0f63799c4cbfa4dfe (diff) | |
| download | seaweedfs-f61490966f70ade813b7cb1d21a24df93fe172b2.tar.xz seaweedfs-f61490966f70ade813b7cb1d21a24df93fe172b2.zip | |
Add time to first byte metric for s3 (#4768)
* Add time to first byte metric for s3
* Change second to millisecond
Diffstat (limited to 'weed/s3api')
| -rw-r--r-- | weed/s3api/s3api_object_handlers.go | 3 | ||||
| -rw-r--r-- | weed/s3api/stats.go | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index e959ff1f1..b63997cd3 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -355,6 +355,7 @@ func (s3a *S3ApiServer) doDeleteEmptyDirectories(client filer_pb.SeaweedFilerCli func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, destUrl string, isWrite bool, responseFn func(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int)) { glog.V(3).Infof("s3 proxying %s to %s", r.Method, destUrl) + start := time.Now() proxyReq, err := http.NewRequest(r.Method, destUrl, r.Body) @@ -404,12 +405,12 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des return } } - if resp.StatusCode == http.StatusNotFound { s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey) return } + TimeToFirstByte(r.Method, start, r) if resp.Header.Get(s3_constants.X_SeaweedFS_Header_Directory_Key) == "true" { responseStatusCode := responseFn(resp, w) s3err.PostLog(r, responseStatusCode, s3err.ErrNone) diff --git a/weed/s3api/stats.go b/weed/s3api/stats.go index 2b36478ad..369c3e0f6 100644 --- a/weed/s3api/stats.go +++ b/weed/s3api/stats.go @@ -43,3 +43,8 @@ func track(f http.HandlerFunc, action string) http.HandlerFunc { stats_collect.S3RequestCounter.WithLabelValues(action, strconv.Itoa(recorder.Status), bucket).Inc() } } + +func TimeToFirstByte(action string, start time.Time, r *http.Request) { + bucket, _ := s3_constants.GetBucketAndObject(r) + stats_collect.S3TimeToFirstByteHistogram.WithLabelValues(action, bucket).Observe(float64(time.Since(start).Milliseconds())) +} |
