forked from mirror/client_golang
Merge pull request #48 from prometheus/beorn7/fix-summary-dimensions
Beorn7/fix summary dimensions
This commit is contained in:
commit
3713bd7d97
|
@ -55,7 +55,7 @@ func TestTimestampConversions(t *testing.T) {
|
|||
|
||||
ts := TimestampFromUnixNano(unixNano)
|
||||
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.
|
||||
|
|
|
@ -116,20 +116,20 @@ func InstrumentHandlerFuncWithOpts(opts SummaryOpts, handlerFunc func(http.Respo
|
|||
|
||||
opts.Name = "request_duration_microseconds"
|
||||
opts.Help = "The HTTP request latencies in microseconds."
|
||||
reqDur := NewSummaryVec(opts, instLabels)
|
||||
reqDur := NewSummary(opts)
|
||||
|
||||
opts.Name = "request_size_bytes"
|
||||
opts.Help = "The HTTP request sizes in bytes."
|
||||
reqSz := NewSummaryVec(opts, instLabels)
|
||||
reqSz := NewSummary(opts)
|
||||
|
||||
opts.Name = "response_size_bytes"
|
||||
opts.Help = "The HTTP response sizes in bytes."
|
||||
resSz := NewSummaryVec(opts, instLabels)
|
||||
resSz := NewSummary(opts)
|
||||
|
||||
regReqCnt := MustRegisterOrGet(reqCnt).(*CounterVec)
|
||||
regReqDur := MustRegisterOrGet(reqDur).(*SummaryVec)
|
||||
regReqSz := MustRegisterOrGet(reqSz).(*SummaryVec)
|
||||
regResSz := MustRegisterOrGet(resSz).(*SummaryVec)
|
||||
regReqDur := MustRegisterOrGet(reqDur).(Summary)
|
||||
regReqSz := MustRegisterOrGet(reqSz).(Summary)
|
||||
regResSz := MustRegisterOrGet(resSz).(Summary)
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
now := time.Now()
|
||||
|
@ -148,9 +148,9 @@ func InstrumentHandlerFuncWithOpts(opts SummaryOpts, handlerFunc func(http.Respo
|
|||
method := sanitizeMethod(r.Method)
|
||||
code := sanitizeCode(delegate.status)
|
||||
regReqCnt.WithLabelValues(method, code).Inc()
|
||||
regReqDur.WithLabelValues(method, code).Observe(elapsed)
|
||||
regResSz.WithLabelValues(method, code).Observe(float64(delegate.written))
|
||||
regReqSz.WithLabelValues(method, code).Observe(float64(<-out))
|
||||
regReqDur.Observe(elapsed)
|
||||
regResSz.Observe(float64(delegate.written))
|
||||
regReqSz.Observe(float64(<-out))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -59,20 +59,17 @@ func TestInstrumentHandler(t *testing.T) {
|
|||
|
||||
opts.Name = "request_duration_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.Help = "The HTTP request sizes in bytes."
|
||||
reqSz := MustRegisterOrGet(NewSummaryVec(opts, instLabels)).(*SummaryVec)
|
||||
MustRegisterOrGet(NewSummary(opts))
|
||||
|
||||
opts.Name = "response_size_bytes"
|
||||
opts.Help = "The HTTP response sizes in bytes."
|
||||
resSz := MustRegisterOrGet(NewSummaryVec(opts, instLabels)).(*SummaryVec)
|
||||
MustRegisterOrGet(NewSummary(opts))
|
||||
|
||||
reqCnt.Reset()
|
||||
reqDur.Reset()
|
||||
reqSz.Reset()
|
||||
resSz.Reset()
|
||||
|
||||
resp := httptest.NewRecorder()
|
||||
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()))
|
||||
}
|
||||
|
||||
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{}
|
||||
sum.Write(out)
|
||||
if want, got := "418", 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 {
|
||||
reqDur.Write(out)
|
||||
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 := uint64(1), out.Summary.GetSampleCount(); want != got {
|
||||
|
|
Loading…
Reference in New Issue