-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend] Two fixes for gRPC query range streaming (#4576)
* Revert "Bugfix: Default step for gRPC streaming query range queries (#4546)" This reverts commit 424274a. * default step if not set Signed-off-by: Joe Elliott <[email protected]> * fix dumping of output to json Signed-off-by: Joe Elliott <[email protected]> * attachExemplars in gRPC diff Signed-off-by: Joe Elliott <[email protected]> * added test and bench Signed-off-by: Joe Elliott <[email protected]> * remove step Signed-off-by: Joe Elliott <[email protected]> * changelog Signed-off-by: Joe Elliott <[email protected]> * fix default step Signed-off-by: Joe Elliott <[email protected]> * lint Signed-off-by: Joe Elliott <[email protected]> * corrected proto import Signed-off-by: Joe Elliott <[email protected]> --------- Signed-off-by: Joe Elliott <[email protected]>
- Loading branch information
1 parent
89b9f7e
commit 9acc16d
Showing
6 changed files
with
139 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package combiner | ||
|
||
import ( | ||
"math" | ||
"math/rand/v2" | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/tempo/pkg/tempopb" | ||
"github.com/grafana/tempo/pkg/traceql" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAttachExemplars(t *testing.T) { | ||
start := uint64(10 * time.Second) | ||
end := uint64(20 * time.Second) | ||
step := traceql.DefaultQueryRangeStep(start, end) | ||
|
||
req := &tempopb.QueryRangeRequest{ | ||
Start: start, | ||
End: end, | ||
Step: step, | ||
} | ||
|
||
tcs := []struct { | ||
name string | ||
include func(i int) bool | ||
}{ | ||
{ | ||
name: "include all", | ||
include: func(_ int) bool { return true }, | ||
}, | ||
{ | ||
name: "include none", | ||
include: func(_ int) bool { return false }, | ||
}, | ||
{ | ||
name: "include every other", | ||
include: func(i int) bool { return i%2 == 0 }, | ||
}, | ||
{ | ||
name: "include rando", | ||
include: func(_ int) bool { return rand.Int()%2 == 0 }, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
resp, expectedSeries := buildSeriesForExemplarTest(start, end, step, tc.include) | ||
|
||
attachExemplars(req, resp) | ||
require.Equal(t, expectedSeries, resp.Series) | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkAttachExemplars(b *testing.B) { | ||
start := uint64(1 * time.Second) | ||
end := uint64(10000 * time.Second) | ||
step := uint64(time.Second) | ||
|
||
req := &tempopb.QueryRangeRequest{ | ||
Start: start, | ||
End: end, | ||
Step: step, | ||
} | ||
|
||
resp, _ := buildSeriesForExemplarTest(start, end, step, func(_ int) bool { return true }) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
attachExemplars(req, resp) | ||
} | ||
} | ||
|
||
func buildSeriesForExemplarTest(start, end, step uint64, include func(i int) bool) (*tempopb.QueryRangeResponse, []*tempopb.TimeSeries) { | ||
resp := &tempopb.QueryRangeResponse{ | ||
Series: []*tempopb.TimeSeries{ | ||
{}, | ||
}, | ||
} | ||
|
||
expectedSeries := []*tempopb.TimeSeries{ | ||
{}, | ||
} | ||
|
||
// populate series and expected series based on step | ||
idx := 0 | ||
for i := start; i < end; i += step { | ||
idx++ | ||
tsMS := int64(i / uint64(time.Millisecond)) | ||
val := float64(idx) | ||
|
||
sample := tempopb.Sample{ | ||
TimestampMs: tsMS, | ||
Value: val, | ||
} | ||
nanExemplar := tempopb.Exemplar{ | ||
TimestampMs: tsMS, | ||
Value: math.NaN(), | ||
} | ||
valExamplar := tempopb.Exemplar{ | ||
TimestampMs: tsMS, | ||
Value: val, | ||
} | ||
|
||
includeExemplar := include(idx) | ||
|
||
// copy the sample and nan exemplar into the response. the nan exemplar should be overwritten | ||
resp.Series[0].Samples = append(resp.Series[0].Samples, sample) | ||
if includeExemplar { | ||
resp.Series[0].Exemplars = append(resp.Series[0].Exemplars, nanExemplar) | ||
} | ||
|
||
// copy the sample and val exemplar into the expected response | ||
expectedSeries[0].Samples = append(expectedSeries[0].Samples, sample) | ||
if includeExemplar { | ||
expectedSeries[0].Exemplars = append(expectedSeries[0].Exemplars, valExamplar) | ||
} | ||
} | ||
|
||
return resp, expectedSeries | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters