Pull request: hup-reload

Merge in DNS/adguard-home from hup-reload to master

Squashed commit of the following:

commit 5cd4ab85bdc7544a4eded2a61f5a5571175daa44
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Oct 7 19:58:17 2022 +0300

    next: imp signal hdlr

commit 8fd18e749fec46982d26fc408e661bd802586c37
Merge: a8780455 f1dd3334
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Oct 7 19:46:48 2022 +0300

    Merge branch 'master' into hup-reload

commit a87804550e15d7fe3d9ded2e5a736c395f96febd
Merge: 349dbe54 960a7a75
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Oct 7 15:49:23 2022 +0300

    Merge branch 'master' into hup-reload

commit 349dbe54fe27eeaf56776c73c3cc5649018d4c60
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Oct 7 15:43:52 2022 +0300

    next: imp docs, names

commit 7287a86d283489127453009267911003cea5227e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Oct 7 13:39:44 2022 +0300

    WIP all: impl dynamic reconfiguration
This commit is contained in:
Ainar Garipov
2022-10-10 14:05:24 +03:00
parent f1dd33346a
commit f5602d9c46
18 changed files with 417 additions and 70 deletions

View File

@@ -11,6 +11,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
"github.com/AdguardTeam/AdGuardHome/internal/next/websvc"
"github.com/stretchr/testify/assert"
@@ -28,7 +29,7 @@ func TestService_HandlePatchSettingsDNS(t *testing.T) {
// TODO(a.garipov): Use [atomic.Bool] in Go 1.19.
var numStarted uint64
confMgr := newConfigManager()
confMgr.onDNS = func() (s websvc.ServiceWithConfig[*dnssvc.Config]) {
confMgr.onDNS = func() (s agh.ServiceWithConfig[*dnssvc.Config]) {
return &aghtest.ServiceWithConfig[*dnssvc.Config]{
OnStart: func() (err error) {
atomic.AddUint64(&numStarted, 1)

View File

@@ -8,6 +8,7 @@ import (
"net/netip"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/AdguardTeam/golibs/log"
)
@@ -89,7 +90,7 @@ func (svc *Service) handlePatchSettingsHTTP(w http.ResponseWriter, r *http.Reque
// TODO(a.garipov): Consider better ways to do this.
const maxUpdDur = 10 * time.Second
updStart := time.Now()
var newSvc ServiceWithConfig[*Config]
var newSvc agh.ServiceWithConfig[*Config]
for newSvc = svc.confMgr.Web(); newSvc == svc; {
if time.Since(updStart) >= maxUpdDur {
log.Error("websvc: failed to update svc after %s", maxUpdDur)

View File

@@ -10,6 +10,7 @@ import (
"testing"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/AdguardTeam/AdGuardHome/internal/next/websvc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -24,7 +25,7 @@ func TestService_HandlePatchSettingsHTTP(t *testing.T) {
}
confMgr := newConfigManager()
confMgr.onWeb = func() (s websvc.ServiceWithConfig[*websvc.Config]) {
confMgr.onWeb = func() (s agh.ServiceWithConfig[*websvc.Config]) {
return websvc.New(&websvc.Config{
TLS: &tls.Config{
Certificates: []tls.Certificate{{}},

View File

@@ -9,6 +9,7 @@ import (
"testing"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
"github.com/AdguardTeam/AdGuardHome/internal/next/websvc"
"github.com/stretchr/testify/assert"
@@ -33,7 +34,7 @@ func TestService_HandleGetSettingsAll(t *testing.T) {
}
confMgr := newConfigManager()
confMgr.onDNS = func() (s websvc.ServiceWithConfig[*dnssvc.Config]) {
confMgr.onDNS = func() (s agh.ServiceWithConfig[*dnssvc.Config]) {
c, err := dnssvc.New(&dnssvc.Config{
Addresses: wantDNS.Addresses,
UpstreamServers: wantDNS.UpstreamServers,
@@ -45,7 +46,7 @@ func TestService_HandleGetSettingsAll(t *testing.T) {
return c
}
confMgr.onWeb = func() (s websvc.ServiceWithConfig[*websvc.Config]) {
confMgr.onWeb = func() (s agh.ServiceWithConfig[*websvc.Config]) {
return websvc.New(&websvc.Config{
TLS: &tls.Config{
Certificates: []tls.Certificate{{}},

View File

@@ -24,21 +24,10 @@ import (
httptreemux "github.com/dimfeld/httptreemux/v5"
)
// ServiceWithConfig is an extension of the [agh.Service] interface for services
// that can return their configuration.
//
// TODO(a.garipov): Consider removing this generic interface if we figure out
// how to make it testable in a better way.
type ServiceWithConfig[ConfigType any] interface {
agh.Service
Config() (c ConfigType)
}
// ConfigManager is the configuration manager interface.
type ConfigManager interface {
DNS() (svc ServiceWithConfig[*dnssvc.Config])
Web() (svc ServiceWithConfig[*Config])
DNS() (svc agh.ServiceWithConfig[*dnssvc.Config])
Web() (svc agh.ServiceWithConfig[*Config])
UpdateDNS(ctx context.Context, c *dnssvc.Config) (err error)
UpdateWeb(ctx context.Context, c *Config) (err error)

View File

@@ -12,6 +12,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
"github.com/AdguardTeam/AdGuardHome/internal/next/websvc"
"github.com/AdguardTeam/golibs/testutil"
@@ -34,20 +35,20 @@ var _ websvc.ConfigManager = (*configManager)(nil)
// configManager is a [websvc.ConfigManager] for tests.
type configManager struct {
onDNS func() (svc websvc.ServiceWithConfig[*dnssvc.Config])
onWeb func() (svc websvc.ServiceWithConfig[*websvc.Config])
onDNS func() (svc agh.ServiceWithConfig[*dnssvc.Config])
onWeb func() (svc agh.ServiceWithConfig[*websvc.Config])
onUpdateDNS func(ctx context.Context, c *dnssvc.Config) (err error)
onUpdateWeb func(ctx context.Context, c *websvc.Config) (err error)
}
// DNS implements the [websvc.ConfigManager] interface for *configManager.
func (m *configManager) DNS() (svc websvc.ServiceWithConfig[*dnssvc.Config]) {
func (m *configManager) DNS() (svc agh.ServiceWithConfig[*dnssvc.Config]) {
return m.onDNS()
}
// Web implements the [websvc.ConfigManager] interface for *configManager.
func (m *configManager) Web() (svc websvc.ServiceWithConfig[*websvc.Config]) {
func (m *configManager) Web() (svc agh.ServiceWithConfig[*websvc.Config]) {
return m.onWeb()
}
@@ -64,8 +65,8 @@ func (m *configManager) UpdateWeb(ctx context.Context, c *websvc.Config) (err er
// newConfigManager returns a *configManager all methods of which panic.
func newConfigManager() (m *configManager) {
return &configManager{
onDNS: func() (svc websvc.ServiceWithConfig[*dnssvc.Config]) { panic("not implemented") },
onWeb: func() (svc websvc.ServiceWithConfig[*websvc.Config]) { panic("not implemented") },
onDNS: func() (svc agh.ServiceWithConfig[*dnssvc.Config]) { panic("not implemented") },
onWeb: func() (svc agh.ServiceWithConfig[*websvc.Config]) { panic("not implemented") },
onUpdateDNS: func(_ context.Context, _ *dnssvc.Config) (err error) {
panic("not implemented")
},