(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestCompare(t *testing.T) { |
| 12 | // Test that the compare function correctly multiplies results based on sampling multiplier |
| 13 | // The multiplication happens in result() method: s.Values[i] *= multiplier |
| 14 | |
| 15 | // Instant query |
| 16 | req := &tempopb.QueryRangeRequest{ |
| 17 | Start: 1, |
| 18 | End: uint64(3 * time.Second), |
| 19 | Step: uint64(2 * time.Second), |
| 20 | Query: `{ } | compare({ .service="selected" })`, |
| 21 | } |
| 22 | |
| 23 | // Test data with clear baseline vs selection distinction |
| 24 | spans := []Span{ |
| 25 | // Baseline spans (service != "selected") |
| 26 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("service", "baseline1").WithSpanString("environment", "prod"), |
| 27 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("service", "baseline2").WithSpanString("environment", "dev"), |
| 28 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("service", "baseline1").WithSpanString("environment", "prod"), |
| 29 | |
| 30 | // Selection spans (service == "selected") |
| 31 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "prod"), |
| 32 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "dev"), |
| 33 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "dev"), |
| 34 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "prod"), |
| 35 | } |
| 36 | |
| 37 | ss, _, err := runTraceQLMetric(req, spans) |
| 38 | require.NoError(t, err) |
| 39 | |
| 40 | expected := []TimeSeries{ |
| 41 | // Baseline values |
| 42 | { |
| 43 | Labels: Labels{ |
| 44 | internalLabelTypeBaseline, |
| 45 | Label{Name: "span.service", Value: NewStaticString("baseline1")}, |
| 46 | }, |
| 47 | Values: []float64{2, 0}, |
| 48 | }, |
| 49 | { |
| 50 | Labels: Labels{ |
| 51 | internalLabelTypeBaseline, |
| 52 | Label{Name: "span.service", Value: NewStaticString("baseline2")}, |
| 53 | }, |
| 54 | Values: []float64{1, 0}, |
| 55 | }, |
| 56 | { |
| 57 | Labels: Labels{ |
| 58 | internalLabelTypeBaseline, |
| 59 | Label{Name: "span.environment", Value: NewStaticString("prod")}, |
| 60 | }, |
| 61 | Values: []float64{2, 0}, |
| 62 | }, |
| 63 | { |
| 64 | Labels: Labels{ |
| 65 | internalLabelTypeBaseline, |
| 66 | Label{Name: "span.environment", Value: NewStaticString("dev")}, |
| 67 | }, |
| 68 | Values: []float64{1, 0}, |
nothing calls this directly
no test coverage detected