From c391b6ca43869ed588afc19ac28a788e034eaed5 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Tue, 25 Feb 2020 12:12:03 +0100 Subject: [PATCH] Use a cryptographically random generator for ULID Signed-off-by: Marco Pracucci --- tsdb/compact.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tsdb/compact.go b/tsdb/compact.go index 61fe549f9..70aa9eee0 100644 --- a/tsdb/compact.go +++ b/tsdb/compact.go @@ -15,10 +15,10 @@ package tsdb import ( "context" + "crypto/rand" "fmt" "io" "math" - "math/rand" "os" "path/filepath" "sort" @@ -413,8 +413,7 @@ func (c *LeveledCompactor) Compact(dest string, dirs []string, open []*Block) (u uids = append(uids, meta.ULID.String()) } - entropy := rand.New(rand.NewSource(time.Now().UnixNano())) - uid = ulid.MustNew(ulid.Now(), entropy) + uid = ulid.MustNew(ulid.Now(), rand.Reader) meta := compactBlockMetas(uid, metas...) err = c.write(dest, meta, blocks...) @@ -468,8 +467,7 @@ func (c *LeveledCompactor) Compact(dest string, dirs []string, open []*Block) (u func (c *LeveledCompactor) Write(dest string, b BlockReader, mint, maxt int64, parent *BlockMeta) (ulid.ULID, error) { start := time.Now() - entropy := rand.New(rand.NewSource(time.Now().UnixNano())) - uid := ulid.MustNew(ulid.Now(), entropy) + uid := ulid.MustNew(ulid.Now(), rand.Reader) meta := &BlockMeta{ ULID: uid,