From 05059724f8f3899cdac92abe4c6f7691d6b09066 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Tue, 13 Jan 2015 14:57:37 +0100 Subject: [PATCH] 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.) --- model/timestamp_test.go | 2 +- prometheus/http.go | 18 +++++++++--------- prometheus/http_test.go | 26 +++++--------------------- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/model/timestamp_test.go b/model/timestamp_test.go index f146a7b..d68f7ba 100644 --- a/model/timestamp_test.go +++ b/model/timestamp_test.go @@ -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. diff --git a/prometheus/http.go b/prometheus/http.go index 02726b6..68ae132 100644 --- a/prometheus/http.go +++ b/prometheus/http.go @@ -120,20 +120,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() @@ -152,9 +152,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)) }) } diff --git a/prometheus/http_test.go b/prometheus/http_test.go index da3b75d..e298327 100644 --- a/prometheus/http_test.go +++ b/prometheus/http_test.go @@ -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 {