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

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: Address comments Created 4 years, 10 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
« no previous file with comments | « go/buildbot/local_db.go ('k') | go/metrics2/counter.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // responseProxy implements http.ResponseWriter and records the status codes. 178 // responseProxy implements http.ResponseWriter and records the status codes.
179 type responseProxy struct { 179 type responseProxy struct {
180 http.ResponseWriter 180 http.ResponseWriter
181 wroteHeader bool 181 wroteHeader bool
182 } 182 }
183 183
184 func (rp *responseProxy) WriteHeader(code int) { 184 func (rp *responseProxy) WriteHeader(code int) {
185 if !rp.wroteHeader { 185 if !rp.wroteHeader {
186 glog.Infof("Response Code: %d", code) 186 glog.Infof("Response Code: %d", code)
187 » » metrics.GetOrRegisterCounter(fmt.Sprintf("http.statuscode.%d", c ode), metrics.DefaultRegistry).Inc(1) 187 » » metrics2.GetCounter("http.response", map[string]string{"statusco de": strconv.Itoa(code)}).Inc(1)
188 rp.ResponseWriter.WriteHeader(code) 188 rp.ResponseWriter.WriteHeader(code)
189 rp.wroteHeader = true 189 rp.wroteHeader = true
190 } 190 }
191 } 191 }
192 192
193 // recordResponse returns a wrapped http.Handler that records the status codes o f the 193 // recordResponse returns a wrapped http.Handler that records the status codes o f the
194 // responses. 194 // responses.
195 // 195 //
196 // Note that if a handler doesn't explicitly set a response code and goes with 196 // Note that if a handler doesn't explicitly set a response code and goes with
197 // the default of 200 then this will never record anything. 197 // the default of 200 then this will never record anything.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 val, err = strconv.Atoi(valStr) 267 val, err = strconv.Atoi(valStr)
268 if err != nil { 268 if err != nil {
269 return 0, fmt.Errorf("Not a valid integer value.") 269 return 0, fmt.Errorf("Not a valid integer value.")
270 } 270 }
271 } 271 }
272 if val < 0 { 272 if val < 0 {
273 return defaultVal, nil 273 return defaultVal, nil
274 } 274 }
275 return val, nil 275 return val, nil
276 } 276 }
OLDNEW
« no previous file with comments | « go/buildbot/local_db.go ('k') | go/metrics2/counter.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698