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] Set query handler for diagnostics workflow to provide result #6273

Merged
merged 2 commits into from
Sep 10, 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
33 changes: 21 additions & 12 deletions service/worker/diagnostics/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
)

const (
diagnosticsWorkflow = "diagnostics-workflow"
tasklist = "wf-diagnostics"
diagnosticsWorkflow = "diagnostics-workflow"
tasklist = "diagnostics-wf-tasklist"
queryDiagnosticsReport = "query-diagnostics-report"

retrieveWfExecutionHistoryActivity = "retrieveWfExecutionHistory"
identifyTimeoutsActivity = "identifyTimeouts"
Expand All @@ -53,7 +54,15 @@
Runbooks []string
}

func (w *dw) DiagnosticsWorkflow(ctx workflow.Context, params DiagnosticsWorkflowInput) (DiagnosticsWorkflowResult, error) {
func (w *dw) DiagnosticsWorkflow(ctx workflow.Context, params DiagnosticsWorkflowInput) (*DiagnosticsWorkflowResult, error) {
var result DiagnosticsWorkflowResult
err := workflow.SetQueryHandler(ctx, queryDiagnosticsReport, func() (DiagnosticsWorkflowResult, error) {
return result, nil
})
if err != nil {
return nil, err

Check warning on line 63 in service/worker/diagnostics/workflow.go

View check run for this annotation

Codecov / codecov/patch

service/worker/diagnostics/workflow.go#L63

Added line #L63 was not covered by tests
}

activityOptions := workflow.ActivityOptions{
ScheduleToCloseTimeout: time.Second * 10,
ScheduleToStartTimeout: time.Second * 5,
Expand All @@ -62,24 +71,27 @@
activityCtx := workflow.WithActivityOptions(ctx, activityOptions)

var wfExecutionHistory *types.GetWorkflowExecutionHistoryResponse
err := workflow.ExecuteActivity(activityCtx, w.retrieveExecutionHistory, retrieveExecutionHistoryInputParams{
err = workflow.ExecuteActivity(activityCtx, w.retrieveExecutionHistory, retrieveExecutionHistoryInputParams{
Domain: params.Domain,
Execution: &types.WorkflowExecution{
WorkflowID: params.WorkflowID,
RunID: params.RunID,
}}).Get(ctx, &wfExecutionHistory)
if err != nil {
return DiagnosticsWorkflowResult{}, fmt.Errorf("RetrieveExecutionHistory: %w", err)
return nil, fmt.Errorf("RetrieveExecutionHistory: %w", err)

Check warning on line 81 in service/worker/diagnostics/workflow.go

View check run for this annotation

Codecov / codecov/patch

service/worker/diagnostics/workflow.go#L81

Added line #L81 was not covered by tests
}

result.Runbooks = []string{linkToTimeoutsRunbook}

var checkResult []invariants.InvariantCheckResult
err = workflow.ExecuteActivity(activityCtx, w.identifyTimeouts, identifyTimeoutsInputParams{
History: wfExecutionHistory,
Domain: params.Domain,
}).Get(ctx, &checkResult)
if err != nil {
return DiagnosticsWorkflowResult{}, fmt.Errorf("IdentifyTimeouts: %w", err)
return nil, fmt.Errorf("IdentifyTimeouts: %w", err)
}
result.Issues = checkResult

var rootCauseResult []invariants.InvariantRootCauseResult
err = workflow.ExecuteActivity(activityCtx, w.rootCauseTimeouts, rootCauseTimeoutsParams{
Expand All @@ -88,12 +100,9 @@
Issues: checkResult,
}).Get(ctx, &rootCauseResult)
if err != nil {
return DiagnosticsWorkflowResult{}, fmt.Errorf("RootCauseTimeouts: %w", err)
return nil, fmt.Errorf("RootCauseTimeouts: %w", err)

Check warning on line 103 in service/worker/diagnostics/workflow.go

View check run for this annotation

Codecov / codecov/patch

service/worker/diagnostics/workflow.go#L103

Added line #L103 was not covered by tests
}
result.RootCause = rootCauseResult

return DiagnosticsWorkflowResult{
Issues: checkResult,
RootCause: rootCauseResult,
Runbooks: []string{linkToTimeoutsRunbook},
}, nil
return &result, nil
}
14 changes: 14 additions & 0 deletions service/worker/diagnostics/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow() {
s.NoError(s.workflowEnv.GetWorkflowResult(&result))
s.ElementsMatch(issues, result.Issues)
s.ElementsMatch(rootCause, result.RootCause)

queriedResult := s.queryDiagnostics()
s.ElementsMatch(queriedResult.Issues, result.Issues)
s.ElementsMatch(queriedResult.RootCause, result.RootCause)
}

func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
Expand All @@ -139,3 +143,13 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
s.Error(s.workflowEnv.GetWorkflowError())
s.EqualError(s.workflowEnv.GetWorkflowError(), errExpected.Error())
}

func (s *diagnosticsWorkflowTestSuite) queryDiagnostics() DiagnosticsWorkflowResult {
queryFuture, err := s.workflowEnv.QueryWorkflow(queryDiagnosticsReport)
s.NoError(err)

var result DiagnosticsWorkflowResult
err = queryFuture.Get(&result)
s.NoError(err)
return result
}
Loading