Skip to content

Commit

Permalink
Pull request 2308: AGDNS-2374-slog-client-storage
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 670ce6f
Merge: b3029a0 098cbab
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 b3029a0
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Nov 22 16:53:18 2024 +0300

    all: slog client storage
  • Loading branch information
schzhn committed Nov 22, 2024
1 parent 098cbab commit abb7380
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions internal/client/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/whois"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/hostsfile"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/logutil/slogutil"
)

Expand Down Expand Up @@ -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
// 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()
defer s.mu.Unlock()

Expand All @@ -516,7 +515,7 @@ func (s *Storage) RemoveByName(name string) (ok bool) {
}

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)
Expand Down
6 changes: 3 additions & 3 deletions internal/client/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func TestStorage_RemoveByName(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.want(t, s.RemoveByName(tc.cliName))
tc.want(t, s.RemoveByName(ctx, tc.cliName))
})
}

Expand All @@ -744,8 +744,8 @@ func TestStorage_RemoveByName(t *testing.T) {
err = s.Add(ctx, existingClient)
require.NoError(t, err)

assert.True(t, s.RemoveByName(existingName))
assert.False(t, s.RemoveByName(existingName))
assert.True(t, s.RemoveByName(ctx, existingName))
assert.False(t, s.RemoveByName(ctx, existingName))
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/home/clientshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (clients *clientsContainer) handleDelClient(w http.ResponseWriter, r *http.
return
}

if !clients.storage.RemoveByName(cj.Name) {
if !clients.storage.RemoveByName(r.Context(), cj.Name) {
aghhttp.Error(r, w, http.StatusBadRequest, "Client not found")

return
Expand Down

0 comments on commit abb7380

Please sign in to comment.