2020-02-18 13:02:59 +03:00
|
|
|
package querylog
|
|
|
|
|
|
|
|
import (
|
2020-11-18 15:43:28 +03:00
|
|
|
"fmt"
|
2020-02-18 13:02:59 +03:00
|
|
|
"io"
|
|
|
|
"os"
|
2021-04-12 18:22:11 +03:00
|
|
|
"strings"
|
2020-02-18 13:02:59 +03:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2021-05-24 17:28:11 +03:00
|
|
|
"github.com/AdguardTeam/golibs/errors"
|
2020-02-20 19:38:11 +03:00
|
|
|
"github.com/AdguardTeam/golibs/log"
|
2020-02-18 13:02:59 +03:00
|
|
|
)
|
|
|
|
|
2020-11-19 12:53:31 +03:00
|
|
|
const (
|
2023-05-24 16:33:15 +03:00
|
|
|
// Timestamp not found errors.
|
|
|
|
errTSNotFound errors.Error = "ts not found"
|
|
|
|
errTSTooLate errors.Error = "ts too late"
|
|
|
|
errTSTooEarly errors.Error = "ts too early"
|
|
|
|
|
|
|
|
// maxEntrySize is a maximum size of the entry.
|
|
|
|
//
|
|
|
|
// TODO: Find a way to grow buffer instead of relying on this value when
|
|
|
|
// reading strings.
|
|
|
|
maxEntrySize = 16 * 1024
|
|
|
|
|
|
|
|
// bufferSize should be enough for at least this number of entries.
|
|
|
|
bufferSize = 100 * maxEntrySize
|
2020-11-19 12:53:31 +03:00
|
|
|
)
|
2020-02-18 13:02:59 +03:00
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// qLogFile represents a single query log file. It allows reading from the
|
|
|
|
// file in the reverse order.
|
|
|
|
//
|
|
|
|
// Please note, that this is a stateful object. Internally, it contains a
|
|
|
|
// pointer to a specific position in the file, and it reads lines in reverse
|
|
|
|
// order starting from that position.
|
|
|
|
type qLogFile struct {
|
|
|
|
// file is the query log file.
|
|
|
|
file *os.File
|
2020-02-21 16:50:20 +03:00
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// buffer that we've read from the file.
|
|
|
|
buffer []byte
|
2020-02-18 13:02:59 +03:00
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// lock is a mutex to make it thread-safe.
|
|
|
|
lock sync.Mutex
|
|
|
|
|
|
|
|
// position is the position in the file.
|
|
|
|
position int64
|
|
|
|
|
|
|
|
// bufferStart is the start of the buffer (in the file).
|
|
|
|
bufferStart int64
|
|
|
|
|
|
|
|
// bufferLen is the length of the buffer.
|
|
|
|
bufferLen int
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// newQLogFile initializes a new instance of the qLogFile.
|
|
|
|
func newQLogFile(path string) (qf *qLogFile, err error) {
|
2020-11-10 19:00:55 +03:00
|
|
|
f, err := os.OpenFile(path, os.O_RDONLY, 0o644)
|
2020-02-18 13:02:59 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
return &qLogFile{file: f}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// validateQLogLineIdx returns error if the line index is not valid to continue
|
|
|
|
// search.
|
|
|
|
func (q *qLogFile) validateQLogLineIdx(lineIdx, lastProbeLineIdx, ts, fSize int64) (err error) {
|
|
|
|
if lineIdx == lastProbeLineIdx {
|
|
|
|
if lineIdx == 0 {
|
|
|
|
return errTSTooEarly
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're testing the same line twice then most likely the scope is
|
|
|
|
// too narrow and we won't find anything anymore in any other file.
|
|
|
|
return fmt.Errorf("looking up timestamp %d in %q: %w", ts, q.file.Name(), errTSNotFound)
|
|
|
|
} else if lineIdx == fSize {
|
|
|
|
return errTSTooLate
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2021-12-13 13:55:41 +03:00
|
|
|
// seekTS performs binary search in the query log file looking for a record
|
2023-05-24 16:33:15 +03:00
|
|
|
// with the specified timestamp. Once the record is found, it sets "position"
|
|
|
|
// so that the next ReadNext call returned that record.
|
2020-02-18 13:02:59 +03:00
|
|
|
//
|
|
|
|
// The algorithm is rather simple:
|
2023-05-24 16:33:15 +03:00
|
|
|
// 1. It starts with the position in the middle of a file.
|
|
|
|
// 2. Shifts back to the beginning of the line.
|
|
|
|
// 3. Checks the log record timestamp.
|
|
|
|
// 4. If it is lower than the timestamp we are looking for, it shifts seek
|
|
|
|
// position to 3/4 of the file. Otherwise, to 1/4 of the file.
|
|
|
|
// 5. It performs the search again, every time the search scope is narrowed
|
|
|
|
// twice.
|
2020-02-18 13:02:59 +03:00
|
|
|
//
|
2020-02-21 12:57:12 +03:00
|
|
|
// Returns:
|
2023-05-24 16:33:15 +03:00
|
|
|
// - It returns the position of the line with the timestamp we were looking
|
|
|
|
// for so that when we call "ReadNext" this line was returned.
|
|
|
|
// - Depth of the search (how many times we compared timestamps).
|
|
|
|
// - If we could not find it, it returns one of the errors described above.
|
|
|
|
func (q *qLogFile) seekTS(timestamp int64) (pos int64, depth int, err error) {
|
2020-02-18 13:02:59 +03:00
|
|
|
q.lock.Lock()
|
|
|
|
defer q.lock.Unlock()
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Empty the buffer.
|
2020-02-20 19:38:11 +03:00
|
|
|
q.buffer = nil
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// First of all, check the file size.
|
2020-02-18 13:02:59 +03:00
|
|
|
fileInfo, err := q.file.Stat()
|
|
|
|
if err != nil {
|
2020-02-21 12:57:12 +03:00
|
|
|
return 0, 0, err
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Define the search scope.
|
|
|
|
|
|
|
|
// Start of the search interval (position in the file).
|
|
|
|
start := int64(0)
|
|
|
|
// End of the search interval (position in the file).
|
|
|
|
end := fileInfo.Size()
|
|
|
|
// Probe is the approximate index of the line we'll try to check.
|
|
|
|
probe := (end - start) / 2
|
|
|
|
|
2020-02-20 19:38:11 +03:00
|
|
|
var line string
|
2023-05-24 16:33:15 +03:00
|
|
|
// Index of the probe line in the file.
|
|
|
|
var lineIdx int64
|
2020-09-02 19:42:26 +03:00
|
|
|
var lineEndIdx int64
|
2023-05-24 16:33:15 +03:00
|
|
|
// Index of the last probe line.
|
|
|
|
var lastProbeLineIdx int64
|
2020-09-02 19:42:26 +03:00
|
|
|
lastProbeLineIdx = -1
|
2020-02-20 19:38:11 +03:00
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Count seek depth in order to detect mistakes. If depth is too large,
|
|
|
|
// we should stop the search.
|
2020-02-20 19:38:11 +03:00
|
|
|
for {
|
2023-05-24 16:33:15 +03:00
|
|
|
// Get the line at the specified position.
|
2020-09-02 19:42:26 +03:00
|
|
|
line, lineIdx, lineEndIdx, err = q.readProbeLine(probe)
|
2020-02-20 19:38:11 +03:00
|
|
|
if err != nil {
|
2020-02-21 12:57:12 +03:00
|
|
|
return 0, depth, err
|
2020-02-20 19:38:11 +03:00
|
|
|
}
|
2020-11-19 12:53:31 +03:00
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Check if the line index if invalid.
|
|
|
|
err = q.validateQLogLineIdx(lineIdx, lastProbeLineIdx, timestamp, fileInfo.Size())
|
|
|
|
if err != nil {
|
|
|
|
return 0, depth, err
|
2020-09-02 19:42:26 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Save the last found idx.
|
2020-09-02 19:42:26 +03:00
|
|
|
lastProbeLineIdx = lineIdx
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Get the timestamp from the query log record.
|
2020-02-20 21:12:51 +03:00
|
|
|
ts := readQLogTimestamp(line)
|
2020-02-20 19:38:11 +03:00
|
|
|
if ts == 0 {
|
2023-05-24 16:33:15 +03:00
|
|
|
return 0, depth, fmt.Errorf(
|
|
|
|
"looking up timestamp %d in %q: record %q has empty timestamp",
|
|
|
|
timestamp,
|
|
|
|
q.file.Name(),
|
|
|
|
line,
|
|
|
|
)
|
2020-02-20 19:38:11 +03:00
|
|
|
}
|
2020-02-18 13:02:59 +03:00
|
|
|
|
2020-02-20 19:38:11 +03:00
|
|
|
if ts == timestamp {
|
2023-05-24 16:33:15 +03:00
|
|
|
// Hurray, returning the result.
|
2020-02-20 19:38:11 +03:00
|
|
|
break
|
|
|
|
}
|
2020-02-18 13:02:59 +03:00
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Narrow the scope and repeat the search.
|
2020-02-20 19:38:11 +03:00
|
|
|
if ts > timestamp {
|
2023-05-24 16:33:15 +03:00
|
|
|
// If the timestamp we're looking for is OLDER than what we found,
|
|
|
|
// then the line is somewhere on the LEFT side from the current
|
|
|
|
// probe position.
|
2020-09-02 19:42:26 +03:00
|
|
|
end = lineIdx
|
2020-02-20 19:38:11 +03:00
|
|
|
} else {
|
2023-05-24 16:33:15 +03:00
|
|
|
// If the timestamp we're looking for is NEWER than what we found,
|
|
|
|
// then the line is somewhere on the RIGHT side from the current
|
|
|
|
// probe position.
|
2020-09-02 19:42:26 +03:00
|
|
|
start = lineEndIdx
|
2020-02-20 19:38:11 +03:00
|
|
|
}
|
2020-09-02 19:42:26 +03:00
|
|
|
probe = start + (end-start)/2
|
2020-02-18 13:02:59 +03:00
|
|
|
|
2020-02-20 19:38:11 +03:00
|
|
|
depth++
|
|
|
|
if depth >= 100 {
|
2023-05-24 16:33:15 +03:00
|
|
|
return 0, depth, fmt.Errorf(
|
|
|
|
"looking up timestamp %d in %q: depth %d too high: %w",
|
|
|
|
timestamp,
|
|
|
|
q.file.Name(),
|
|
|
|
depth,
|
|
|
|
errTSNotFound,
|
|
|
|
)
|
2020-02-20 19:38:11 +03:00
|
|
|
}
|
|
|
|
}
|
2020-02-18 13:02:59 +03:00
|
|
|
|
2020-02-20 19:38:11 +03:00
|
|
|
q.position = lineIdx + int64(len(line))
|
2020-02-21 12:57:12 +03:00
|
|
|
return q.position, depth, nil
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// SeekStart changes the current position to the end of the file. Please note,
|
|
|
|
// that we're reading query log in the reverse order and that's why log start
|
|
|
|
// is actually the end of file.
|
2020-02-20 21:12:51 +03:00
|
|
|
//
|
2023-05-24 16:33:15 +03:00
|
|
|
// Returns nil if we were able to change the current position. Returns error
|
|
|
|
// in any other case.
|
|
|
|
func (q *qLogFile) SeekStart() (int64, error) {
|
2020-02-18 13:02:59 +03:00
|
|
|
q.lock.Lock()
|
|
|
|
defer q.lock.Unlock()
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Empty the buffer.
|
2020-02-20 19:38:11 +03:00
|
|
|
q.buffer = nil
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// First of all, check the file size.
|
2020-02-18 13:02:59 +03:00
|
|
|
fileInfo, err := q.file.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Place the position to the very end of file.
|
2020-02-18 13:02:59 +03:00
|
|
|
q.position = fileInfo.Size() - 1
|
|
|
|
if q.position < 0 {
|
|
|
|
q.position = 0
|
|
|
|
}
|
2023-05-24 16:33:15 +03:00
|
|
|
|
2020-02-18 13:02:59 +03:00
|
|
|
return q.position, nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// ReadNext reads the next line (in the reverse order) from the file and shifts
|
|
|
|
// the current position left to the next (actually prev) line.
|
|
|
|
//
|
|
|
|
// Returns io.EOF if there's nothing more to read.
|
|
|
|
func (q *qLogFile) ReadNext() (string, error) {
|
2020-02-18 13:02:59 +03:00
|
|
|
q.lock.Lock()
|
|
|
|
defer q.lock.Unlock()
|
|
|
|
|
|
|
|
if q.position == 0 {
|
|
|
|
return "", io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
line, lineIdx, err := q.readNextLine(q.position)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Shift position.
|
2020-02-18 13:02:59 +03:00
|
|
|
if lineIdx == 0 {
|
|
|
|
q.position = 0
|
|
|
|
} else {
|
2023-05-24 16:33:15 +03:00
|
|
|
// There's usually a line break before the line, so we should shift one
|
|
|
|
// more char left from the line "\nline".
|
2020-02-18 13:02:59 +03:00
|
|
|
q.position = lineIdx - 1
|
|
|
|
}
|
|
|
|
return line, err
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Close frees the underlying resources.
|
|
|
|
func (q *qLogFile) Close() error {
|
2020-02-18 13:02:59 +03:00
|
|
|
return q.file.Close()
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// readNextLine reads the next line from the specified position. This line
|
|
|
|
// actually have to END on that position.
|
2020-02-18 13:02:59 +03:00
|
|
|
//
|
2023-05-24 16:33:15 +03:00
|
|
|
// The algorithm is:
|
|
|
|
// 1. Check if we have the buffer initialized.
|
|
|
|
// 2. If it is so, scan it and look for the line there.
|
|
|
|
// 3. If we cannot find the line there, read the prev chunk into the buffer.
|
|
|
|
// 4. Read the line from the buffer.
|
|
|
|
func (q *qLogFile) readNextLine(position int64) (string, int64, error) {
|
2020-02-18 13:02:59 +03:00
|
|
|
relativePos := position - q.bufferStart
|
2020-02-20 19:38:11 +03:00
|
|
|
if q.buffer == nil || (relativePos < maxEntrySize && q.bufferStart != 0) {
|
2023-05-24 16:33:15 +03:00
|
|
|
// Time to re-init the buffer.
|
2020-02-18 13:02:59 +03:00
|
|
|
err := q.initBuffer(position)
|
|
|
|
if err != nil {
|
|
|
|
return "", 0, err
|
|
|
|
}
|
2020-02-20 19:38:11 +03:00
|
|
|
relativePos = position - q.bufferStart
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Look for the end of the prev line, this is where we'll read from.
|
2020-11-10 19:00:55 +03:00
|
|
|
startLine := int64(0)
|
2020-02-18 13:02:59 +03:00
|
|
|
for i := relativePos - 1; i >= 0; i-- {
|
|
|
|
if q.buffer[i] == '\n' {
|
|
|
|
startLine = i + 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
line := string(q.buffer[startLine:relativePos])
|
|
|
|
lineIdx := q.bufferStart + startLine
|
2023-05-24 16:33:15 +03:00
|
|
|
|
2020-02-18 13:02:59 +03:00
|
|
|
return line, lineIdx, nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// initBuffer initializes the qLogFile buffer. The goal is to read a chunk of
|
|
|
|
// file that includes the line with the specified position.
|
|
|
|
func (q *qLogFile) initBuffer(position int64) error {
|
2020-02-18 13:02:59 +03:00
|
|
|
q.bufferStart = int64(0)
|
2021-01-27 18:32:13 +03:00
|
|
|
if position > bufferSize {
|
2020-02-18 13:02:59 +03:00
|
|
|
q.bufferStart = position - bufferSize
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Seek to this position.
|
2020-02-18 13:02:59 +03:00
|
|
|
_, err := q.file.Seek(q.bufferStart, io.SeekStart)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.buffer == nil {
|
|
|
|
q.buffer = make([]byte, bufferSize)
|
|
|
|
}
|
2021-01-27 18:32:13 +03:00
|
|
|
|
2020-02-18 13:02:59 +03:00
|
|
|
q.bufferLen, err = q.file.Read(q.buffer)
|
|
|
|
|
2021-01-27 18:32:13 +03:00
|
|
|
return err
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// readProbeLine reads a line that includes the specified position. This
|
|
|
|
// method is supposed to be used when we use binary search in the Seek method.
|
|
|
|
// In the case of consecutive reads, use readNext, cause it uses better buffer.
|
|
|
|
func (q *qLogFile) readProbeLine(position int64) (string, int64, int64, error) {
|
|
|
|
// First of all, we should read a buffer that will include the query log
|
|
|
|
// line. In order to do this, we'll define the boundaries.
|
2020-02-18 13:02:59 +03:00
|
|
|
seekPosition := int64(0)
|
2023-05-24 16:33:15 +03:00
|
|
|
// Position relative to the buffer we're going to read.
|
|
|
|
relativePos := position
|
2021-01-27 18:32:13 +03:00
|
|
|
if position > maxEntrySize {
|
2020-02-18 13:02:59 +03:00
|
|
|
seekPosition = position - maxEntrySize
|
|
|
|
relativePos = maxEntrySize
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Seek to this position.
|
2020-02-18 13:02:59 +03:00
|
|
|
_, err := q.file.Seek(seekPosition, io.SeekStart)
|
|
|
|
if err != nil {
|
2020-09-02 19:42:26 +03:00
|
|
|
return "", 0, 0, err
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// The buffer size is 2*maxEntrySize.
|
2020-02-18 13:02:59 +03:00
|
|
|
buffer := make([]byte, maxEntrySize*2)
|
|
|
|
bufferLen, err := q.file.Read(buffer)
|
|
|
|
if err != nil {
|
2020-09-02 19:42:26 +03:00
|
|
|
return "", 0, 0, err
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Now start looking for the new line character starting from the
|
|
|
|
// relativePos and going left.
|
2020-11-10 19:00:55 +03:00
|
|
|
startLine := int64(0)
|
2020-02-18 13:02:59 +03:00
|
|
|
for i := relativePos - 1; i >= 0; i-- {
|
|
|
|
if buffer[i] == '\n' {
|
|
|
|
startLine = i + 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2023-05-24 16:33:15 +03:00
|
|
|
// Looking for the end of line now.
|
2020-11-10 19:00:55 +03:00
|
|
|
endLine := int64(bufferLen)
|
2020-09-02 19:42:26 +03:00
|
|
|
lineEndIdx := endLine + seekPosition
|
2020-02-18 13:02:59 +03:00
|
|
|
for i := relativePos; i < int64(bufferLen); i++ {
|
|
|
|
if buffer[i] == '\n' {
|
|
|
|
endLine = i
|
2020-09-02 19:42:26 +03:00
|
|
|
lineEndIdx = endLine + seekPosition + 1
|
2020-02-18 13:02:59 +03:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// Finally we can return the string we were looking for.
|
2020-02-18 13:02:59 +03:00
|
|
|
lineIdx := startLine + seekPosition
|
2020-09-02 19:42:26 +03:00
|
|
|
return string(buffer[startLine:endLine]), lineIdx, lineEndIdx, nil
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// readJSONValue reads a JSON string in form of '"key":"value"'. prefix must
|
|
|
|
// be of the form '"key":"' to generate less garbage.
|
2021-04-12 18:22:11 +03:00
|
|
|
func readJSONValue(s, prefix string) string {
|
|
|
|
i := strings.Index(s, prefix)
|
|
|
|
if i == -1 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
start := i + len(prefix)
|
|
|
|
i = strings.IndexByte(s[start:], '"')
|
|
|
|
if i == -1 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
end := start + i
|
|
|
|
return s[start:end]
|
|
|
|
}
|
|
|
|
|
2023-05-24 16:33:15 +03:00
|
|
|
// readQLogTimestamp reads the timestamp field from the query log line.
|
2020-02-21 01:07:30 +03:00
|
|
|
func readQLogTimestamp(str string) int64 {
|
2021-04-12 18:22:11 +03:00
|
|
|
val := readJSONValue(str, `"T":"`)
|
2020-02-18 13:02:59 +03:00
|
|
|
if len(val) == 0 {
|
2021-04-12 18:22:11 +03:00
|
|
|
val = readJSONValue(str, `"Time":"`)
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(val) == 0 {
|
2020-02-20 21:12:51 +03:00
|
|
|
log.Error("Couldn't find timestamp: %s", str)
|
2020-02-18 13:02:59 +03:00
|
|
|
return 0
|
|
|
|
}
|
2023-05-24 16:33:15 +03:00
|
|
|
|
2020-02-20 21:12:51 +03:00
|
|
|
tm, err := time.Parse(time.RFC3339Nano, val)
|
2020-02-18 13:02:59 +03:00
|
|
|
if err != nil {
|
2020-02-20 21:12:51 +03:00
|
|
|
log.Error("Couldn't parse timestamp: %s", val)
|
2020-02-18 13:02:59 +03:00
|
|
|
return 0
|
|
|
|
}
|
2023-05-24 16:33:15 +03:00
|
|
|
|
2020-02-21 01:07:30 +03:00
|
|
|
return tm.UnixNano()
|
2020-02-18 13:02:59 +03:00
|
|
|
}
|