Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: go/httputils/http.go

Issue 1722163002: Metrics2: Store a registry of Counters (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 package httputils 1 package httputils
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "io/ioutil" 7 "io/ioutil"
8 "net" 8 "net"
9 "net/http" 9 "net/http"
10 "net/url" 10 "net/url"
11 "runtime" 11 "runtime"
12 "strconv" 12 "strconv"
13 "time" 13 "time"
14 14
15 // Below is a port of the exponential backoff implementation from 15 // Below is a port of the exponential backoff implementation from
16 // google-http-java-client. 16 // google-http-java-client.
17 "github.com/cenkalti/backoff" 17 "github.com/cenkalti/backoff"
18 "github.com/fiorix/go-web/autogzip" 18 "github.com/fiorix/go-web/autogzip"
19 "github.com/rcrowley/go-metrics"
20 "github.com/skia-dev/glog" 19 "github.com/skia-dev/glog"
20 "go.skia.org/infra/go/metrics2"
21 "go.skia.org/infra/go/timer" 21 "go.skia.org/infra/go/timer"
22 "go.skia.org/infra/go/util" 22 "go.skia.org/infra/go/util"
23 ) 23 )
24 24
25 const ( 25 const (
26 DIAL_TIMEOUT = time.Minute 26 DIAL_TIMEOUT = time.Minute
27 REQUEST_TIMEOUT = 5 * time.Minute 27 REQUEST_TIMEOUT = 5 * time.Minute
28 28
29 // Exponential backoff defaults. 29 // Exponential backoff defaults.
30 INITIAL_INTERVAL = 500 * time.Millisecond 30 INITIAL_INTERVAL = 500 * time.Millisecond
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 // responseProxy implements http.ResponseWriter and records the status codes. 172 // responseProxy implements http.ResponseWriter and records the status codes.
173 type responseProxy struct { 173 type responseProxy struct {
174 http.ResponseWriter 174 http.ResponseWriter
175 wroteHeader bool 175 wroteHeader bool
176 } 176 }
177 177
178 func (rp *responseProxy) WriteHeader(code int) { 178 func (rp *responseProxy) WriteHeader(code int) {
179 if !rp.wroteHeader { 179 if !rp.wroteHeader {
180 glog.Infof("Response Code: %d", code) 180 glog.Infof("Response Code: %d", code)
181 » » metrics.GetOrRegisterCounter(fmt.Sprintf("http.statuscode.%d", c ode), metrics.DefaultRegistry).Inc(1) 181 » » metrics2.GetCounter("http.response", map[string]string{"statusco de": strconv.Itoa(code)}).Inc(1)
182 rp.ResponseWriter.WriteHeader(code) 182 rp.ResponseWriter.WriteHeader(code)
183 rp.wroteHeader = true 183 rp.wroteHeader = true
184 } 184 }
185 } 185 }
186 186
187 // recordResponse returns a wrapped http.Handler that records the status codes o f the 187 // recordResponse returns a wrapped http.Handler that records the status codes o f the
188 // responses. 188 // responses.
189 // 189 //
190 // Note that if a handler doesn't explicitly set a response code and goes with 190 // Note that if a handler doesn't explicitly set a response code and goes with
191 // the default of 200 then this will never record anything. 191 // the default of 200 then this will never record anything.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 val, err = strconv.Atoi(valStr) 261 val, err = strconv.Atoi(valStr)
262 if err != nil { 262 if err != nil {
263 return 0, fmt.Errorf("Not a valid integer value.") 263 return 0, fmt.Errorf("Not a valid integer value.")
264 } 264 }
265 } 265 }
266 if val < 0 { 266 if val < 0 {
267 return defaultVal, nil 267 return defaultVal, nil
268 } 268 }
269 return val, nil 269 return val, nil
270 } 270 }
OLDNEW
« no previous file with comments | « go/buildbot/local_db.go ('k') | go/metrics2/counter.go » ('j') | go/metrics2/metrics.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698