Pull request: querylog bug fix
Merge in DNS/adguard-home from 2324-querylog-bug-fix to master
Closes #2324.
Squashed commit of the following:
commit fdd584a218e1edc3e45ab5b00ceed0a3be681e32
Merge: 8103f9e42 f2eda6d19
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Wed Nov 18 15:35:42 2020 +0300
Merge branch 'master' into 2324-querylog-bug-fix
commit 8103f9e42a398f43682ee30d09b3afdab0e9e177
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Wed Nov 18 14:28:29 2020 +0300
querylog: fix the file ordering bug
commit 2c4e8fcc5b8593be1614480508dfd600fc676e64
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Nov 17 20:57:45 2020 +0300
querylog: wrap errors to clarify error trace
commit 3733062b494817696e4443f153774bb01cea1b06
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Nov 17 18:55:17 2020 +0300
querylog: fix logger output bug
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package querylog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -102,13 +103,14 @@ func (q *QLogFile) Seek(timestamp int64) (int64, int, error) {
|
||||
if err != nil {
|
||||
return 0, depth, err
|
||||
}
|
||||
|
||||
if lineIdx < start || lineEndIdx > end || lineIdx == lastProbeLineIdx {
|
||||
// If we're testing the same line twice then most likely
|
||||
// the scope is too narrow and we won't find anything anymore
|
||||
log.Error("querylog: didn't find timestamp:%v", timestamp)
|
||||
return 0, depth, ErrSeekNotFound
|
||||
// the scope is too narrow and we won't find anything
|
||||
// anymore in any other file.
|
||||
return 0, depth, fmt.Errorf("couldn't find timestamp %v: %w", timestamp, ErrSeekNotFound)
|
||||
} else if lineIdx == end && lineEndIdx == end {
|
||||
// If both line beginning and line ending indices point
|
||||
// at the end of the file, we apparently reached it.
|
||||
return 0, depth, ErrEndOfLog
|
||||
}
|
||||
|
||||
@@ -119,7 +121,7 @@ func (q *QLogFile) Seek(timestamp int64) (int64, int, error) {
|
||||
ts := readQLogTimestamp(line)
|
||||
|
||||
if ts == 0 {
|
||||
return 0, depth, ErrSeekNotFound
|
||||
return 0, depth, fmt.Errorf("couldn't get timestamp: %w", ErrSeekNotFound)
|
||||
}
|
||||
|
||||
if ts == timestamp {
|
||||
@@ -141,8 +143,7 @@ func (q *QLogFile) Seek(timestamp int64) (int64, int, error) {
|
||||
|
||||
depth++
|
||||
if depth >= 100 {
|
||||
log.Error("Seek depth is too high, aborting. File %s, ts %v", q.file.Name(), timestamp)
|
||||
return 0, depth, ErrSeekNotFound
|
||||
return 0, depth, fmt.Errorf("seek depth is too high, aborting. File %s, timestamp %v: %w", q.file.Name(), timestamp, ErrSeekNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user