+ new setting "dns.querylog_memsize"
* set 1000 entries by default (not 5000)
This commit is contained in:
parent
31ffae7717
commit
7e45c2fc24
|
@ -106,6 +106,7 @@ type dnsConfig struct {
|
|||
|
||||
QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled
|
||||
QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days)
|
||||
QueryLogMemSize uint32 `yaml:"querylog_memsize"` // number of entries kept in memory before they are flushed to disk
|
||||
|
||||
dnsforward.FilteringConfig `yaml:",inline"`
|
||||
|
||||
|
@ -164,8 +165,6 @@ var config = configuration{
|
|||
BindHost: "0.0.0.0",
|
||||
Port: 53,
|
||||
StatsInterval: 1,
|
||||
QueryLogEnabled: true,
|
||||
QueryLogInterval: 1,
|
||||
FilteringConfig: dnsforward.FilteringConfig{
|
||||
ProtectionEnabled: true, // whether or not use any of dnsfilter features
|
||||
BlockingMode: "nxdomain", // mode how to answer filtered requests
|
||||
|
@ -202,6 +201,10 @@ func initConfig() {
|
|||
|
||||
config.WebSessionTTLHours = 30 * 24
|
||||
|
||||
config.DNS.QueryLogEnabled = true
|
||||
config.DNS.QueryLogInterval = 90
|
||||
config.DNS.QueryLogMemSize = 1000
|
||||
|
||||
config.DNS.CacheSize = 4 * 1024 * 1024
|
||||
config.DNS.DnsfilterConf.SafeBrowsingCacheSize = 1 * 1024 * 1024
|
||||
config.DNS.DnsfilterConf.SafeSearchCacheSize = 1 * 1024 * 1024
|
||||
|
@ -310,6 +313,7 @@ func (c *configuration) write() error {
|
|||
config.queryLog.WriteDiskConfig(&dc)
|
||||
config.DNS.QueryLogEnabled = dc.Enabled
|
||||
config.DNS.QueryLogInterval = dc.Interval
|
||||
config.DNS.QueryLogMemSize = dc.MemSize
|
||||
}
|
||||
|
||||
if config.dnsFilter != nil {
|
||||
|
|
|
@ -50,6 +50,7 @@ func initDNSServer() {
|
|||
Enabled: config.DNS.QueryLogEnabled,
|
||||
BaseDir: baseDir,
|
||||
Interval: config.DNS.QueryLogInterval,
|
||||
MemSize: config.DNS.QueryLogMemSize,
|
||||
ConfigModified: onConfigModified,
|
||||
HTTPRegister: httpRegister,
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
logBufferCap = 5000 // maximum capacity of buffer before it's flushed to disk
|
||||
queryLogFileName = "querylog.json" // .gz added during compression
|
||||
getDataLimit = 500 // GetData(): maximum log entries to return
|
||||
|
||||
|
@ -147,7 +146,7 @@ func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Res
|
|||
l.buffer = append(l.buffer, &entry)
|
||||
needFlush := false
|
||||
if !l.flushPending {
|
||||
needFlush = len(l.buffer) >= logBufferCap
|
||||
needFlush = len(l.buffer) >= int(l.conf.MemSize)
|
||||
if needFlush {
|
||||
l.flushPending = true
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
type DiskConfig struct {
|
||||
Enabled bool
|
||||
Interval uint32
|
||||
MemSize uint32
|
||||
}
|
||||
|
||||
// QueryLog - main interface
|
||||
|
@ -32,6 +33,7 @@ type Config struct {
|
|||
Enabled bool
|
||||
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
|
||||
|
||||
// Called when the configuration is changed by HTTP request
|
||||
ConfigModified func()
|
||||
|
|
|
@ -27,7 +27,7 @@ func (l *queryLog) flushLogBuffer(fullFlush bool) error {
|
|||
|
||||
// flush remainder to file
|
||||
l.bufferLock.Lock()
|
||||
needFlush := len(l.buffer) >= logBufferCap
|
||||
needFlush := len(l.buffer) >= int(l.conf.MemSize)
|
||||
if !needFlush && !fullFlush {
|
||||
l.bufferLock.Unlock()
|
||||
return nil
|
||||
|
|
|
@ -23,6 +23,7 @@ func TestQueryLog(t *testing.T) {
|
|||
conf := Config{
|
||||
Enabled: true,
|
||||
Interval: 1,
|
||||
MemSize: 100,
|
||||
}
|
||||
conf.BaseDir = prepareTestDir()
|
||||
defer func() { _ = os.RemoveAll(conf.BaseDir) }()
|
||||
|
|
Loading…
Reference in New Issue