Skip to content

Commit

Permalink
fix: use nanosecond precision for timestamp in compacted tsdb index f…
Browse files Browse the repository at this point in the history
…ile names (#12502)
  • Loading branch information
sandeepsukhani authored Apr 8, 2024
1 parent 6700413 commit be501c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/storage/stores/shipper/indexshipper/tsdb/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (i SingleTenantTSDBIdentifier) Hash(h hash.Hash32) (err error) {
func (i SingleTenantTSDBIdentifier) str() string {
return fmt.Sprintf(
"%d-%s-%d-%d-%x.tsdb",
i.TS.Unix(),
i.TS.UnixNano(),
compactedFileUploader,
i.From,
i.Through,
Expand Down Expand Up @@ -109,7 +109,7 @@ func ParseSingleTenantTSDBPath(p string) (id SingleTenantTSDBIdentifier, ok bool
return
}

ts, err := strconv.Atoi(elems[0])
ts, err := strconv.ParseInt(elems[0], 10, 64)
if err != nil {
return
}
Expand All @@ -133,8 +133,14 @@ func ParseSingleTenantTSDBPath(p string) (id SingleTenantTSDBIdentifier, ok bool
return
}

var parsedTS time.Time
if len(elems[0]) <= 10 {
parsedTS = time.Unix(ts, 0)
} else {
parsedTS = time.Unix(0, ts)
}
return SingleTenantTSDBIdentifier{
TS: time.Unix(int64(ts), 0),
TS: parsedTS,
From: model.Time(from),
Through: model.Time(through),
Checksum: uint32(checksum),
Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/stores/shipper/indexshipper/tsdb/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ func TestParseSingleTenantTSDBPath(t *testing.T) {
},
ok: true,
},
{
desc: "simple_works_with_nanosecond",
input: "1712534400000000000-compactor-1-10-ff.tsdb",
id: SingleTenantTSDBIdentifier{
TS: time.Unix(0, 1712534400000000000),
From: 1,
Through: 10,
Checksum: 255,
},
ok: true,
},
{
desc: "uint32_max_checksum_works",
input: fmt.Sprintf("1-compactor-1-10-%x.tsdb", math.MaxUint32),
Expand Down

0 comments on commit be501c2

Please sign in to comment.