MCPcopy
hub / github.com/grafana/tempo / TestWriteMetrics

Function TestWriteMetrics

integration/operations/operational_metrics_test.go:18–69  ·  integration/operations/operational_metrics_test.go::TestWriteMetrics
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestWriteMetrics(t *testing.T) {
19 util.RunIntegrationTests(t, util.TestHarnessConfig{
20 Components: util.ComponentsRecentDataQuerying | util.ComponentsBackendQuerying,
21 }, func(h *util.TempoHarness) {
22 h.WaitTracesWritable(t)
23
24 countTraces := 10
25 countSpans := 3 * 3 * countTraces // batches * spans per batch * traces
26 countBytes := 0
27
28 for range countTraces {
29 trace := test.MakeTraceWithSpanCount(3, 3, test.ValidTraceID(nil))
30 countBytes += trace.Size()
31
32 require.NoError(t, h.WriteTempoProtoTraces(trace, ""))
33 }
34
35 h.WaitTracesQueryable(t, countTraces)
36
37 // distributor
38 distributor := h.Services[util.ServiceDistributor]
39 assertMetricEquals(t, distributor, "tempo_distributor_produce_batches_total", float64(countTraces), nil)
40 assertMetricEquals(t, distributor, "tempo_distributor_spans_received_total", float64(countSpans), nil)
41
42 sums, err := distributor.SumMetrics([]string{"tempo_distributor_bytes_received_total"})
43 require.NoError(t, err)
44 actualBytes := sums[0]
45 assertMetricInDelta(t, distributor, "tempo_distributor_bytes_received_total", float64(countBytes), .1*float64(countBytes), nil)
46 assertMetricInDelta(t, distributor, "tempo_distributor_ingress_bytes_total", float64(countBytes), .1*float64(countBytes), nil)
47
48 // livestore
49 livestore := h.Services[util.ServiceLiveStoreZoneA]
50 assertMetricInDelta(t, livestore, "tempo_live_store_bytes_received_total", float64(countBytes), actualBytes, nil)
51 assertMetricEquals(t, livestore, "tempo_live_store_partition_owned", float64(1), nil)
52
53 // we may not have yet completed a block so wait for this one
54 err = livestore.WaitSumMetricsWithOptions(e2e.Greater(0),
55 []string{"tempo_live_store_blocks_completed_total"},
56 e2e.WaitMissingMetrics,
57 )
58 require.NoError(t, err)
59
60 h.WaitTracesWrittenToBackend(t, countTraces)
61
62 // blockbuilder
63 blockbuilder := h.Services[util.ServiceBlockBuilder]
64 assertMetricEquals(t, blockbuilder, "tempo_block_builder_flushed_blocks", float64(1), nil)
65 assertMetricEquals(t, blockbuilder, "tempo_block_builder_owned_partitions", float64(1), nil)
66 assertMetricGreater(t, blockbuilder, "tempo_block_builder_fetch_records_total", float64(0), nil)
67 assertMetricGreater(t, blockbuilder, "tempo_block_builder_fetch_bytes_total", float64(0), nil)
68 })
69}
70
71func TestReadMetrics(t *testing.T) {
72 util.RunIntegrationTests(t, util.TestHarnessConfig{}, func(h *util.TempoHarness) {

Callers

nothing calls this directly

Calls 10

MakeTraceWithSpanCountFunction · 0.92
ValidTraceIDFunction · 0.92
assertMetricEqualsFunction · 0.85
assertMetricInDeltaFunction · 0.85
assertMetricGreaterFunction · 0.85
WaitTracesWritableMethod · 0.80
WriteTempoProtoTracesMethod · 0.80
WaitTracesQueryableMethod · 0.80
SizeMethod · 0.65

Tested by

no test coverage detected