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

tsdb creation supports fingerprint overrides #6178

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions pkg/storage/stores/tsdb/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ func (b *Builder) Build(
for _, s := range b.streams {
streams = append(streams, s)
}

// Use the supplied fingerprints instead of hashing labels for two reasons:
// 1) Correctness: fingerprints differ from label hashes because
// we add a synthesized __loki_tennat__ label, which is eventually compacted away.
// 2) Speed: No hashing required
sort.Slice(streams, func(i, j int) bool {
if a, b := streams[i].labels.Hash(), streams[j].labels.Hash(); a != b {
return a < b
if streams[i].fp != streams[j].fp {
return streams[i].fp < streams[j].fp
}
return labels.Compare(streams[i].labels, streams[j].labels) < 0
})
Expand Down
5 changes: 5 additions & 0 deletions pkg/storage/stores/tsdb/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, fp model.F
return err
}

// Put the supplied fingerprint instead of the calculated hash.
// This allows us to have a synthetic label (__loki_tenant__) in
// the pre-compacted TSDBs which map to fingerprints (and chunks)
// without this label in storage.
labelHash := uint64(fp)

lastHash := w.lastSeriesHash
// Ensure series are sorted by the priorities: [`hash(labels)`, `labels`]
if (labelHash < lastHash && len(w.lastSeries) > 0) || labelHash == lastHash && labels.Compare(lset, w.lastSeries) < 0 {
Expand Down