Skip to content

Commit

Permalink
all: querylog size memory
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Dec 25, 2023
1 parent ad147ac commit 0b17cfc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -58,6 +58,7 @@ NOTE: Add new changes BELOW THIS COMMENT.

### Fixed

- Zero value in `querylog.size_memory` disables logging ([#6570]).
- Load balancing algorithm stuck on a single server ([#6480]).
- Statistics for 7 days displayed as 168 hours on the dashboard.
- Pre-filling the Edit static lease window with data ([#6534]).
Expand All @@ -71,6 +72,7 @@ NOTE: Add new changes BELOW THIS COMMENT.
[#6534]: https://github.com/AdguardTeam/AdGuardHome/issues/6534
[#6541]: https://github.com/AdguardTeam/AdGuardHome/issues/6541
[#6545]: https://github.com/AdguardTeam/AdGuardHome/issues/6545
[#6570]: https://github.com/AdguardTeam/AdGuardHome/issues/6570

<!--
NOTE: Add new changes ABOVE THIS COMMENT.
Expand Down
2 changes: 1 addition & 1 deletion internal/home/config.go
Expand Up @@ -267,7 +267,7 @@ type queryLogConfig struct {

// MemSize is the number of entries kept in memory before they are flushed
// to disk.
MemSize int `yaml:"size_memory"`
MemSize uint `yaml:"size_memory"`

// Enabled defines if the query log is enabled.
Enabled bool `yaml:"enabled"`
Expand Down
4 changes: 2 additions & 2 deletions internal/querylog/qlog.go
Expand Up @@ -202,10 +202,10 @@ func (l *queryLog) Add(params *AddParams) {
defer l.confMu.RUnlock()

isEnabled, fileIsEnabled = l.conf.Enabled, l.conf.FileEnabled
memSize = l.conf.MemSize
memSize = int(l.conf.MemSize)
}()

if !isEnabled || memSize == 0 {
if !isEnabled {
return
}

Expand Down
11 changes: 7 additions & 4 deletions internal/querylog/querylog.go
Expand Up @@ -63,7 +63,7 @@ type Config struct {

// MemSize is the number of entries kept in a memory buffer before they are
// flushed to disk.
MemSize int
MemSize uint

// Enabled tells if the query log is enabled.
Enabled bool
Expand Down Expand Up @@ -143,14 +143,17 @@ func newQueryLog(conf Config) (l *queryLog, err error) {
}
}

if conf.MemSize < 0 {
return nil, errors.Error("memory size must be greater or equal to zero")
memSize := int(conf.MemSize)
if memSize == 0 {
// If query log is not diabled, we still need to write entries to a
// file. And all writing goes through a buffer.
memSize = 1
}

l = &queryLog{
findClient: findClient,

buffer: aghalg.NewRingBuffer[*logEntry](conf.MemSize),
buffer: aghalg.NewRingBuffer[*logEntry](memSize),

conf: &Config{},
confMu: &sync.RWMutex{},
Expand Down

0 comments on commit 0b17cfc

Please sign in to comment.