fix: Audit tests on the correct response writer type (#9445)

This commit is contained in:
Anis Elleuch
2020-04-30 06:17:36 +01:00
committed by GitHub
parent c2529260e7
commit d090a17ed0
8 changed files with 191 additions and 139 deletions

View File

@@ -28,6 +28,7 @@ import (
"net/url"
"regexp"
"strings"
"time"
xhttp "github.com/minio/minio/cmd/http"
"github.com/minio/minio/cmd/logger"
@@ -35,6 +36,8 @@ import (
"github.com/minio/minio/pkg/bucket/object/tagging"
"github.com/minio/minio/pkg/handlers"
"github.com/minio/minio/pkg/madmin"
stats "github.com/minio/minio/cmd/http/stats"
)
const (
@@ -360,36 +363,19 @@ func httpTraceHdrs(f http.HandlerFunc) http.HandlerFunc {
func collectAPIStats(api string, f http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
globalHTTPStats.currentS3Requests.Inc(api)
defer globalHTTPStats.currentS3Requests.Dec(api)
isS3Request := !strings.HasPrefix(r.URL.Path, minioReservedBucketPath)
statsWriter := stats.NewRecordAPIStats(w)
// Time start before the call is about to start.
tBefore := UTCNow()
apiStatsWriter := &recordAPIStats{ResponseWriter: w, TTFB: tBefore, isS3Request: isS3Request}
if isS3Request {
globalHTTPStats.currentS3Requests.Inc(api)
}
// Execute the request
f.ServeHTTP(apiStatsWriter, r)
if isS3Request {
globalHTTPStats.currentS3Requests.Dec(api)
}
// Firstbyte read.
tAfter := apiStatsWriter.TTFB
f.ServeHTTP(statsWriter, r)
// Time duration in secs since the call started.
//
// We don't need to do nanosecond precision in this
// simply for the fact that it is not human readable.
durationSecs := tAfter.Sub(tBefore).Seconds()
durationSecs := time.Since(statsWriter.StartTime).Seconds()
// Update http statistics
globalHTTPStats.updateStats(api, r, apiStatsWriter, durationSecs)
globalHTTPStats.updateStats(api, r, statsWriter, durationSecs)
}
}