1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/sdk/go/arvados"
13 "git.arvados.org/arvados.git/sdk/go/arvadostest"
14 "git.arvados.org/arvados.git/sdk/go/ctxlog"
15 "git.arvados.org/arvados.git/sdk/go/httpserver"
16 "github.com/prometheus/client_golang/prometheus"
20 func (s *routerSuite) TestMetrics(c *C) {
21 reg := prometheus.NewRegistry()
22 router, cancel := testRouter(c, s.cluster, reg)
24 instrumented := httpserver.Instrument(reg, ctxlog.TestLogger(c), router)
25 handler := instrumented.ServeAPI(s.cluster.ManagementToken, instrumented)
27 router.keepstore.BlockWrite(context.Background(), arvados.BlockWriteOptions{
31 router.keepstore.BlockWrite(context.Background(), arvados.BlockWriteOptions{
36 // prime the metrics by doing a no-op request
37 resp := call(handler, "GET", "/", "", nil, nil)
39 resp = call(handler, "GET", "/metrics.json", "", nil, nil)
40 c.Check(resp.Code, Equals, http.StatusUnauthorized)
41 resp = call(handler, "GET", "/metrics.json", "foobar", nil, nil)
42 c.Check(resp.Code, Equals, http.StatusForbidden)
43 resp = call(handler, "GET", "/metrics.json", arvadostest.ManagementToken, nil, nil)
44 c.Check(resp.Code, Equals, http.StatusOK)
60 json.NewDecoder(resp.Body).Decode(&j)
61 found := make(map[string]bool)
62 names := map[string]bool{}
65 for _, m := range g.Metric {
66 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" {
67 c.Check(m.Summary.SampleCount, Equals, "2")
73 metricsNames := []string{
74 "arvados_keepstore_bufferpool_inuse_buffers",
75 "arvados_keepstore_bufferpool_max_buffers",
76 "arvados_keepstore_bufferpool_allocated_bytes",
77 "arvados_keepstore_pull_queue_inprogress_entries",
78 "arvados_keepstore_pull_queue_pending_entries",
79 "arvados_keepstore_trash_queue_inprogress_entries",
80 "arvados_keepstore_trash_queue_pending_entries",
81 "request_duration_seconds",
83 for _, m := range metricsNames {
85 c.Check(ok, Equals, true, Commentf("checking metric %q", m))