Pull request 2308: AGDNS-2374-slog-client-storage
Squashed commit of the following:
commit 670ce6f7267ae6447c179ba491fc18c01cffa1ab
Merge: b3029a041 098cbab7e
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Fri Nov 22 17:09:08 2024 +0300
Merge branch 'master' into AGDNS-2374-slog-client-storage
commit b3029a041aa0f4b536dd899f162fcee2b7d5127b
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Fri Nov 22 16:53:18 2024 +0300
all: slog client storage
This commit is contained in:
parent
098cbab7e6
commit
abb738013a
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/whois"
|
"github.com/AdguardTeam/AdGuardHome/internal/whois"
|
||||||
"github.com/AdguardTeam/golibs/errors"
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
"github.com/AdguardTeam/golibs/hostsfile"
|
"github.com/AdguardTeam/golibs/hostsfile"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
|
||||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -506,7 +505,7 @@ func (s *Storage) FindByMAC(mac net.HardwareAddr) (p *Persistent, ok bool) {
|
||||||
|
|
||||||
// RemoveByName removes persistent client information. ok is false if no such
|
// RemoveByName removes persistent client information. ok is false if no such
|
||||||
// client exists by that name.
|
// client exists by that name.
|
||||||
func (s *Storage) RemoveByName(name string) (ok bool) {
|
func (s *Storage) RemoveByName(ctx context.Context, name string) (ok bool) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -516,7 +515,7 @@ func (s *Storage) RemoveByName(name string) (ok bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.CloseUpstreams(); err != nil {
|
if err := p.CloseUpstreams(); err != nil {
|
||||||
log.Error("client storage: removing client %q: %s", p.Name, err)
|
s.logger.ErrorContext(ctx, "removing client", "name", p.Name, slogutil.KeyError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.index.remove(p)
|
s.index.remove(p)
|
||||||
|
|
|
@ -735,7 +735,7 @@ func TestStorage_RemoveByName(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
tc.want(t, s.RemoveByName(tc.cliName))
|
tc.want(t, s.RemoveByName(ctx, tc.cliName))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -744,8 +744,8 @@ func TestStorage_RemoveByName(t *testing.T) {
|
||||||
err = s.Add(ctx, existingClient)
|
err = s.Add(ctx, existingClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.True(t, s.RemoveByName(existingName))
|
assert.True(t, s.RemoveByName(ctx, existingName))
|
||||||
assert.False(t, s.RemoveByName(existingName))
|
assert.False(t, s.RemoveByName(ctx, existingName))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ func (clients *clientsContainer) handleDelClient(w http.ResponseWriter, r *http.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !clients.storage.RemoveByName(cj.Name) {
|
if !clients.storage.RemoveByName(r.Context(), cj.Name) {
|
||||||
aghhttp.Error(r, w, http.StatusBadRequest, "Client not found")
|
aghhttp.Error(r, w, http.StatusBadRequest, "Client not found")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue