Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

Add ErrorGetNotFound and ErrorGetInternal to volume server metrics (#4960)

SmsS4f95848ba7d26
diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.go
index 10ff15d92e..30813073c5 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 {
diff --git a/weed/stats/metrics_names.go b/weed/stats/metrics_names.go
index cf8b933381..a79b3f3db5 100644
--- a/weed/stats/metrics_names.go
+++ b/weed/stats/metrics_names.go
@@ -10,6 +10,8 @@ const (
ErrorSizeMismatch = "errorSizeMismatch"
ErrorCRC = "errorCRC"
ErrorIndexOutOfRange = "errorIndexOutOfRange"
+ ErrorGetNotFound = "errorGetNotFound"
+ ErrorGetInternal = "errorGetInternal"
// master topology
ErrorWriteToLocalDisk = "errorWriteToLocalDisk"