diff --git a/tools/cli/app_test.go b/tools/cli/app_test.go index da97e857044..e3b951719ce 100644 --- a/tools/cli/app_test.go +++ b/tools/cli/app_test.go @@ -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) diff --git a/tools/cli/workflow.go b/tools/cli/workflow.go index f464fc4b580..8291c4dcf0b 100644 --- a/tools/cli/workflow.go +++ b/tools/cli/workflow.go @@ -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"}, diff --git a/tools/cli/workflow_commands.go b/tools/cli/workflow_commands.go index 65e9d5cc5a6..ae8e6ca5149 100644 --- a/tools/cli/workflow_commands.go +++ b/tools/cli/workflow_commands.go @@ -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 { + 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)