Skip to content

Commit

Permalink
Add search block headers (#943)
Browse files Browse the repository at this point in the history
* Add search block headers

Signed-off-by: Martin Disibio <[email protected]>

* nolint

Signed-off-by: Martin Disibio <[email protected]>

* Fix buffer usage in SearchBlockIterator to prevent data corruption

Signed-off-by: Martin Disibio <[email protected]>

* Reorganize search iterator and combiner

Signed-off-by: Martin Disibio <[email protected]>

* changelog

Signed-off-by: Martin Disibio <[email protected]>

* no nolint

Signed-off-by: Martin Disibio <[email protected]>

* Add skipped blocks metric to response

Signed-off-by: Martin Disibio <[email protected]>
  • Loading branch information
mdisibio authored Sep 15, 2021
1 parent 78d8107 commit 0e7e7aa
Show file tree
Hide file tree
Showing 16 changed files with 529 additions and 186 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [ENHANCEMENT] Implement trace comparison in Vulture [#904](https://github.com/grafana/tempo/pull/904) (@zalegrala)
* [ENHANCEMENT] Dedupe search records while replaying WAL [#940](https://github.com/grafana/tempo/pull/940) (@annanay25)
* [ENHANCEMENT] Add status endpoint to list the available endpoints [#938](https://github.com/grafana/tempo/pull/938) (@zalegrala)
* [ENHANCEMENT] Add search block headers [#943](https://github.com/grafana/tempo/pull/943) (@mdisibio)
* [CHANGE] Renamed CLI flag from `--storage.trace.maintenance-cycle` to `--storage.trace.blocklist_poll`. This is a **breaking change** [#897](https://github.com/grafana/tempo/pull/897) (@mritunjaysharma394)
* [CHANGE] update jsonnet alerts and recording rules to use `job_selectors` and `cluster_selectors` for configurable unique identifier labels [#935](https://github.com/grafana/tempo/pull/935) (@kevinschoonover)
* [CHANGE] Modify generated tag keys in Vulture for easier filtering [#934](https://github.com/grafana/tempo/pull/934) (@zalegrala)
Expand Down
1 change: 1 addition & 0 deletions modules/ingester/instance_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (i *instance) Search(ctx context.Context, req *tempopb.SearchRequest) (*tem
InspectedTraces: sr.TracesInspected(),
InspectedBytes: sr.BytesInspected(),
InspectedBlocks: sr.BlocksInspected(),
SkippedBlocks: sr.BlocksSkipped(),
},
}, nil
}
Expand Down
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
1 change: 1 addition & 0 deletions modules/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func (q *Querier) postProcessSearchResults(req *tempopb.SearchRequest, rr []resp
response.Metrics.InspectedBytes += sr.Metrics.InspectedBytes
response.Metrics.InspectedTraces += sr.Metrics.InspectedTraces
response.Metrics.InspectedBlocks += sr.Metrics.InspectedBlocks
response.Metrics.SkippedBlocks += sr.Metrics.SkippedBlocks
}
}

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

0 comments on commit 0e7e7aa

Please sign in to comment.