Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions receiver/oxideauditlogsreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ func (s *auditLogScraper) loadCursor() (cursor, bool) {
s.logger.Warn("cursor file missing time_completed", zap.String("path", s.cfg.CursorPath))
return cursor{}, false
}
if now := time.Now(); c.TimeCompleted.After(now) {
s.logger.Warn("cursor file time_completed is in the future, clamping to now",
zap.String("path", s.cfg.CursorPath),
zap.Timep("time_completed", c.TimeCompleted),
)
c = cursor{TimeCompleted: &now}
}
return c, true
}

Expand Down
16 changes: 16 additions & 0 deletions receiver/oxideauditlogsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,19 @@ func TestCursorPersistence(t *testing.T) {
require.Equal(t, "id-2", s2.cursor.ID)
require.Equal(t, t2, *s2.cursor.TimeCompleted)
}

func TestFutureCursorClamped(t *testing.T) {
cursorPath := filepath.Join(t.TempDir(), "cursor.json")
future := time.Now().Add(time.Hour)
data, err := json.Marshal(cursor{TimeCompleted: &future, ID: "id-1"})
require.NoError(t, err)
require.NoError(t, os.WriteFile(cursorPath, data, 0o600))

cfg := &Config{InitialLookback: 24 * time.Hour, CursorPath: cursorPath}
client := &mockAuditLogClient{host: "https://example.oxide.computer"}
s := newAuditLogScraper(cfg, componenttest.NewNopTelemetrySettings(), client)
require.NoError(t, s.Start(context.Background(), nil))

require.Empty(t, s.cursor.ID)
require.WithinDuration(t, time.Now(), *s.cursor.TimeCompleted, 5*time.Second)
}