(t *testing.T)
| 155 | } |
| 156 | |
| 157 | func TestCompareScalesResults(t *testing.T) { |
| 158 | // Test that the compare function correctly multiplies results based on sampling multiplier |
| 159 | // The multiplication happens in result() method: s.Values[i] *= multiplier |
| 160 | |
| 161 | // Instant query |
| 162 | req := &tempopb.QueryRangeRequest{ |
| 163 | Start: 1, |
| 164 | End: uint64(3 * time.Second), |
| 165 | Step: uint64(2 * time.Second), |
| 166 | Query: `{ } | compare({ .service="selected" })`, |
| 167 | } |
| 168 | |
| 169 | a := newMetricsCompare(newSpansetFilter( |
| 170 | newBinaryOperation(OpEqual, |
| 171 | NewAttribute("service"), |
| 172 | NewStaticString("selected"), |
| 173 | )), 10, 0, 0) |
| 174 | a.init(req, AggregateModeRaw) |
| 175 | |
| 176 | // Test data with clear baseline vs selection distinction |
| 177 | spans := []Span{ |
| 178 | // Baseline spans (service != "selected") |
| 179 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("service", "baseline1").WithSpanString("environment", "prod"), |
| 180 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("service", "baseline2").WithSpanString("environment", "dev"), |
| 181 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("service", "baseline1").WithSpanString("environment", "prod"), |
| 182 | |
| 183 | // Selection spans (service == "selected") |
| 184 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "prod"), |
| 185 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "dev"), |
| 186 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "dev"), |
| 187 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("service", "selected").WithSpanString("environment", "prod"), |
| 188 | } |
| 189 | |
| 190 | for _, span := range spans { |
| 191 | a.observe(span) |
| 192 | } |
| 193 | |
| 194 | // Double all counts |
| 195 | ss := a.result(2.0) |
| 196 | |
| 197 | expected := []TimeSeries{ |
| 198 | // Baseline values |
| 199 | { |
| 200 | Labels: Labels{ |
| 201 | internalLabelTypeBaseline, |
| 202 | Label{Name: "span.service", Value: NewStaticString("baseline1")}, |
| 203 | }, |
| 204 | Values: []float64{4, 0}, |
| 205 | }, |
| 206 | { |
| 207 | Labels: Labels{ |
| 208 | internalLabelTypeBaseline, |
| 209 | Label{Name: "span.service", Value: NewStaticString("baseline2")}, |
| 210 | }, |
| 211 | Values: []float64{2, 0}, |
| 212 | }, |
| 213 | { |
| 214 | Labels: Labels{ |
nothing calls this directly
no test coverage detected