mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-12-29 10:59:02 +08:00
chore: add status code for request_total metrics (#5188)
This commit is contained in:
committed by
GitHub
parent
fe417ee02d
commit
a7fc723ae0
@@ -31,6 +31,8 @@ security settings:
|
||||
*/
|
||||
|
||||
func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Request) {
|
||||
statusRecorder := stats.NewStatusResponseWriter(w)
|
||||
w = statusRecorder
|
||||
w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
|
||||
if r.Header.Get("Origin") != "" {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
@@ -38,10 +40,10 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
start := time.Now()
|
||||
requestMethod := r.Method
|
||||
defer func(start time.Time, method *string) {
|
||||
stats.VolumeServerRequestCounter.WithLabelValues(*method).Inc()
|
||||
defer func(start time.Time, method *string, statusRecorder *stats.StatusRecorder) {
|
||||
stats.VolumeServerRequestCounter.WithLabelValues(*method, strconv.Itoa(statusRecorder.Status)).Inc()
|
||||
stats.VolumeServerRequestHistogram.WithLabelValues(*method).Observe(time.Since(start).Seconds())
|
||||
}(start, &requestMethod)
|
||||
}(start, &requestMethod, statusRecorder)
|
||||
switch r.Method {
|
||||
case http.MethodGet, http.MethodHead:
|
||||
stats.ReadRequest()
|
||||
@@ -63,11 +65,9 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque
|
||||
vs.inFlightDownloadDataLimitCond.L.Unlock()
|
||||
vs.GetOrHeadHandler(w, r)
|
||||
case http.MethodDelete:
|
||||
stats.VolumeServerRequestCounter.WithLabelValues(r.Method).Inc()
|
||||
stats.DeleteRequest()
|
||||
vs.guard.WhiteList(vs.DeleteHandler)(w, r)
|
||||
case http.MethodPut, http.MethodPost:
|
||||
stats.VolumeServerRequestCounter.WithLabelValues(r.Method).Inc()
|
||||
contentLength := getContentLength(r)
|
||||
// exclude the replication from the concurrentUploadLimitMB
|
||||
if r.URL.Query().Get("type") != "replicate" && vs.concurrentUploadLimit != 0 {
|
||||
@@ -124,11 +124,21 @@ func getContentLength(r *http.Request) int64 {
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) publicReadOnlyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
statusRecorder := stats.NewStatusResponseWriter(w)
|
||||
w = statusRecorder
|
||||
w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
|
||||
if r.Header.Get("Origin") != "" {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
requestMethod := r.Method
|
||||
defer func(start time.Time, method *string, statusRecorder *stats.StatusRecorder) {
|
||||
stats.VolumeServerRequestCounter.WithLabelValues(*method, strconv.Itoa(statusRecorder.Status)).Inc()
|
||||
stats.VolumeServerRequestHistogram.WithLabelValues(*method).Observe(time.Since(start).Seconds())
|
||||
}(start, &requestMethod, statusRecorder)
|
||||
|
||||
switch r.Method {
|
||||
case http.MethodGet, http.MethodHead:
|
||||
stats.ReadRequest()
|
||||
|
||||
Reference in New Issue
Block a user