mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-03 13:56:36 +09:00
ipn/auditlog: don't restore logs for a profile without an ID
The extension starts a logger when the control client is created, which for a new profile happens before the profile has an ID. Start then tried to load stored logs with an empty key and logged "[unexpected] failed to restore logs: empty key" on every fresh start, as seen in the Windows integration tests. A profile without an ID has no stored logs, so skip the restore. Updates #cleanup Updates #22309 (the only [unexpected] log line in integration tests) Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
1 parent
7edc089a07
commit
45098febab
2 files changed
+35
-3
No files matched your search
@@ -162,9 +162,14 @@ func (al *Logger) Start(t Transport) error {
|
||||
}
|
||||
|
||||
al.transport = t
|
||||
pending, err := al.storedCountLocked()
|
||||
if err != nil {
|
||||
al.logf("[unexpected] failed to restore logs: %v", err)
|
||||
var pending int
|
||||
// A profile that has not been persisted yet has no ID,
|
||||
// and no stored logs to restore.
|
||||
if al.profileID != "" {
|
||||
var err error
|
||||
if pending, err = al.storedCountLocked(); err != nil {
|
||||
al.logf("[unexpected] failed to restore logs: %v", err)
|
||||
}
|
||||
}
|
||||
go al.flushWorker()
|
||||
if pending > 0 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -370,6 +371,32 @@ func TestEnqueueBeforeSetProfileID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStartBeforeSetProfileID tests that a logger can be started for a profile
|
||||
// that has no ID yet, and that it sends logs once the ID is set.
|
||||
func TestStartBeforeSetProfileID(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
mockTransport := newMockTransport(nil)
|
||||
al := loggerForTest(t, Opts{
|
||||
RetryLimit: 100,
|
||||
Logf: func(format string, args ...any) {
|
||||
t.Logf(format, args...)
|
||||
if strings.Contains(format, "[unexpected]") {
|
||||
t.Errorf("unexpected log: "+format, args...)
|
||||
}
|
||||
},
|
||||
Store: NewLogStore(&mem.Store{}),
|
||||
})
|
||||
|
||||
c.Assert(al.Start(mockTransport), qt.IsNil)
|
||||
c.Assert(al.SetProfileID("test"), qt.IsNil)
|
||||
c.Assert(al.Enqueue(tailcfg.AuditNodeDisconnect, "log"), qt.IsNil)
|
||||
al.FlushAndStop(context.Background())
|
||||
|
||||
if gotSent, wantSent := mockTransport.sentCount(), 1; gotSent != wantSent {
|
||||
t.Fatalf("sent: got %d, want %d", gotSent, wantSent)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLogStoring tests that audit logs are persisted sorted by timestamp, oldest to newest
|
||||
func TestLogSorting(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
Reference in new issue
Block a user