aboutsummaryrefslogtreecommitdiff
path: root/weed/server
diff options
context:
space:
mode:
authorSmsS4 <36403983+SmsS4@users.noreply.github.com>2023-10-30 18:08:03 +0330
committerGitHub <noreply@github.com>2023-10-30 07:38:03 -0700
commitf95848ba7d26742e9822b12104a8b9bb7698e616 (patch)
tree64405d7d8d502b22f48e38ff1cdfcc3d6a806c3e /weed/server
parentd1e83a3b4df0c515d0aeb75dfbc8f398a771a90a (diff)
downloadseaweedfs-f95848ba7d26742e9822b12104a8b9bb7698e616.tar.xz
seaweedfs-f95848ba7d26742e9822b12104a8b9bb7698e616.zip
Add ErrorGetNotFound and ErrorGetInternal to volume server metrics (#4960)
Diffstat (limited to 'weed/server')
-rw-r--r--weed/server/volume_server_handlers_read.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.go
index 10ff15d92..30813073c 100644
--- a/weed/server/volume_server_handlers_read.go
+++ b/weed/server/volume_server_handlers_read.go
@@ -21,6 +21,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/images"
"github.com/seaweedfs/seaweedfs/weed/operation"
+ "github.com/seaweedfs/seaweedfs/weed/stats"
"github.com/seaweedfs/seaweedfs/weed/storage"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/util"
@@ -28,6 +29,16 @@ import (
var fileNameEscaper = strings.NewReplacer(`\`, `\\`, `"`, `\"`)
+func NotFound(w http.ResponseWriter) {
+ stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorGetNotFound).Inc()
+ w.WriteHeader(http.StatusNotFound)
+}
+
+func InternalError(w http.ResponseWriter) {
+ stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorGetInternal).Inc()
+ w.WriteHeader(http.StatusInternalServerError)
+}
+
func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) {
n := new(needle.Needle)
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)
@@ -56,14 +67,14 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
if !hasVolume && !hasEcVolume {
if vs.ReadMode == "local" {
glog.V(0).Infoln("volume is not local:", err, r.URL.Path)
- w.WriteHeader(http.StatusNotFound)
+ NotFound(w)
return
}
lookupResult, err := operation.LookupVolumeId(vs.GetMaster, vs.grpcDialOption, volumeId.String())
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
if err != nil || len(lookupResult.Locations) <= 0 {
glog.V(0).Infoln("lookup error:", err, r.URL.Path)
- w.WriteHeader(http.StatusNotFound)
+ NotFound(w)
return
}
if vs.ReadMode == "proxy" {
@@ -74,7 +85,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
request, err := http.NewRequest("GET", r.URL.String(), nil)
if err != nil {
glog.V(0).Infof("failed to instance http request of url %s: %v", r.URL.String(), err)
- w.WriteHeader(http.StatusInternalServerError)
+ InternalError(w)
return
}
for k, vv := range r.Header {
@@ -86,7 +97,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
response, err := client.Do(request)
if err != nil {
glog.V(0).Infof("request remote url %s: %v", r.URL.String(), err)
- w.WriteHeader(http.StatusInternalServerError)
+ InternalError(w)
return
}
defer util.CloseResponse(response)
@@ -147,15 +158,16 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
if err != nil || count < 0 {
glog.V(3).Infof("read %s isNormalVolume %v error: %v", r.URL.Path, hasVolume, err)
if err == storage.ErrorNotFound || err == storage.ErrorDeleted {
- w.WriteHeader(http.StatusNotFound)
+ NotFound(w)
} else {
- w.WriteHeader(http.StatusInternalServerError)
+ InternalError(w)
}
return
}
if n.Cookie != cookie {
glog.V(0).Infof("request %s with cookie:%x expected:%x from %s agent %s", r.URL.Path, cookie, n.Cookie, r.RemoteAddr, r.UserAgent())
- w.WriteHeader(http.StatusNotFound)
+ stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorGetNotFound).Inc()
+ NotFound(w)
return
}
if n.LastModified != 0 {