Logging added for when compaction takes more than the block time range (#8151)

* Logging added for when compaction takes more than the block time range

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Log only if no errors were already logged

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Log duration as human readable string

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Move logging from compactHead() to Compact()

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Compute duration of all head compactions plus wal truncation

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Remove named return added os first commits

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Address nits

Signed-off-by: arthursens <arthursens2005@gmail.com>

* Change miliseconds to seconds to make fuzzit tests happy

Signed-off-by: ArthurSens <arthursens2005@gmail.com>
This commit is contained in:
Arthur Silva Sens 2020-12-07 18:29:43 -03:00 committed by GitHub
parent f055690b34
commit 64a106c5dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -805,6 +805,7 @@ func (db *DB) Compact() (returnErr error) {
).Err() ).Err()
}() }()
start := time.Now()
// Check whether we have pending head blocks that are ready to be persisted. // Check whether we have pending head blocks that are ready to be persisted.
// They have the highest priority. // They have the highest priority.
for { for {
@ -839,6 +840,15 @@ func (db *DB) Compact() (returnErr error) {
return errors.Wrap(err, "WAL truncation in Compact") return errors.Wrap(err, "WAL truncation in Compact")
} }
compactionDuration := time.Since(start)
// TODO: change to milliseconds once fuzzit tests are removed
if int64(compactionDuration.Seconds())*1000 > db.head.chunkRange.Load() {
level.Warn(db.logger).Log(
"msg", "Head compaction took longer than the block time range, compactions are falling behind and won't be able to catch up",
"duration", compactionDuration.String(),
"block_range", db.head.chunkRange.Load(),
)
}
return db.compactBlocks() return db.compactBlocks()
} }