MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestWaitSumMetric

Function TestWaitSumMetric

integration/e2e/service_test.go:19–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestWaitSumMetric(t *testing.T) {
20 // Listen on a random port before starting the HTTP server, to
21 // make sure the port is already open when we'll call WaitSumMetric()
22 // the first time (this avoid flaky tests).
23 ln, err := net.Listen("tcp", "localhost:0")
24 require.NoError(t, err)
25 defer ln.Close()
26
27 // Get the port.
28 _, addrPort, err := net.SplitHostPort(ln.Addr().String())
29 require.NoError(t, err)
30
31 port, err := strconv.Atoi(addrPort)
32 require.NoError(t, err)
33
34 // Start an HTTP server exposing the metrics.
35 srv := &http.Server{
36 Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
37 _, _ = w.Write([]byte(`
38# HELP metric_c cheescake
39# TYPE metric_c gauge
40metric_c 20
41# HELP metric_a cheescake
42# TYPE metric_a gauge
43metric_a 1
44metric_a{first="value1"} 10
45metric_a{first="value1", something="x"} 4
46metric_a{first="value1", something2="a"} 203
47metric_a{first="value2"} 2
48metric_a{second="value1"} 1
49# HELP metric_b cheescake
50# TYPE metric_b gauge
51metric_b 1000
52# HELP metric_b_counter cheescake
53# TYPE metric_b_counter counter
54metric_b_counter 1020
55# HELP metric_b_hist cheescake
56# TYPE metric_b_hist histogram
57metric_b_hist_count 5
58metric_b_hist_sum 124
59metric_b_hist_bucket{le="5.36870912e+08"} 1
60metric_b_hist_bucket{le="+Inf"} 5
61# HELP metric_b_summary cheescake
62# TYPE metric_b_summary summary
63metric_b_summary_sum 22
64metric_b_summary_count 1
65`))
66 }),
67 }
68 defer srv.Close()
69
70 go func() {
71 _ = srv.Serve(ln)
72 }()
73
74 s := &HTTPService{
75 httpPort: 0,
76 ConcreteService: &ConcreteService{

Callers

nothing calls this directly

Calls 7

WaitSumMetricsMethod · 0.95
EqualsFunction · 0.85
SetBackoffMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected