querylog

package
v0.104.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2020 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSeekNotFound = errors.New("Seek not found the record")

ErrSeekNotFound is returned from the Seek method if we failed to find the desired record

Functions

This section is empty.

Types

type AddParams added in v0.100.0

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 string // Protocol for the client connection: "" (plain), "doh", "dot"
}

AddParams - parameters for Add()

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 added in v0.101.0

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 added in v0.101.0

func NewQLogFile(path string) (*QLogFile, error)

NewQLogFile initializes a new instance of the QLogFile

func (*QLogFile) Close added in v0.101.0

func (q *QLogFile) Close() error

Close frees the underlying resources

func (*QLogFile) ReadNext added in v0.101.0

func (q *QLogFile) ReadNext() (string, error)

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 added in v0.101.0

func (q *QLogFile) Seek(timestamp int64) (int64, int, error)

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

func (*QLogFile) SeekStart added in v0.101.0

func (q *QLogFile) SeekStart() (int64, error)

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

Returns nil if we were able to change the current position. Returns error in any other case.

type QLogReader added in v0.101.0

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 added in v0.101.0

func NewQLogReader(files []string) (*QLogReader, error)

NewQLogReader initializes a QLogReader instance with the specified files

func (*QLogReader) Close added in v0.101.0

func (r *QLogReader) Close() error

Close closes the QLogReader

func (*QLogReader) ReadNext added in v0.101.0

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 added in v0.101.0

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 added in v0.101.0

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.

type QueryLog

type QueryLog interface {
	Start()

	// Close query log object
	Close()

	// Add a log entry
	Add(params AddParams)

	// WriteDiskConfig - write configuration
	WriteDiskConfig(c *Config)
}

QueryLog - main interface

func New

func New(conf Config) QueryLog

New - create a new instance of the query log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL