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

Function TestSegmentSearchResponse

modules/frontend/combiner/search_test.go:791–859  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

789}
790
791func TestSegmentSearchResponse(t *testing.T) {
792 input := &tempopb.SearchResponse{
793 Metrics: &tempopb.SearchMetrics{},
794 Traces: []*tempopb.TraceSearchMetadata{
795 {
796 TraceID: "a",
797 SpanSet: &tempopb.SpanSet{
798 Spans: []*tempopb.Span{
799 {SpanID: "1", Name: "span1", StartTimeUnixNano: 1000, DurationNanos: 100},
800 {SpanID: "2", Name: "span2", StartTimeUnixNano: 2000, DurationNanos: 200},
801 {SpanID: "3", Name: "span3", StartTimeUnixNano: 3000, DurationNanos: 300},
802 },
803 },
804 },
805 {
806 TraceID: "b",
807 SpanSet: &tempopb.SpanSet{
808 Spans: []*tempopb.Span{
809 {SpanID: "4", Name: "span4", StartTimeUnixNano: 4000, DurationNanos: 400},
810 },
811 },
812 },
813 {
814 TraceID: "c",
815 SpanSet: &tempopb.SpanSet{
816 Spans: []*tempopb.Span{
817 {SpanID: "5", Name: "span5", StartTimeUnixNano: 5000, DurationNanos: 500},
818 },
819 },
820 },
821 },
822 }
823
824 t.Run("fits", func(t *testing.T) {
825 // Generate a test packet size that is large enough for only part of the data.
826 maxSize := (&tempopb.SearchResponse{
827 Metrics: input.Metrics,
828 Traces: input.Traces[:2],
829 }).Size()
830 out := segmentSearchResponse(input, maxSize)
831
832 require.Len(t, out, 2)
833 requireProtoSegmentsFit(t, out, maxSize)
834 require.Len(t, out[0].Traces, 2)
835 require.Len(t, out[1].Traces, 1)
836 require.Equal(t, input.Traces[0], out[0].Traces[0])
837 require.Equal(t, input.Traces[1], out[0].Traces[1])
838 require.Equal(t, input.Traces[2], out[1].Traces[0])
839 require.Equal(t, input.Metrics, out[0].Metrics)
840 require.Equal(t, input.Metrics, out[1].Metrics)
841 })
842
843 t.Run("at least one", func(t *testing.T) {
844 // This is smaller than every item but will test logic to ensure we always send at least one item even if too big
845 const maxSize = 1
846 out := segmentSearchResponse(input, maxSize)
847
848 require.Len(t, out, 3)

Callers

nothing calls this directly

Calls 6

segmentSearchResponseFunction · 0.85
requireProtoSegmentsFitFunction · 0.85
SizeMethod · 0.65
LenMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected