Merge pull request #48 from prometheus/beorn7/fix-summary-dimensions

Beorn7/fix summary dimensions
This commit is contained in:
juliusv 2015-01-22 17:03:39 +01:00
commit 3713bd7d97
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

@ -116,20 +116,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()
@ -148,9 +148,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 {