MCPcopy
hub / github.com/kopia/kopia / TestMetricsPushFlags

Function TestMetricsPushFlags

cli/observability_flags_test.go:17–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestMetricsPushFlags(t *testing.T) {
18 env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
19
20 mux := http.NewServeMux()
21
22 var (
23 mu sync.Mutex
24 urls []string
25 bodies []string
26 auths []string
27 )
28
29 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
30 mu.Lock()
31 defer mu.Unlock()
32
33 urls = append(urls, r.RequestURI)
34 d, _ := io.ReadAll(r.Body)
35 bodies = append(bodies, r.Method+":"+string(d))
36 u, p, _ := r.BasicAuth()
37
38 auths = append(auths, u+":"+p)
39 })
40
41 tmp1 := testutil.TempDirectory(t)
42
43 server := httptest.NewServer(mux)
44 defer server.Close()
45
46 env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", tmp1,
47 "--metrics-push-addr="+server.URL,
48 "--metrics-push-interval=30s",
49 "--metrics-push-format=text",
50 )
51
52 env.RunAndExpectSuccess(t, "repo", "status",
53 "--metrics-push-addr="+server.URL,
54 "--metrics-push-interval=30s",
55 "--metrics-push-grouping=a:b",
56 "--metrics-push-username=user1",
57 "--metrics-push-password=pass1",
58 "--metrics-push-format=proto-text",
59 )
60
61 require.Equal(t, []string{
62 "/metrics/job/kopia", // initial
63 "/metrics/job/kopia", // final
64 "/metrics/job/kopia/a/b", // initial
65 "/metrics/job/kopia/a/b", // final
66 }, urls)
67
68 require.Equal(t, "user1:pass1", auths[len(auths)-1])
69
70 for _, b := range bodies {
71 // make sure bodies include some kopia metrics, don't need more
72 require.Contains(t, b, "kopia_cache_hit_bytes_total")
73 }
74

Callers

nothing calls this directly

Calls 10

RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
TempDirectoryFunction · 0.92
EqualMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
CloseMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected