Documentation ¶
Overview ¶
Package querylog provides query log functions and interfaces.
Index ¶
Constants ¶
const ErrEndOfLog agherr.Error = "seek: end of log"
ErrEndOfLog is returned from Seek when the end of the current log is reached.
const ErrSeekNotFound agherr.Error = "seek: record not found"
ErrSeekNotFound is returned from Seek if when it fails to find the requested record.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddParams ¶
type AddParams struct { Question *dns.Msg Answer *dns.Msg // The response we sent to the client (optional) OrigAnswer *dns.Msg // The response from an upstream server (optional) Result *dnsfilter.Result // Filtering result (optional) Elapsed time.Duration // Time spent for processing the request ClientIP net.IP Upstream string // Upstream server URL ClientProto ClientProto }
AddParams - parameters for Add()
type ClientProto ¶
type ClientProto string
ClientProto values are names of the client protocols.
const ( ClientProtoDOH ClientProto = "doh" ClientProtoDOQ ClientProto = "doq" ClientProtoDOT ClientProto = "dot" ClientProtoPlain ClientProto = "" )
Client protocol names.
func NewClientProto ¶
func NewClientProto(s string) (cp ClientProto, err error)
NewClientProto validates that the client protocol name is valid and returns the name as a ClientProto.
type Config ¶
type Config struct { Enabled bool // enable the module FileEnabled bool // write logs to file BaseDir string // directory where log file is stored Interval uint32 // interval to rotate logs (in days) MemSize uint32 // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool // anonymize clients' IP addresses // Called when the configuration is changed by HTTP request ConfigModified func() // Register an HTTP handler HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request)) }
Config - configuration object
type QLogFile ¶
type QLogFile struct {
// contains filtered or unexported fields
}
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.
func NewQLogFile ¶
NewQLogFile initializes a new instance of the QLogFile
func (*QLogFile) ReadNext ¶
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 to read more
func (*QLogFile) Seek ¶
Seek performs binary search in the query log file looking for a record with the specified timestamp. Once the record is found, it sets "position" so that the next ReadNext call returned that record.
The algorithm is rather simple: 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.
Returns: * It returns the position of the 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 ErrSeekNotFound
type QLogReader ¶
type QLogReader struct {
// contains filtered or unexported fields
}
QLogReader allows reading from multiple query log files in the reverse order.
Please note that this is a stateful object. Internally, it contains a pointer to a particular query log file, and to a specific position in this file, and it reads lines in reverse order starting from that position.
func NewQLogReader ¶
func NewQLogReader(files []string) (*QLogReader, error)
NewQLogReader initializes a QLogReader instance with the specified files
func (*QLogReader) ReadNext ¶
func (r *QLogReader) ReadNext() (string, error)
ReadNext reads the next line (in the reverse order) from the query log files. and shifts the current position left to the next (actually prev) line (or the next file). returns io.EOF if there's nothing to read more.
func (*QLogReader) Seek ¶
func (r *QLogReader) Seek(timestamp int64) error
Seek performs binary search of a query log record with the specified timestamp. If the record is found, it sets QLogReader's position to point to that line, so that the next ReadNext call returned this line.
Returns nil if the record is successfully found. Returns an error if for some reason we could not find a record with the specified timestamp.
func (*QLogReader) SeekStart ¶
func (r *QLogReader) SeekStart() error
SeekStart changes the current position to the end of the newest 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
Returns nil if we were able to change the current position. Returns error in any other case.