aboutsummaryrefslogtreecommitdiff
path: root/weed/server/filer_server_handlers.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2024-01-10 23:05:27 +0500
committerGitHub <noreply@github.com>2024-01-10 10:05:27 -0800
commita7fc723ae0992c787629ad57c6f2c4f05c1de553 (patch)
treea250a80be0380ccccc10b2dd7e32d8a2e2356ae4 /weed/server/filer_server_handlers.go
parentfe417ee02d1dbe722b0061c3f82dc1916157f36f (diff)
downloadseaweedfs-a7fc723ae0992c787629ad57c6f2c4f05c1de553.tar.xz
seaweedfs-a7fc723ae0992c787629ad57c6f2c4f05c1de553.zip
chore: add status code for request_total metrics (#5188)
Diffstat (limited to 'weed/server/filer_server_handlers.go')
-rw-r--r--weed/server/filer_server_handlers.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.go
index d71b60d70..ac66514f2 100644
--- a/weed/server/filer_server_handlers.go
+++ b/weed/server/filer_server_handlers.go
@@ -4,6 +4,7 @@ import (
"errors"
"net/http"
"os"
+ "strconv"
"strings"
"sync/atomic"
"time"
@@ -17,7 +18,8 @@ import (
func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
start := time.Now()
-
+ statusRecorder := stats.NewStatusResponseWriter(w)
+ w = statusRecorder
origin := r.Header.Get("Origin")
if origin != "" {
if fs.option.AllowedOrigins == nil || len(fs.option.AllowedOrigins) == 0 || fs.option.AllowedOrigins[0] == "*" {
@@ -53,23 +55,23 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
fileId = r.RequestURI[len("/?proxyChunkId="):]
}
if fileId != "" {
- stats.FilerRequestCounter.WithLabelValues(stats.ChunkProxy).Inc()
fs.proxyToVolumeServer(w, r, fileId)
+ stats.FilerHandlerCounter.WithLabelValues(stats.ChunkProxy).Inc()
stats.FilerRequestHistogram.WithLabelValues(stats.ChunkProxy).Observe(time.Since(start).Seconds())
return
}
+ defer func() {
+ stats.FilerRequestCounter.WithLabelValues(r.Method, strconv.Itoa(statusRecorder.Status)).Inc()
+ stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds())
+ }()
+
isReadHttpCall := r.Method == "GET" || r.Method == "HEAD"
if !fs.maybeCheckJwtAuthorization(r, !isReadHttpCall) {
writeJsonError(w, r, http.StatusUnauthorized, errors.New("wrong jwt"))
return
}
- stats.FilerRequestCounter.WithLabelValues(r.Method).Inc()
- defer func() {
- stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds())
- }()
-
w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION)
switch r.Method {
@@ -115,6 +117,8 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
start := time.Now()
+ statusRecorder := stats.NewStatusResponseWriter(w)
+ w = statusRecorder
os.Stdout.WriteString("Request: " + r.Method + " " + r.URL.String() + "\n")
@@ -140,8 +144,8 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Reque
w.Header().Set("Access-Control-Allow-Credentials", "true")
}
- stats.FilerRequestCounter.WithLabelValues(r.Method).Inc()
defer func() {
+ stats.FilerRequestCounter.WithLabelValues(r.Method, strconv.Itoa(statusRecorder.Status)).Inc()
stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds())
}()
// We handle OPTIONS first because it never should be authenticated