Make head block ULIDs descriptive (#13100)

* Make head block ULIDs descriptive

As far as I understand, these ULIDs aren't persisted anywhere, so it
should be safe to change them.

When debugging an issue, seeing an ULID like
`2ZBXFNYVVFDXFPGSB1CHFNYQTZ` or `33DXR7JA39CHDKMQ9C40H6YVVF` isn't very
helpful, so I propose to make them readable in their ULID string
version.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

* Set a different ULID for RangeHead

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

---------

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
This commit is contained in:
Oleg Zaytsev 2023-11-17 12:29:36 +01:00 committed by GitHub
parent 1b84c01b76
commit f997c72f29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View file

@ -1407,11 +1407,13 @@ func (h *RangeHead) NumSeries() uint64 {
return h.head.NumSeries() return h.head.NumSeries()
} }
var rangeHeadULID = ulid.MustParse("0000000000XXXXXXXRANGEHEAD")
func (h *RangeHead) Meta() BlockMeta { func (h *RangeHead) Meta() BlockMeta {
return BlockMeta{ return BlockMeta{
MinTime: h.MinTime(), MinTime: h.MinTime(),
MaxTime: h.MaxTime(), MaxTime: h.MaxTime(),
ULID: h.head.Meta().ULID, ULID: rangeHeadULID,
Stats: BlockStats{ Stats: BlockStats{
NumSeries: h.NumSeries(), NumSeries: h.NumSeries(),
}, },
@ -1537,15 +1539,15 @@ func (h *Head) NumSeries() uint64 {
return h.numSeries.Load() return h.numSeries.Load()
} }
var headULID = ulid.MustParse("0000000000XXXXXXXXXXXXHEAD")
// Meta returns meta information about the head. // Meta returns meta information about the head.
// The head is dynamic so will return dynamic results. // The head is dynamic so will return dynamic results.
func (h *Head) Meta() BlockMeta { func (h *Head) Meta() BlockMeta {
var id [16]byte
copy(id[:], "______head______")
return BlockMeta{ return BlockMeta{
MinTime: h.MinTime(), MinTime: h.MinTime(),
MaxTime: h.MaxTime(), MaxTime: h.MaxTime(),
ULID: ulid.ULID(id), ULID: headULID,
Stats: BlockStats{ Stats: BlockStats{
NumSeries: h.NumSeries(), NumSeries: h.NumSeries(),
}, },

View file

@ -17,6 +17,8 @@ import (
"fmt" "fmt"
"sort" "sort"
"github.com/oklog/ulid"
"github.com/prometheus/prometheus/tsdb/chunkenc" "github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/tsdb/tombstones" "github.com/prometheus/prometheus/tsdb/tombstones"
) )
@ -135,13 +137,13 @@ func (oh *OOORangeHead) Tombstones() (tombstones.Reader, error) {
return tombstones.NewMemTombstones(), nil return tombstones.NewMemTombstones(), nil
} }
var oooRangeHeadULID = ulid.MustParse("0000000000XXXX000RANGEHEAD")
func (oh *OOORangeHead) Meta() BlockMeta { func (oh *OOORangeHead) Meta() BlockMeta {
var id [16]byte
copy(id[:], "____ooo_head____")
return BlockMeta{ return BlockMeta{
MinTime: oh.mint, MinTime: oh.mint,
MaxTime: oh.maxt, MaxTime: oh.maxt,
ULID: id, ULID: oooRangeHeadULID,
Stats: BlockStats{ Stats: BlockStats{
NumSeries: oh.head.NumSeries(), NumSeries: oh.head.NumSeries(),
}, },

View file

@ -18,6 +18,7 @@ import (
"errors" "errors"
"math" "math"
"github.com/oklog/ulid"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
@ -371,13 +372,13 @@ func (ch *OOOCompactionHead) Tombstones() (tombstones.Reader, error) {
return tombstones.NewMemTombstones(), nil return tombstones.NewMemTombstones(), nil
} }
var oooCompactionHeadULID = ulid.MustParse("0000000000XX000COMPACTHEAD")
func (ch *OOOCompactionHead) Meta() BlockMeta { func (ch *OOOCompactionHead) Meta() BlockMeta {
var id [16]byte
copy(id[:], "copy(id[:], \"ooo_compact_head\")")
return BlockMeta{ return BlockMeta{
MinTime: ch.mint, MinTime: ch.mint,
MaxTime: ch.maxt, MaxTime: ch.maxt,
ULID: id, ULID: oooCompactionHeadULID,
Stats: BlockStats{ Stats: BlockStats{
NumSeries: uint64(len(ch.postings)), NumSeries: uint64(len(ch.postings)),
}, },