Skip to content

Commit

Permalink
feat(blooms): Only write key and key=value to blooms (#14686)
Browse files Browse the repository at this point in the history
  • Loading branch information
salvacorts authored Oct 31, 2024
1 parent 061bdfe commit 3af0004
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/sources/operations/bloom-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ If there are new TSDB files or any of them have changed, the planner will create
The builder pulls a task from the planner's queue and processes the containing streams and chunks.
For a given stream, the builder will iterate through all the log lines inside its new chunks and build a bloom for the stream.
In case of changes for a previously processed TSDB file, builders will try to reuse blooms from existing blocks instead of building new ones from scratch.
The builder converts structured metadata from each log line of each chunk of a stream and appends the hash of each key, value, and key-value pair to the bloom, followed by the hashes combined with the chunk identifier.
The builder converts structured metadata from each log line of each chunk of a stream and appends the hash of each key, and key-value pair to the bloom, followed by the hashes combined with the chunk identifier.
The first set of hashes allows gateways to skip whole streams, while the latter is for skipping individual chunks.

For example, given structured metadata `foo=bar` in the chunk `c6dj8g`, we append to the stream bloom the following hashes: `hash("foo")`, `hash("bar")`, `hash("foo=bar")`, `hash("c6dj8g" + "foo")` ... `hash("c6dj8g" + "foo=bar")`.
For example, given structured metadata `foo=bar` in the chunk `c6dj8g`, we append to the stream bloom the following hashes: `hash("foo")`, `hash("foo=bar")`, `hash("c6dj8g" + "foo")` and `hash("c6dj8g" + "foo=bar")`.

## Query sharding

Expand Down
1 change: 0 additions & 1 deletion pkg/storage/bloom/v1/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (t *StructuredMetadataTokenizer) Tokens(kv push.LabelAdapter) iter.Iterator
combined := fmt.Sprintf("%s=%s", kv.Name, kv.Value)
t.tokens = append(t.tokens[:0],
kv.Name, t.prefix+kv.Name,
kv.Value, t.prefix+kv.Value,
combined, t.prefix+combined,
)
return iter.NewSliceIter(t.tokens)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/bloom/v1/tokenizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestStructuredMetadataTokenizer(t *testing.T) {
tokenizer := NewStructuredMetadataTokenizer("chunk")

metadata := push.LabelAdapter{Name: "pod", Value: "loki-1"}
expected := []string{"pod", "chunkpod", "loki-1", "chunkloki-1", "pod=loki-1", "chunkpod=loki-1"}
expected := []string{"pod", "chunkpod", "pod=loki-1", "chunkpod=loki-1"}

tokenIter := tokenizer.Tokens(metadata)
got, err := v2.Collect(tokenIter)
Expand Down

0 comments on commit 3af0004

Please sign in to comment.