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

This commit is contained in:
SmsS4 2023-10-30 18:08:03 +03:30 committed by GitHub
parent d1e83a3b4d
commit f95848ba7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/images" "github.com/seaweedfs/seaweedfs/weed/images"
"github.com/seaweedfs/seaweedfs/weed/operation" "github.com/seaweedfs/seaweedfs/weed/operation"
"github.com/seaweedfs/seaweedfs/weed/stats"
"github.com/seaweedfs/seaweedfs/weed/storage" "github.com/seaweedfs/seaweedfs/weed/storage"
"github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util"
@ -28,6 +29,16 @@ import (
var fileNameEscaper = strings.NewReplacer(`\`, `\\`, `"`, `\"`) 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) { func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) {
n := new(needle.Needle) n := new(needle.Needle)
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path) 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 !hasVolume && !hasEcVolume {
if vs.ReadMode == "local" { if vs.ReadMode == "local" {
glog.V(0).Infoln("volume is not local:", err, r.URL.Path) glog.V(0).Infoln("volume is not local:", err, r.URL.Path)
w.WriteHeader(http.StatusNotFound) NotFound(w)
return return
} }
lookupResult, err := operation.LookupVolumeId(vs.GetMaster, vs.grpcDialOption, volumeId.String()) lookupResult, err := operation.LookupVolumeId(vs.GetMaster, vs.grpcDialOption, volumeId.String())
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err) glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
if err != nil || len(lookupResult.Locations) <= 0 { if err != nil || len(lookupResult.Locations) <= 0 {
glog.V(0).Infoln("lookup error:", err, r.URL.Path) glog.V(0).Infoln("lookup error:", err, r.URL.Path)
w.WriteHeader(http.StatusNotFound) NotFound(w)
return return
} }
if vs.ReadMode == "proxy" { 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) request, err := http.NewRequest("GET", r.URL.String(), nil)
if err != nil { if err != nil {
glog.V(0).Infof("failed to instance http request of url %s: %v", r.URL.String(), err) glog.V(0).Infof("failed to instance http request of url %s: %v", r.URL.String(), err)
w.WriteHeader(http.StatusInternalServerError) InternalError(w)
return return
} }
for k, vv := range r.Header { 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) response, err := client.Do(request)
if err != nil { if err != nil {
glog.V(0).Infof("request remote url %s: %v", r.URL.String(), err) glog.V(0).Infof("request remote url %s: %v", r.URL.String(), err)
w.WriteHeader(http.StatusInternalServerError) InternalError(w)
return return
} }
defer util.CloseResponse(response) defer util.CloseResponse(response)
@ -147,15 +158,16 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
if err != nil || count < 0 { if err != nil || count < 0 {
glog.V(3).Infof("read %s isNormalVolume %v error: %v", r.URL.Path, hasVolume, err) glog.V(3).Infof("read %s isNormalVolume %v error: %v", r.URL.Path, hasVolume, err)
if err == storage.ErrorNotFound || err == storage.ErrorDeleted { if err == storage.ErrorNotFound || err == storage.ErrorDeleted {
w.WriteHeader(http.StatusNotFound) NotFound(w)
} else { } else {
w.WriteHeader(http.StatusInternalServerError) InternalError(w)
} }
return return
} }
if n.Cookie != cookie { 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()) 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 return
} }
if n.LastModified != 0 { if n.LastModified != 0 {

View file

@ -10,6 +10,8 @@ const (
ErrorSizeMismatch = "errorSizeMismatch" ErrorSizeMismatch = "errorSizeMismatch"
ErrorCRC = "errorCRC" ErrorCRC = "errorCRC"
ErrorIndexOutOfRange = "errorIndexOutOfRange" ErrorIndexOutOfRange = "errorIndexOutOfRange"
ErrorGetNotFound = "errorGetNotFound"
ErrorGetInternal = "errorGetInternal"
// master topology // master topology
ErrorWriteToLocalDisk = "errorWriteToLocalDisk" ErrorWriteToLocalDisk = "errorWriteToLocalDisk"