Skip to content

Commit

Permalink
[Wf-Diagnostics] Diagnose workflow execution from cli (#6271)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankari165 authored Sep 9, 2024
1 parent 08dba4d commit 0a6ad93
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
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 {
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

0 comments on commit 0a6ad93

Please sign in to comment.