Skip to content
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

fix: better error messages and failed execution info #877

Merged
merged 5 commits into from
Jan 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/scripts/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func watchLogs(id string, client client.Client) {
if execution.ExecutionResult.IsCompleted() {
fmt.Println()

uiShellCommandBlock(id)
uiShellGetExecution(id)

return
}
}

uiShellCommandBlock(id)
uiShellGetExecution(id)
}
15 changes: 8 additions & 7 deletions cmd/kubectl-testkube/commands/scripts/execution_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"text/template"

"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/ui"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -77,14 +78,14 @@ func (r ExecutionRawRenderer) Watch(execution testkube.Execution, writer io.Writ
return err
}

// TODO fix this - introduce some common data interface for rendering such objects
// renderers need to be simplified and render Execution should be in one place (not many as now)
// - move all logic from execution, start, watch here to show final execution
func (r ExecutionRawRenderer) renderDetails(execution testkube.Execution, writer io.Writer) error {
_, err := fmt.Fprintf(writer, "Name: %s, Status: %s, Duration: %s\n",
execution.Name,
*execution.ExecutionResult.Status,
execution.CalculateDuration(),
)

return err
ui.Writer = writer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ui is ugly I know ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this thread safe? Write is a global var

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, added comment to rewrite whole ui, to be able to get new instance with writer passed / I know this sucks ;) as this global is good for simple use cases - we can rethink this whole solution on some meeting with team

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsukhin FYI extracted this as separate issue #878

uiPrintStatus(execution)
uiShellGetExecution(execution.Id)
return nil
}

func GetExecutionRenderer(cmd *cobra.Command) ExecutionRenderer {
Expand Down
19 changes: 14 additions & 5 deletions cmd/kubectl-testkube/commands/scripts/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func NewStartScriptCmd() *cobra.Command {
DownloadArtifacts(execution.Id, downloadDir, client)
}

uiShellCommandBlock(execution.Id)
uiShellGetExecution(execution.Id)
uiShellWatchExecution(execution.Id)
},
}

Expand All @@ -71,6 +72,8 @@ func NewStartScriptCmd() *cobra.Command {
func uiPrintStatus(execution testkube.Execution) {
result := execution.ExecutionResult

ui.NL()

switch true {
case result.IsQueued():
ui.Warn("Script queued for execution")
Expand All @@ -79,26 +82,32 @@ func uiPrintStatus(execution testkube.Execution) {
ui.Warn("Script execution started")

case result.IsSuccesful():
fmt.Println(result.Output)
ui.Info(result.Output)
duration := execution.EndTime.Sub(execution.StartTime)
ui.Success("Script execution completed with sucess in " + duration.String())

case result.IsFailed():
fmt.Println(result.ErrorMessage)
ui.Warn("Test script execution failed:")
ui.Info(result.ErrorMessage)
ui.Errf("Script execution failed")
os.Exit(1)
}

ui.NL()
}

func uiShellCommandBlock(id string) {
func uiShellGetExecution(id string) {
ui.ShellCommand(
"Use following command to get script execution details",
"kubectl testkube scripts execution "+id,
)

ui.NL()
}

func uiShellWatchExecution(id string) {
ui.ShellCommand(
"or watch script execution until complete",
"Watch script execution until complete",
"kubectl testkube scripts watch "+id,
)

Expand Down
1 change: 0 additions & 1 deletion internal/app/api/v1/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func (s TestKubeAPI) GetExecutionHandler() fiber.Handler {
}
}

s.Log.Infow("get script execution request", "id", scriptID, "executionID", executionID)
s.Log.Debugw("get script execution request - debug", "execution", execution)

return c.JSON(execution)
Expand Down