From 73e53dcd1c7ff1d6a8ad4b23db7eccb513b616eb Mon Sep 17 00:00:00 2001 From: Val Date: Tue, 3 Oct 2023 12:31:56 +0200 Subject: [PATCH] cmd/tailscale,ipn/ipnlocal: print debug component names Make the 'tailscale debug component-logs' command print the component names for which extra logging can be turned on, for easier discoverability of debug functions. Updates #cleanup Co-authored-by: Paul Scott Signed-off-by: Val --- cmd/tailscale/cli/debug.go | 9 +++++---- ipn/backend.go | 7 +++++++ ipn/ipnlocal/local.go | 9 ++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go index c8c0f75c0..3dc821c10 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscale/cli/debug.go @@ -63,9 +63,10 @@ var debugCmd = &ffcli.Command{ ShortHelp: "print DERP map", }, { - Name: "component-logs", - Exec: runDebugComponentLogs, - ShortHelp: "enable/disable debug logs for a component", + Name: "component-logs", + Exec: runDebugComponentLogs, + ShortHelp: "enable/disable debug logs for a component", + ShortUsage: "tailscale debug component-logs [" + strings.Join(ipn.DebuggableComponents, "|") + "]", FlagSet: (func() *flag.FlagSet { fs := newFlagSet("component-logs") fs.DurationVar(&debugComponentLogsArgs.forDur, "for", time.Hour, "how long to enable debug logs for; zero or negative means to disable") @@ -724,7 +725,7 @@ var debugComponentLogsArgs struct { func runDebugComponentLogs(ctx context.Context, args []string) error { if len(args) != 1 { - return errors.New("usage: debug component-logs ") + return errors.New("usage: debug component-logs [" + strings.Join(ipn.DebuggableComponents, "|") + "]") } component := args[0] dur := debugComponentLogsArgs.forDur diff --git a/ipn/backend.go b/ipn/backend.go index 8da7e6a5c..ad5dbd4bf 100644 --- a/ipn/backend.go +++ b/ipn/backend.go @@ -192,6 +192,13 @@ type PartialFile struct { // - "_debug__until" with value being a unix timestamp stringified type StateKey string +// DebuggableComponents is a list of components whose debugging can be turned on +// and off individually using the tailscale debug command. +var DebuggableComponents = []string{ + "magicsock", + "sockstats", +} + type Options struct { // FrontendLogID is the public logtail id used by the frontend. FrontendLogID string diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 1144d93bf..c02e7d5ba 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -386,7 +386,7 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo b.logf("[unexpected] failed to wire up PeerAPI port for engine %T", e) } - for _, component := range debuggableComponents { + for _, component := range ipn.DebuggableComponents { key := componentStateKey(component) if ut, err := ipn.ReadStoreInt(pm.Store(), key); err == nil { if until := time.Unix(ut, 0); until.After(b.clock.Now()) { @@ -404,11 +404,6 @@ type componentLogState struct { timer tstime.TimerController // if non-nil, the AfterFunc to disable it } -var debuggableComponents = []string{ - "magicsock", - "sockstats", -} - func componentStateKey(component string) ipn.StateKey { return ipn.StateKey("_debug_" + component + "_until") } @@ -440,7 +435,7 @@ func (b *LocalBackend) SetComponentDebugLogging(component string, until time.Tim } } } - if setEnabled == nil || !slices.Contains(debuggableComponents, component) { + if setEnabled == nil || !slices.Contains(ipn.DebuggableComponents, component) { return fmt.Errorf("unknown component %q", component) } timeUnixOrZero := func(t time.Time) int64 {