mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
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 <paul@tailscale.com> Signed-off-by: Val <valerie@tailscale.com>
This commit is contained in:
parent
5efd5e093e
commit
73e53dcd1c
@ -66,6 +66,7 @@
|
|||||||
Name: "component-logs",
|
Name: "component-logs",
|
||||||
Exec: runDebugComponentLogs,
|
Exec: runDebugComponentLogs,
|
||||||
ShortHelp: "enable/disable debug logs for a component",
|
ShortHelp: "enable/disable debug logs for a component",
|
||||||
|
ShortUsage: "tailscale debug component-logs [" + strings.Join(ipn.DebuggableComponents, "|") + "]",
|
||||||
FlagSet: (func() *flag.FlagSet {
|
FlagSet: (func() *flag.FlagSet {
|
||||||
fs := newFlagSet("component-logs")
|
fs := newFlagSet("component-logs")
|
||||||
fs.DurationVar(&debugComponentLogsArgs.forDur, "for", time.Hour, "how long to enable debug logs for; zero or negative means to disable")
|
fs.DurationVar(&debugComponentLogsArgs.forDur, "for", time.Hour, "how long to enable debug logs for; zero or negative means to disable")
|
||||||
@ -724,7 +725,7 @@ func runTS2021(ctx context.Context, args []string) error {
|
|||||||
|
|
||||||
func runDebugComponentLogs(ctx context.Context, args []string) error {
|
func runDebugComponentLogs(ctx context.Context, args []string) error {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return errors.New("usage: debug component-logs <component>")
|
return errors.New("usage: debug component-logs [" + strings.Join(ipn.DebuggableComponents, "|") + "]")
|
||||||
}
|
}
|
||||||
component := args[0]
|
component := args[0]
|
||||||
dur := debugComponentLogsArgs.forDur
|
dur := debugComponentLogsArgs.forDur
|
||||||
|
@ -192,6 +192,13 @@ type PartialFile struct {
|
|||||||
// - "_debug_<component>_until" with value being a unix timestamp stringified
|
// - "_debug_<component>_until" with value being a unix timestamp stringified
|
||||||
type StateKey string
|
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 {
|
type Options struct {
|
||||||
// FrontendLogID is the public logtail id used by the frontend.
|
// FrontendLogID is the public logtail id used by the frontend.
|
||||||
FrontendLogID string
|
FrontendLogID string
|
||||||
|
@ -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)
|
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)
|
key := componentStateKey(component)
|
||||||
if ut, err := ipn.ReadStoreInt(pm.Store(), key); err == nil {
|
if ut, err := ipn.ReadStoreInt(pm.Store(), key); err == nil {
|
||||||
if until := time.Unix(ut, 0); until.After(b.clock.Now()) {
|
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
|
timer tstime.TimerController // if non-nil, the AfterFunc to disable it
|
||||||
}
|
}
|
||||||
|
|
||||||
var debuggableComponents = []string{
|
|
||||||
"magicsock",
|
|
||||||
"sockstats",
|
|
||||||
}
|
|
||||||
|
|
||||||
func componentStateKey(component string) ipn.StateKey {
|
func componentStateKey(component string) ipn.StateKey {
|
||||||
return ipn.StateKey("_debug_" + component + "_until")
|
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)
|
return fmt.Errorf("unknown component %q", component)
|
||||||
}
|
}
|
||||||
timeUnixOrZero := func(t time.Time) int64 {
|
timeUnixOrZero := func(t time.Time) int64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user