diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index c28374d87..3228edc64 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -313,6 +313,7 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var bucket string bumpStartIfNeeded := func() {} + var startRecorded bool if bs := h.opts.BucketedStats; bs != nil { bucket = bs.bucketForRequest(r) if bs.Started != nil { @@ -320,6 +321,7 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { case *expvar.Int: // If we've already seen this bucket for, count it immediately. v.Add(1) + startRecorded = true case nil: // Otherwise, for newly seen paths, only count retroactively // (so started-finished doesn't go negative) so we don't fill @@ -437,12 +439,13 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if bs := h.opts.BucketedStats; bs != nil && bs.Finished != nil { - // Only increment metrics for buckets that result in good HTTP statuses. + // Only increment metrics for buckets that result in good HTTP statuses + // or when we know the start was already counted. // Otherwise they get full of internet scanning noise. Only filtering 404 // gets most of the way there but there are also plenty of URLs that are // almost right but result in 400s too. Seem easier to just only ignore // all 4xx and 5xx. - if msg.Code < 400 { + if startRecorded || msg.Code < 400 { bumpStartIfNeeded() bs.Finished.Add(bucket, 1) }