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
16 changes: 15 additions & 1 deletion cmd/lk/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,21 @@ func listUserAnalyticsSessions(ctx context.Context, cmd *cli.Command) error {
if err != nil {
return cloudAPIError(err)
}
return render.SessionsPage(out, cmd.Bool("json"), sessions, nextCursor)
asJSON := cmd.Bool("json")
if err := render.SessionsPage(out, asJSON, sessions, nextCursor); err != nil {
return err
}
if len(sessions) == 0 && !asJSON && searchedDefaultWindow(opts) {
out.Statusf("Only the last 24 hours were searched — re-run with %s to look further back", util.Accented("--start YYYY-MM-DD"))
}
return nil
}

// searchedDefaultWindow reports whether a listing left its window to the
// Public API, which then searches only the last 24 hours. A cursor carries the
// window of the listing it came from.
func searchedDefaultWindow(opts public.SessionListOptions) bool {
return opts.Start.IsZero() && opts.Cursor == ""
}

// sessionListOptions reads the session list flags for the Public API. --start
Expand Down
10 changes: 10 additions & 0 deletions cmd/lk/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ func TestSessionListOptions(t *testing.T) {
}
}

// TestSearchedDefaultWindow checks when an empty listing gets the hint that only
// the last 24 hours were searched: when neither --start nor a cursor set the
// window, so a quiet day doesn't read as a project with no sessions.
func TestSearchedDefaultWindow(t *testing.T) {
assert.True(t, searchedDefaultWindow(public.SessionListOptions{}))
assert.False(t, searchedDefaultWindow(public.SessionListOptions{Start: time.Date(2026, 10, 1, 0, 0, 0, 0, time.UTC)}))
// A cursor carries the window of the listing it came from.
assert.False(t, searchedDefaultWindow(public.SessionListOptions{Cursor: "abc"}))
}

// validateListModeFlags runs analyticsListModeFlags.validate on a command built
// from fresh analyticsSessionListFlags plus the --experimental-auth selector,
// which production declares on the root.
Expand Down
Loading