Pull request: upd golibs, use timeutil
Merge in DNS/adguard-home from use-timeutil to master Squashed commit of the following: commit 28defb577b2b00efa448f63fe6a0cc468aa53164 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 30 19:46:38 2021 +0300 all: upd golibs, use timeutil
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -103,11 +104,11 @@ func (l *queryLog) Close() {
|
||||
func checkInterval(ivl time.Duration) (ok bool) {
|
||||
// The constants for possible values of query log's rotation interval.
|
||||
const (
|
||||
quarterDay = 6 * time.Hour
|
||||
day = 24 * time.Hour
|
||||
week = day * 7
|
||||
month = day * 30
|
||||
threeMonths = day * 90
|
||||
quarterDay = timeutil.Day / 4
|
||||
day = timeutil.Day
|
||||
week = timeutil.Day * 7
|
||||
month = timeutil.Day * 30
|
||||
threeMonths = timeutil.Day * 90
|
||||
)
|
||||
|
||||
return ivl == quarterDay || ivl == day || ivl == week || ivl == month || ivl == threeMonths
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/dnsproxy/proxyutil"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -26,7 +27,7 @@ func TestQueryLog(t *testing.T) {
|
||||
l := newQueryLog(Config{
|
||||
Enabled: true,
|
||||
FileEnabled: true,
|
||||
RotationIvl: 24 * time.Hour,
|
||||
RotationIvl: timeutil.Day,
|
||||
MemSize: 100,
|
||||
BaseDir: t.TempDir(),
|
||||
})
|
||||
@@ -128,7 +129,7 @@ func TestQueryLog(t *testing.T) {
|
||||
func TestQueryLogOffsetLimit(t *testing.T) {
|
||||
l := newQueryLog(Config{
|
||||
Enabled: true,
|
||||
RotationIvl: 24 * time.Hour,
|
||||
RotationIvl: timeutil.Day,
|
||||
MemSize: 100,
|
||||
BaseDir: t.TempDir(),
|
||||
})
|
||||
@@ -203,7 +204,7 @@ func TestQueryLogMaxFileScanEntries(t *testing.T) {
|
||||
l := newQueryLog(Config{
|
||||
Enabled: true,
|
||||
FileEnabled: true,
|
||||
RotationIvl: 24 * time.Hour,
|
||||
RotationIvl: timeutil.Day,
|
||||
MemSize: 100,
|
||||
BaseDir: t.TempDir(),
|
||||
})
|
||||
@@ -231,7 +232,7 @@ func TestQueryLogFileDisabled(t *testing.T) {
|
||||
l := newQueryLog(Config{
|
||||
Enabled: true,
|
||||
FileEnabled: false,
|
||||
RotationIvl: 24 * time.Hour,
|
||||
RotationIvl: timeutil.Day,
|
||||
MemSize: 2,
|
||||
BaseDir: t.TempDir(),
|
||||
})
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -125,7 +126,7 @@ func newQueryLog(conf Config) (l *queryLog) {
|
||||
"querylog: warning: unsupported rotation interval %d, setting to 1 day",
|
||||
conf.RotationIvl,
|
||||
)
|
||||
l.conf.RotationIvl = 24 * time.Hour
|
||||
l.conf.RotationIvl = timeutil.Day
|
||||
}
|
||||
|
||||
return l
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
)
|
||||
|
||||
// flushLogBuffer flushes the current buffer to file and resets the current buffer
|
||||
@@ -150,6 +151,6 @@ func (l *queryLog) periodicRotate() {
|
||||
}
|
||||
|
||||
// What?
|
||||
time.Sleep(24 * time.Hour)
|
||||
time.Sleep(timeutil.Day)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -37,7 +38,7 @@ func TestQueryLog_Search_findClient(t *testing.T) {
|
||||
l := newQueryLog(Config{
|
||||
FindClient: findClient,
|
||||
BaseDir: t.TempDir(),
|
||||
RotationIvl: 24 * time.Hour,
|
||||
RotationIvl: timeutil.Day,
|
||||
MemSize: 100,
|
||||
Enabled: true,
|
||||
FileEnabled: true,
|
||||
|
||||
Reference in New Issue
Block a user