Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search block headers #943

Merged
merged 9 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/ingester/instance_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/grafana/tempo/pkg/tempopb"
"github.com/grafana/tempo/pkg/util"
"github.com/grafana/tempo/pkg/util/test"
"github.com/grafana/tempo/tempodb/search"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -357,7 +358,8 @@ func TestInstanceSearchMetrics(t *testing.T) {

search := func() *tempopb.SearchMetrics {
sr, err := i.Search(context.Background(), &tempopb.SearchRequest{
Tags: map[string]string{"nomatch": "nomatch"},
// Exhaustive search
Tags: map[string]string{search.SecretExhaustiveSearchTag: "!"},
})
require.NoError(t, err)
return sr.Metrics
Expand Down
97 changes: 97 additions & 0 deletions pkg/tempofb/SearchBlockHeader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions pkg/tempofb/SearchBlockHeader_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package tempofb

import flatbuffers "github.com/google/flatbuffers/go"

type SearchBlockHeaderBuilder struct {
Tags SearchDataMap
MinDur uint64
MaxDur uint64
}

func NewSearchBlockHeaderBuilder() *SearchBlockHeaderBuilder {
return &SearchBlockHeaderBuilder{
Tags: SearchDataMap{},
}
}

func (s *SearchBlockHeaderBuilder) AddEntry(e *SearchEntry) {

kv := &KeyValues{} //buffer

// Record all unique keyvalues
for i, ii := 0, e.TagsLength(); i < ii; i++ {
e.Tags(kv, i)
for j, jj := 0, kv.ValueLength(); j < jj; j++ {
s.AddTag(string(kv.Key()), string(kv.Value(j)))
}
}

// Record min/max durations
dur := e.EndTimeUnixNano() - e.StartTimeUnixNano()
if s.MinDur == 0 || dur < s.MinDur {
s.MinDur = dur
}
if dur > s.MaxDur {
s.MaxDur = dur
}
}

// AddTag adds the unique tag name and value to the search data. No effect if the pair is already present.
func (s *SearchBlockHeaderBuilder) AddTag(k string, v string) {
s.Tags.Add(k, v)
}

func (s *SearchBlockHeaderBuilder) ToBytes() []byte {
b := flatbuffers.NewBuilder(1024)

tags := s.Tags.WriteToBuilder(b)

SearchBlockHeaderStart(b)
SearchBlockHeaderAddMinDurationNanos(b, s.MinDur)
SearchBlockHeaderAddMaxDurationNanos(b, s.MaxDur)
SearchBlockHeaderAddTags(b, tags)
offset := SearchBlockHeaderEnd(b)
b.Finish(offset)
return b.FinishedBytes()
}
12 changes: 12 additions & 0 deletions pkg/tempofb/tempo.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ table SearchPage {

// Trace entries
entries : [SearchEntry];
}

table SearchBlockHeader {
// This is a rollup of all distinct tags/values in the
// block for quick elimination.
tags : [KeyValues];

// Smallest trace duration in the block
min_duration_nanos: uint64;

// Largest trace duration in the block
max_duration_nanos: uint64;
}
Loading