-
Notifications
You must be signed in to change notification settings - Fork 42
Probe scripts #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Probe scripts #260
Changes from all commits
e5d034e
d66e245
1f18b0f
e742adf
143c0df
d156492
d740405
3d8d8f6
2fa8b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,27 @@ var inspectCmd = &cobra.Command{ | |
| }, | ||
| } | ||
|
|
||
| var debugCmd = &cobra.Command{ | ||
| Use: "debug", | ||
| } | ||
|
|
||
| var probeCmd = &cobra.Command{ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new command is useful to check the result of a healthcheck probe |
||
| Use: "probe", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| serviceName := args[0] | ||
|
|
||
| resp, err := playground.ExecuteHealthCheckManually(serviceName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Printf("Exit code: %d\n", resp.ExitCode) | ||
| fmt.Printf("Output: %s\n", resp.Output) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| var logsCmd = &cobra.Command{ | ||
| Use: "logs", | ||
| Short: "Show logs for a service", | ||
|
|
@@ -193,6 +214,10 @@ func main() { | |
| rootCmd.AddCommand(stopCmd) | ||
| stopCmd.Flags().StringVar(&outputFlag, "output", "", "Output folder for the artifacts") | ||
|
|
||
| debugCmd.AddCommand(probeCmd) | ||
| debugCmd.AddCommand(inspectCmd) | ||
| rootCmd.AddCommand(debugCmd) | ||
|
|
||
| if err := rootCmd.Execute(); err != nil { | ||
| fmt.Println(err) | ||
| os.Exit(1) | ||
|
|
@@ -280,14 +305,14 @@ func runIt(recipe playground.Recipe) error { | |
|
|
||
| if interactive { | ||
| i := playground.NewInteractiveDisplay(svcManager) | ||
| cfg.Callback = i.HandleUpdate | ||
| cfg.AddCallback(i.HandleUpdate) | ||
| } | ||
|
|
||
| // Add callback to log service updates in debug mode | ||
| if logLevel == playground.LevelDebug { | ||
| cfg.Callback = func(serviceName string, update playground.TaskStatus) { | ||
| cfg.AddCallback(func(serviceName string, update playground.TaskStatus) { | ||
| log.Printf("[DEBUG] [%s] %s\n", serviceName, update) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| dockerRunner, err := playground.NewLocalRunner(cfg) | ||
|
|
@@ -328,14 +353,7 @@ func runIt(recipe playground.Recipe) error { | |
| return fmt.Errorf("failed to wait for service readiness: %w", err) | ||
| } | ||
|
|
||
| fmt.Printf("\nWaiting for network to be ready for transactions...\n") | ||
| networkReadyStart := time.Now() | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This alongside |
||
| if err := playground.CompleteReady(ctx, svcManager.Services); err != nil { | ||
| dockerRunner.Stop() | ||
| return fmt.Errorf("network not ready: %w", err) | ||
| } | ||
| fmt.Printf("Network is ready for transactions (took %.1fs)\n", time.Since(networkReadyStart).Seconds()) | ||
| fmt.Println("Session ID:", svcManager.ID) | ||
| fmt.Println("\nServices healthy... Ready to accept transactions") | ||
|
|
||
| // get the output from the recipe | ||
| output := recipe.Output(svcManager) | ||
|
|
@@ -353,9 +371,11 @@ func runIt(recipe playground.Recipe) error { | |
| watchdogErr := make(chan error, 1) | ||
| if watchdog { | ||
| go func() { | ||
| if err := playground.RunWatchdog(artifacts.Out, svcManager.Services); err != nil { | ||
| watchdogErr <- fmt.Errorf("watchdog failed: %w", err) | ||
| } | ||
| cfg.AddCallback(func(name string, status playground.TaskStatus) { | ||
| if status == playground.TaskStatusUnhealty { | ||
| watchdogErr <- fmt.Errorf("watchdog failed: %w", fmt.Errorf("task '%s' is not healthy anymore", name)) | ||
| } | ||
| }) | ||
| }() | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put all the commands that look like debugging utilities under the
debugsubcommand.