Remove the partition of summaries by HTTP status code and method.

Summaries as implemented cannot be aggregated in a meaningful
way. Partitoning them by status code and method only made sense if we
were interested in the individual latency and size of e.g. GET request
that result in status 503. In general, that's not the case. Most of
the time, the user will be interested in the latency and size of _all_
HTTP requests.

(With future changes to client_golang, we will consider making the
HTTP instrumentation configurable, e.g. to handle the case where the
user is only interested in the latency of successful requests.)
This commit is contained in:
Bjoern Rabenstein 2015-01-13 14:57:37 +01:00
parent 159e96f6c7
commit 05059724f8
3 changed files with 15 additions and 31 deletions

View File

@ -55,7 +55,7 @@ func TestTimestampConversions(t *testing.T) {
ts := TimestampFromUnixNano(unixNano) ts := TimestampFromUnixNano(unixNano)
if !ts.Time().Equal(t1) { if !ts.Time().Equal(t1) {
t.Fatalf("Expected %s, got %s %d", t1, ts.Time()) t.Fatalf("Expected %s, got %s", t1, ts.Time())
} }
// Test available precision. // Test available precision.

View File

@ -120,20 +120,20 @@ func InstrumentHandlerFuncWithOpts(opts SummaryOpts, handlerFunc func(http.Respo
opts.Name = "request_duration_microseconds" opts.Name = "request_duration_microseconds"
opts.Help = "The HTTP request latencies in microseconds." opts.Help = "The HTTP request latencies in microseconds."
reqDur := NewSummaryVec(opts, instLabels) reqDur := NewSummary(opts)
opts.Name = "request_size_bytes" opts.Name = "request_size_bytes"
opts.Help = "The HTTP request sizes in bytes." opts.Help = "The HTTP request sizes in bytes."
reqSz := NewSummaryVec(opts, instLabels) reqSz := NewSummary(opts)
opts.Name = "response_size_bytes" opts.Name = "response_size_bytes"
opts.Help = "The HTTP response sizes in bytes." opts.Help = "The HTTP response sizes in bytes."
resSz := NewSummaryVec(opts, instLabels) resSz := NewSummary(opts)
regReqCnt := MustRegisterOrGet(reqCnt).(*CounterVec) regReqCnt := MustRegisterOrGet(reqCnt).(*CounterVec)
regReqDur := MustRegisterOrGet(reqDur).(*SummaryVec) regReqDur := MustRegisterOrGet(reqDur).(Summary)
regReqSz := MustRegisterOrGet(reqSz).(*SummaryVec) regReqSz := MustRegisterOrGet(reqSz).(Summary)
regResSz := MustRegisterOrGet(resSz).(*SummaryVec) regResSz := MustRegisterOrGet(resSz).(Summary)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
now := time.Now() now := time.Now()
@ -152,9 +152,9 @@ func InstrumentHandlerFuncWithOpts(opts SummaryOpts, handlerFunc func(http.Respo
method := sanitizeMethod(r.Method) method := sanitizeMethod(r.Method)
code := sanitizeCode(delegate.status) code := sanitizeCode(delegate.status)
regReqCnt.WithLabelValues(method, code).Inc() regReqCnt.WithLabelValues(method, code).Inc()
regReqDur.WithLabelValues(method, code).Observe(elapsed) regReqDur.Observe(elapsed)
regResSz.WithLabelValues(method, code).Observe(float64(delegate.written)) regResSz.Observe(float64(delegate.written))
regReqSz.WithLabelValues(method, code).Observe(float64(<-out)) regReqSz.Observe(float64(<-out))
}) })
} }

View File

@ -59,20 +59,17 @@ func TestInstrumentHandler(t *testing.T) {
opts.Name = "request_duration_microseconds" opts.Name = "request_duration_microseconds"
opts.Help = "The HTTP request latencies in microseconds." opts.Help = "The HTTP request latencies in microseconds."
reqDur := MustRegisterOrGet(NewSummaryVec(opts, instLabels)).(*SummaryVec) reqDur := MustRegisterOrGet(NewSummary(opts)).(Summary)
opts.Name = "request_size_bytes" opts.Name = "request_size_bytes"
opts.Help = "The HTTP request sizes in bytes." opts.Help = "The HTTP request sizes in bytes."
reqSz := MustRegisterOrGet(NewSummaryVec(opts, instLabels)).(*SummaryVec) MustRegisterOrGet(NewSummary(opts))
opts.Name = "response_size_bytes" opts.Name = "response_size_bytes"
opts.Help = "The HTTP response sizes in bytes." opts.Help = "The HTTP response sizes in bytes."
resSz := MustRegisterOrGet(NewSummaryVec(opts, instLabels)).(*SummaryVec) MustRegisterOrGet(NewSummary(opts))
reqCnt.Reset() reqCnt.Reset()
reqDur.Reset()
reqSz.Reset()
resSz.Reset()
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
req := &http.Request{ req := &http.Request{
@ -88,22 +85,9 @@ func TestInstrumentHandler(t *testing.T) {
t.Fatalf("expected body %s, got %s", "Howdy there!", string(resp.Body.Bytes())) t.Fatalf("expected body %s, got %s", "Howdy there!", string(resp.Body.Bytes()))
} }
if want, got := 1, len(reqDur.children); want != got {
t.Errorf("want %d children in reqDur, got %d", want, got)
}
sum, err := reqDur.GetMetricWithLabelValues("get", "418")
if err != nil {
t.Fatal(err)
}
out := &dto.Metric{} out := &dto.Metric{}
sum.Write(out) reqDur.Write(out)
if want, got := "418", out.Label[0].GetValue(); want != got { if want, got := "test-handler", out.Label[0].GetValue(); want != got {
t.Errorf("want label value %q in reqDur, got %q", want, got)
}
if want, got := "test-handler", out.Label[1].GetValue(); want != got {
t.Errorf("want label value %q in reqDur, got %q", want, got)
}
if want, got := "get", out.Label[2].GetValue(); want != got {
t.Errorf("want label value %q in reqDur, got %q", want, got) t.Errorf("want label value %q in reqDur, got %q", want, got)
} }
if want, got := uint64(1), out.Summary.GetSampleCount(); want != got { if want, got := uint64(1), out.Summary.GetSampleCount(); want != got {