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

Function TestCountOverTime

pkg/traceql/engine_metrics_test.go:911–958  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

909}
910
911func TestCountOverTime(t *testing.T) {
912 req := &tempopb.QueryRangeRequest{
913 Start: 1,
914 End: uint64(3 * time.Second),
915 Step: uint64(1 * time.Second),
916 Query: "{ } | count_over_time() by (span.foo)",
917 }
918
919 // A variety of spans across times, durations, and series. All durations are powers of 2 for simplicity
920 in := []Span{
921 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(128),
922 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
923 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(512),
924
925 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
926 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
927 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
928 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
929
930 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
931 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
932 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
933 }
934
935 // Output series with quantiles per foo
936 // Prom labels are sorted alphabetically, traceql labels maintain original order.
937 out := []TimeSeries{
938 {
939 Labels: []Label{
940 {Name: "span.foo", Value: NewStaticString("baz")},
941 },
942 Values: []float64{0, 0, 3},
943 Exemplars: make([]Exemplar, 0),
944 },
945 {
946 Labels: []Label{
947 {Name: "span.foo", Value: NewStaticString("bar")},
948 },
949 Values: []float64{3, 4, 0},
950 Exemplars: make([]Exemplar, 0),
951 },
952 }
953
954 result, seriesCount, err := runTraceQLMetric(req, in)
955 require.NoError(t, err)
956 require.Equal(t, len(result), seriesCount)
957 requireEqualSeriesSets(t, out, result)
958}
959
960func TestCountOverTimeInstantNs(t *testing.T) {
961 // not rounded values to simulate real world data

Callers

nothing calls this directly

Calls 8

newMockSpanFunction · 0.85
NewStaticStringFunction · 0.85
runTraceQLMetricFunction · 0.85
requireEqualSeriesSetsFunction · 0.85
WithDurationMethod · 0.80
WithSpanStringMethod · 0.80
WithStartTimeMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected