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

[Wf-Diagnostics] Diagnose workflow execution from cli #6271

Merged
merged 1 commit into from
Sep 9, 2024
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
13 changes: 13 additions & 0 deletions tools/cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,19 @@ func (s *cliAppSuite) TestRestartWorkflow_Failed() {
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDiagnoseWorkflow() {
resp := &types.DiagnoseWorkflowExecutionResponse{Domain: "test", DiagnosticWorkflowExecution: &types.WorkflowExecution{WorkflowID: "123", RunID: uuid.New()}}
s.serverFrontendClient.EXPECT().DiagnoseWorkflowExecution(gomock.Any(), gomock.Any()).Return(resp, nil).Times(1)
err := s.app.Run([]string{"", "--do", domainName, "workflow", "diagnose", "-w", "wid", "-r", "rid"})
s.Nil(err)
}

func (s *cliAppSuite) TestDiagnoseWorkflow_Failed() {
s.serverFrontendClient.EXPECT().DiagnoseWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil, &types.BadRequestError{"faked error"})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "workflow", "diagnose", "-w", "wid", "-r", "rid"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestStartWorkflow() {
resp := &types.StartWorkflowExecutionResponse{RunID: uuid.New()}
s.serverFrontendClient.EXPECT().StartWorkflowExecution(gomock.Any(), gomock.Any()).Return(resp, nil).Times(2)
Expand Down
7 changes: 7 additions & 0 deletions tools/cli/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ func newWorkflowCommands() []cli.Command {
Flags: flagsForExecution,
Action: RestartWorkflow,
},
{
Name: "diagnose",
Aliases: []string{"diag"},
Usage: "diagnoses a previous workflow execution",
Flags: flagsForExecution,
Action: DiagnoseWorkflow,
},
{
Name: "activity",
Aliases: []string{"act"},
Expand Down
31 changes: 31 additions & 0 deletions tools/cli/workflow_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,37 @@ func RestartWorkflow(c *cli.Context) {
}
}

// DiagnoseWorkflow diagnoses a workflow execution
func DiagnoseWorkflow(c *cli.Context) {
wfClient := getWorkflowClient(c)

domain := getRequiredGlobalOption(c, FlagDomain)
wid := getRequiredOption(c, FlagWorkflowID)
rid := getRequiredOption(c, FlagRunID)

ctx, cancel := newContext(c)
defer cancel()
resp, err := wfClient.DiagnoseWorkflowExecution(
ctx,
&types.DiagnoseWorkflowExecutionRequest{
Domain: domain,
WorkflowExecution: &types.WorkflowExecution{
WorkflowID: wid,
RunID: rid,
},
Identity: getCliIdentity(),
},
)

if err != nil {
ErrorAndExit("Diagnose workflow failed.", err)
} else {
sankari165 marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println("Workflow diagnosis started. Query the diagnostic workflow to get diagnostics report.")
fmt.Println("============Diagnostic Workflow details============")
fmt.Printf("Domain: %s, Workflow Id: %s, Run Id: %s\n", resp.GetDomain(), resp.GetDiagnosticWorkflowExecution().GetWorkflowID(), resp.GetDiagnosticWorkflowExecution().GetRunID())
}
}

// ShowHistory shows the history of given workflow execution based on workflowID and runID.
func ShowHistory(c *cli.Context) {
wid := getRequiredOption(c, FlagWorkflowID)
Expand Down
Loading