Pull request 2355: AGDNS-2686-client-manager-clock

Merge in DNS/adguard-home from AGDNS-2686-client-manager-clock to master

Squashed commit of the following:

commit 1d3cafa7f1036a72b766feaee1db00398e51c364
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Tue Mar 4 20:52:39 2025 +0300

    all: client manager clock
This commit is contained in:
Stanislav Chzhen
2025-03-04 21:18:22 +03:00
parent 318bd2901a
commit 0d2163c1d6
4 changed files with 32 additions and 8 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/timeutil"
)
// CommonUpstreamConfig contains common settings for custom client upstream
@@ -68,16 +69,20 @@ type upstreamManager struct {
// commonConf is the common upstream configuration.
commonConf *CommonUpstreamConfig
// clock is used to get the current time. It must not be nil.
clock timeutil.Clock
// confUpdate is the timestamp of the latest common upstream configuration
// update.
confUpdate time.Time
}
// newUpstreamManager returns the new properly initialized upstream manager.
func newUpstreamManager(logger *slog.Logger) (m *upstreamManager) {
func newUpstreamManager(logger *slog.Logger, clock timeutil.Clock) (m *upstreamManager) {
return &upstreamManager{
logger: logger,
uidToCustomConf: make(map[UID]*customUpstreamConfig),
clock: clock,
}
}
@@ -85,7 +90,7 @@ func newUpstreamManager(logger *slog.Logger) (m *upstreamManager) {
// timestamp of the latest configuration update.
func (m *upstreamManager) updateCommonUpstreamConfig(conf *CommonUpstreamConfig) {
m.commonConf = conf
m.confUpdate = time.Now()
m.confUpdate = m.clock.Now()
}
// updateCustomUpstreamConfig updates the stored custom client upstream