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
30 changes: 30 additions & 0 deletions tool/teleport/common/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type DebugClient interface {
GetLogLevel(context.Context) (string, error)
// CollectProfile collects a pprof profile.
CollectProfile(context.Context, string, int) ([]byte, error)
// GetReadiness checks if the instance is ready to serve requests.
GetReadiness(context.Context) (debugclient.Readiness, error)
SocketPath() string
}

Expand Down Expand Up @@ -166,6 +168,34 @@ func collectProfiles(ctx context.Context, clt DebugClient, buf io.Writer, rawPro
return trace.NewAggregate(tw.Close(), gw.Close())
}

// onReadyz checks if the instance is ready to serve requests.
func onReadyz(ctx context.Context, configPath string) error {
clt, dataDir, err := newDebugClient(configPath)
if err != nil {
return trace.Wrap(err)
}

if err := readyz(ctx, clt); err != nil {
return convertToReadableErr(err, dataDir, clt.SocketPath())
}

return nil
}

func readyz(ctx context.Context, clt DebugClient) error {
readiness, err := clt.GetReadiness(ctx)
if err != nil {
return trace.Wrap(err)
}

if !readiness.Ready {
return trace.Errorf("not ready (PID:%d): %s", readiness.PID, readiness.Status)
}

fmt.Printf("ready (PID:%d)\n", readiness.PID)
return nil
}

// newDebugClient initializes the debug client based on the Teleport
// configuration. It also returns the data dir and socket path used.
func newDebugClient(configPath string) (DebugClient, string, error) {
Expand Down
3 changes: 3 additions & 0 deletions tool/teleport/common/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ func Run(options Options) (app *kingpin.Application, executedCommand string, con
collectProfilesCmd.Alias(collectProfileUsageExamples) // We're using "alias" section to display usage examples.
collectProfilesCmd.Arg("PROFILES", fmt.Sprintf("Comma-separated profile names to be exported. Supported profiles: %s. Default: %s", strings.Join(slices.Collect(maps.Keys(debugclient.SupportedProfiles)), ","), strings.Join(defaultCollectProfiles, ","))).StringVar(&ccf.Profiles)
collectProfilesCmd.Flag("seconds", "For CPU and trace profiles, profile for the given duration (if set to 0, it returns a profile snapshot). For other profiles, return a delta profile. Default: 0").Short('s').Default("0").IntVar(&ccf.ProfileSeconds)
readyzCmd := debugCmd.Command("readyz", "Checks if the instance is ready to serve requests.")

selinuxCmd := app.Command("selinux-ssh", "Commands related to SSH SELinux module.").Hidden()
selinuxCmd.Flag("config", fmt.Sprintf("Path to a configuration file [%v].", defaults.ConfigFilePath)).Short('c').ExistingFileVar(&ccf.ConfigFile)
Expand Down Expand Up @@ -810,6 +811,8 @@ Examples:
err = onGetLogLevel(ccf.ConfigFile)
case collectProfilesCmd.FullCommand():
err = onCollectProfiles(ccf.ConfigFile, ccf.Profiles, ccf.ProfileSeconds)
case readyzCmd.FullCommand():
err = onReadyz(ctx, ccf.ConfigFile)
case moduleSourceCmd.FullCommand():
if runtime.GOOS != "linux" {
break
Expand Down
Loading