Skip to content

Commit 4424df7

Browse files
authored
[Wf-Diagnostics] Introduce Diagnostics starter workflow as parent workflow to run diagnostics (#6310)
* wf setup * [Wf-Diagnostics] Introduce Diagnostics starter workflow as parent workflow to run diagnostics * Update parent_workflow.go * Update parent_workflow.go
1 parent 6594452 commit 4424df7

File tree

5 files changed

+81
-22
lines changed

5 files changed

+81
-22
lines changed

service/frontend/api/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (wh *WorkflowHandler) DiagnoseWorkflowExecution(ctx context.Context, reques
221221
diagnosticWorkflowID := fmt.Sprintf("%s-%s-%s", request.GetDomain(), wfExecution.GetWorkflowID(), wfExecution.GetRunID())
222222
diagnosticWorkflowDomain := "cadence-system"
223223

224-
diagnosticWorkflowInput := diagnostics.DiagnosticsWorkflowInput{
224+
diagnosticWorkflowInput := diagnostics.DiagnosticsStarterWorkflowInput{
225225
Domain: request.GetDomain(),
226226
WorkflowID: request.GetWorkflowExecution().GetWorkflowID(),
227227
RunID: request.GetWorkflowExecution().GetRunID(),
@@ -235,7 +235,7 @@ func (wh *WorkflowHandler) DiagnoseWorkflowExecution(ctx context.Context, reques
235235
Domain: diagnosticWorkflowDomain,
236236
WorkflowID: diagnosticWorkflowID,
237237
WorkflowType: &types.WorkflowType{
238-
Name: "diagnostics-workflow",
238+
Name: "diagnostics-starter-workflow",
239239
},
240240
TaskList: &types.TaskList{
241241
Name: "wf-diagnostics",

service/worker/diagnostics/module.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (w *dw) Start() error {
7878
}
7979
newWorker := worker.New(w.svcClient, common.SystemLocalDomainName, tasklist, workerOpts)
8080
newWorker.RegisterWorkflowWithOptions(w.DiagnosticsWorkflow, workflow.RegisterOptions{Name: diagnosticsWorkflow})
81+
newWorker.RegisterWorkflowWithOptions(w.DiagnosticsStarterWorkflow, workflow.RegisterOptions{Name: diagnosticsStarterWorkflow})
8182
newWorker.RegisterActivityWithOptions(w.retrieveExecutionHistory, activity.RegisterOptions{Name: retrieveWfExecutionHistoryActivity})
8283
newWorker.RegisterActivityWithOptions(w.identifyTimeouts, activity.RegisterOptions{Name: identifyTimeoutsActivity})
8384
newWorker.RegisterActivityWithOptions(w.rootCauseTimeouts, activity.RegisterOptions{Name: rootCauseTimeoutsActivity})
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// The MIT License (MIT)
2+
3+
// Copyright (c) 2017-2020 Uber Technologies Inc.
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
package diagnostics
24+
25+
import (
26+
"fmt"
27+
28+
"go.uber.org/cadence/workflow"
29+
)
30+
31+
const (
32+
diagnosticsStarterWorkflow = "diagnostics-starter-workflow"
33+
queryDiagnosticsReport = "query-diagnostics-report"
34+
)
35+
36+
type DiagnosticsStarterWorkflowInput struct {
37+
Domain string
38+
WorkflowID string
39+
RunID string
40+
}
41+
42+
type DiagnosticsStarterWorkflowResult struct {
43+
DiagnosticsResult *DiagnosticsWorkflowResult
44+
}
45+
46+
func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params DiagnosticsWorkflowInput) (*DiagnosticsStarterWorkflowResult, error) {
47+
var result DiagnosticsWorkflowResult
48+
err := workflow.SetQueryHandler(ctx, queryDiagnosticsReport, func() (DiagnosticsStarterWorkflowResult, error) {
49+
return DiagnosticsStarterWorkflowResult{DiagnosticsResult: &result}, nil
50+
})
51+
if err != nil {
52+
return nil, err
53+
}
54+
55+
err = workflow.ExecuteChildWorkflow(ctx, w.DiagnosticsWorkflow, DiagnosticsWorkflowInput{
56+
Domain: params.Domain,
57+
WorkflowID: params.WorkflowID,
58+
RunID: params.RunID,
59+
}).Get(ctx, &result)
60+
if err != nil {
61+
return nil, fmt.Errorf("Workflow Diagnostics: %w", err)
62+
}
63+
64+
return &DiagnosticsStarterWorkflowResult{DiagnosticsResult: &result}, nil
65+
}

service/worker/diagnostics/workflow.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ import (
3535
)
3636

3737
const (
38-
diagnosticsWorkflow = "diagnostics-workflow"
39-
tasklist = "diagnostics-wf-tasklist"
40-
queryDiagnosticsReport = "query-diagnostics-report"
38+
diagnosticsWorkflow = "diagnostics-workflow"
39+
tasklist = "diagnostics-wf-tasklist"
4140

4241
retrieveWfExecutionHistoryActivity = "retrieveWfExecutionHistory"
4342
identifyTimeoutsActivity = "identifyTimeouts"
@@ -82,13 +81,6 @@ func (w *dw) DiagnosticsWorkflow(ctx workflow.Context, params DiagnosticsWorkflo
8281
defer sw.Stop()
8382

8483
var timeoutsResult timeoutDiagnostics
85-
err := workflow.SetQueryHandler(ctx, queryDiagnosticsReport, func() (DiagnosticsWorkflowResult, error) {
86-
return DiagnosticsWorkflowResult{Timeouts: &timeoutsResult}, nil
87-
})
88-
if err != nil {
89-
return nil, err
90-
}
91-
9284
activityOptions := workflow.ActivityOptions{
9385
ScheduleToCloseTimeout: time.Second * 10,
9486
ScheduleToStartTimeout: time.Second * 5,
@@ -97,7 +89,7 @@ func (w *dw) DiagnosticsWorkflow(ctx workflow.Context, params DiagnosticsWorkflo
9789
activityCtx := workflow.WithActivityOptions(ctx, activityOptions)
9890

9991
var wfExecutionHistory *types.GetWorkflowExecutionHistoryResponse
100-
err = workflow.ExecuteActivity(activityCtx, w.retrieveExecutionHistory, retrieveExecutionHistoryInputParams{
92+
err := workflow.ExecuteActivity(activityCtx, w.retrieveExecutionHistory, retrieveExecutionHistoryInputParams{
10193
Domain: params.Domain,
10294
Execution: &types.WorkflowExecution{
10395
WorkflowID: params.WorkflowID,

service/worker/diagnostics/workflow_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (s *diagnosticsWorkflowTestSuite) SetupTest() {
6969
mockResource.Finish(s.T())
7070
})
7171

72+
s.workflowEnv.RegisterWorkflowWithOptions(s.dw.DiagnosticsStarterWorkflow, workflow.RegisterOptions{Name: diagnosticsStarterWorkflow})
7273
s.workflowEnv.RegisterWorkflowWithOptions(s.dw.DiagnosticsWorkflow, workflow.RegisterOptions{Name: diagnosticsWorkflow})
7374
s.workflowEnv.RegisterActivityWithOptions(s.dw.retrieveExecutionHistory, activity.RegisterOptions{Name: retrieveWfExecutionHistoryActivity})
7475
s.workflowEnv.RegisterActivityWithOptions(s.dw.identifyTimeouts, activity.RegisterOptions{Name: identifyTimeoutsActivity})
@@ -80,7 +81,7 @@ func (s *diagnosticsWorkflowTestSuite) TearDownTest() {
8081
}
8182

8283
func (s *diagnosticsWorkflowTestSuite) TestWorkflow() {
83-
params := &DiagnosticsWorkflowInput{
84+
params := &DiagnosticsStarterWorkflowInput{
8485
Domain: "test",
8586
WorkflowID: "123",
8687
RunID: "abc",
@@ -130,16 +131,16 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow() {
130131
s.workflowEnv.OnActivity(retrieveWfExecutionHistoryActivity, mock.Anything, mock.Anything).Return(nil, nil)
131132
s.workflowEnv.OnActivity(identifyTimeoutsActivity, mock.Anything, mock.Anything).Return(issues, nil)
132133
s.workflowEnv.OnActivity(rootCauseTimeoutsActivity, mock.Anything, mock.Anything).Return(rootCause, nil)
133-
s.workflowEnv.ExecuteWorkflow(diagnosticsWorkflow, params)
134+
s.workflowEnv.ExecuteWorkflow(diagnosticsStarterWorkflow, params)
134135
s.True(s.workflowEnv.IsWorkflowCompleted())
135-
var result DiagnosticsWorkflowResult
136+
var result DiagnosticsStarterWorkflowResult
136137
s.NoError(s.workflowEnv.GetWorkflowResult(&result))
137-
s.ElementsMatch(timeoutIssues, result.Timeouts.Issues)
138-
s.ElementsMatch(timeoutRootCause, result.Timeouts.RootCause)
138+
s.ElementsMatch(timeoutIssues, result.DiagnosticsResult.Timeouts.Issues)
139+
s.ElementsMatch(timeoutRootCause, result.DiagnosticsResult.Timeouts.RootCause)
139140

140141
queriedResult := s.queryDiagnostics()
141-
s.ElementsMatch(queriedResult.Timeouts.Issues, result.Timeouts.Issues)
142-
s.ElementsMatch(queriedResult.Timeouts.RootCause, result.Timeouts.RootCause)
142+
s.ElementsMatch(queriedResult.DiagnosticsResult.Timeouts.Issues, result.DiagnosticsResult.Timeouts.Issues)
143+
s.ElementsMatch(queriedResult.DiagnosticsResult.Timeouts.RootCause, result.DiagnosticsResult.Timeouts.RootCause)
143144
}
144145

145146
func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
@@ -158,11 +159,11 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
158159
s.EqualError(s.workflowEnv.GetWorkflowError(), errExpected.Error())
159160
}
160161

161-
func (s *diagnosticsWorkflowTestSuite) queryDiagnostics() DiagnosticsWorkflowResult {
162+
func (s *diagnosticsWorkflowTestSuite) queryDiagnostics() DiagnosticsStarterWorkflowResult {
162163
queryFuture, err := s.workflowEnv.QueryWorkflow(queryDiagnosticsReport)
163164
s.NoError(err)
164165

165-
var result DiagnosticsWorkflowResult
166+
var result DiagnosticsStarterWorkflowResult
166167
err = queryFuture.Get(&result)
167168
s.NoError(err)
168169
return result

0 commit comments

Comments
 (0)