+func (s *MountsSuite) TestMetrics(c *check.C) {
+ s.call("PUT", "/"+TestHash, "", TestBlock)
+ s.call("PUT", "/"+TestHash2, "", TestBlock2)
+ resp := s.call("GET", "/metrics.json", "", nil)
+ c.Check(resp.Code, check.Equals, http.StatusOK)
+ var j []struct {
+ Name string
+ Help string
+ Type string
+ Metric []struct {
+ Label []struct {
+ Name string
+ Value string
+ }
+ Summary struct {
+ SampleCount string `json:"sample_count"`
+ SampleSum float64 `json:"sample_sum"`
+ Quantile []struct {
+ Quantile float64
+ Value float64
+ }
+ }
+ }
+ }
+ json.NewDecoder(resp.Body).Decode(&j)
+ found := make(map[string]bool)
+ for _, g := range j {
+ for _, m := range g.Metric {
+ if len(m.Label) == 2 && m.Label[0].Name == "code" && m.Label[0].Value == "200" && m.Label[1].Name == "method" && m.Label[1].Value == "put" {
+ c.Check(m.Summary.SampleCount, check.Equals, "2")
+ c.Check(len(m.Summary.Quantile), check.Not(check.Equals), 0)
+ c.Check(m.Summary.Quantile[0].Value, check.Not(check.Equals), float64(0))
+ found[g.Name] = true
+ }
+ }
+ }
+ c.Check(found["request_duration_seconds"], check.Equals, true)
+ c.Check(found["time_to_status_seconds"], check.Equals, true)
+}
+
+func (s *MountsSuite) call(method, path, tok string, body []byte) *httptest.ResponseRecorder {