Skip to content

[Wf-Diagnostics] retrieve workflow execution history within issue identification activity #6607

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

Merged
merged 1 commit into from
Jan 10, 2025
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
24 changes: 10 additions & 14 deletions service/worker/diagnostics/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,26 @@ const (
WfDiagnosticsAppName = "workflow-diagnostics"
)

type retrieveExecutionHistoryInputParams struct {
Domain string
type identifyIssuesParams struct {
Execution *types.WorkflowExecution
Domain string
}

func (w *dw) retrieveExecutionHistory(ctx context.Context, info retrieveExecutionHistoryInputParams) (*types.GetWorkflowExecutionHistoryResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downside of this change is that you will have to download history multiple times for all diagnostics. If performance considerations arise, we might need to work on an external storage option to pull it from the DB once and then only download it from the storage (which should be faster).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All issue checks are done after the history retrieval so its ok with the current req but I do agree that if we have to share it amongst other modules we need ext storage

func (w *dw) identifyIssues(ctx context.Context, info identifyIssuesParams) ([]invariant.InvariantCheckResult, error) {
result := make([]invariant.InvariantCheckResult, 0)

frontendClient := w.clientBean.GetFrontendClient()
return frontendClient.GetWorkflowExecutionHistory(ctx, &types.GetWorkflowExecutionHistoryRequest{
history, err := frontendClient.GetWorkflowExecutionHistory(ctx, &types.GetWorkflowExecutionHistoryRequest{
Domain: info.Domain,
Execution: info.Execution,
})
}

type identifyIssuesParams struct {
History *types.GetWorkflowExecutionHistoryResponse
Domain string
}

func (w *dw) identifyIssues(ctx context.Context, info identifyIssuesParams) ([]invariant.InvariantCheckResult, error) {
result := make([]invariant.InvariantCheckResult, 0)
if err != nil {
return nil, err
}

for _, inv := range w.invariants {
issues, err := inv.Check(ctx, invariant.InvariantCheckInput{
WorkflowExecutionHistory: info.History,
WorkflowExecutionHistory: history,
Domain: info.Domain,
})
if err != nil {
Expand Down
18 changes: 4 additions & 14 deletions service/worker/diagnostics/activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ const (
timeUnit = time.Second
)

func Test__retrieveExecutionHistory(t *testing.T) {
dwtest := testDiagnosticWorkflow(t)
result, err := dwtest.retrieveExecutionHistory(context.Background(), retrieveExecutionHistoryInputParams{
Domain: "test",
Execution: &types.WorkflowExecution{
WorkflowID: "123",
RunID: "abc",
},
})
require.NoError(t, err)
require.Equal(t, testWorkflowExecutionHistoryResponse(), result)
}

func Test__identifyIssues(t *testing.T) {
dwtest := testDiagnosticWorkflow(t)
actMetadata := failure.FailureMetadata{
Expand Down Expand Up @@ -100,7 +87,10 @@ func Test__identifyIssues(t *testing.T) {
Metadata: retryMetadataInBytes,
},
}
result, err := dwtest.identifyIssues(context.Background(), identifyIssuesParams{History: testWorkflowExecutionHistoryResponse()})
result, err := dwtest.identifyIssues(context.Background(), identifyIssuesParams{Execution: &types.WorkflowExecution{
WorkflowID: "123",
RunID: "abc",
}})
require.NoError(t, err)
require.Equal(t, expectedResult, result)
}
Expand Down
1 change: 0 additions & 1 deletion service/worker/diagnostics/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (w *dw) Start() error {
newWorker := worker.New(w.svcClient, common.SystemLocalDomainName, tasklist, workerOpts)
newWorker.RegisterWorkflowWithOptions(w.DiagnosticsWorkflow, workflow.RegisterOptions{Name: diagnosticsWorkflow})
newWorker.RegisterWorkflowWithOptions(w.DiagnosticsStarterWorkflow, workflow.RegisterOptions{Name: diagnosticsStarterWorkflow})
newWorker.RegisterActivityWithOptions(w.retrieveExecutionHistory, activity.RegisterOptions{Name: retrieveWfExecutionHistoryActivity})
newWorker.RegisterActivityWithOptions(w.identifyIssues, activity.RegisterOptions{Name: identifyIssuesActivity})
newWorker.RegisterActivityWithOptions(w.rootCauseIssues, activity.RegisterOptions{Name: rootCauseIssuesActivity})
newWorker.RegisterActivityWithOptions(w.emitUsageLogs, activity.RegisterOptions{Name: emitUsageLogsActivity})
Expand Down
17 changes: 4 additions & 13 deletions service/worker/diagnostics/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,14 @@ func (w *dw) DiagnosticsWorkflow(ctx workflow.Context, params DiagnosticsWorkflo
StartToCloseTimeout: time.Second * 5,
}
activityCtx := workflow.WithActivityOptions(ctx, activityOptions)
timeoutsResult.Runbooks = []string{linkToTimeoutsRunbook}

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

timeoutsResult.Runbooks = []string{linkToTimeoutsRunbook}

err = workflow.ExecuteActivity(activityCtx, w.identifyIssues, identifyIssuesParams{
History: wfExecutionHistory,
Domain: params.Domain,
},
Domain: params.Domain,
}).Get(ctx, &checkResult)
if err != nil {
return nil, fmt.Errorf("IdentifyIssues: %w", err)
Expand Down
3 changes: 0 additions & 3 deletions service/worker/diagnostics/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (s *diagnosticsWorkflowTestSuite) SetupTest() {

s.workflowEnv.RegisterWorkflowWithOptions(s.dw.DiagnosticsStarterWorkflow, workflow.RegisterOptions{Name: diagnosticsStarterWorkflow})
s.workflowEnv.RegisterWorkflowWithOptions(s.dw.DiagnosticsWorkflow, workflow.RegisterOptions{Name: diagnosticsWorkflow})
s.workflowEnv.RegisterActivityWithOptions(s.dw.retrieveExecutionHistory, activity.RegisterOptions{Name: retrieveWfExecutionHistoryActivity})
s.workflowEnv.RegisterActivityWithOptions(s.dw.identifyIssues, activity.RegisterOptions{Name: identifyIssuesActivity})
s.workflowEnv.RegisterActivityWithOptions(s.dw.rootCauseIssues, activity.RegisterOptions{Name: rootCauseIssuesActivity})
s.workflowEnv.RegisterActivityWithOptions(s.dw.emitUsageLogs, activity.RegisterOptions{Name: emitUsageLogsActivity})
Expand Down Expand Up @@ -133,7 +132,6 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow() {
PollersMetadata: &timeout.PollersMetadata{TaskListBacklog: taskListBacklog},
},
}
s.workflowEnv.OnActivity(retrieveWfExecutionHistoryActivity, mock.Anything, mock.Anything).Return(nil, nil)
s.workflowEnv.OnActivity(identifyIssuesActivity, mock.Anything, mock.Anything).Return(issues, nil)
s.workflowEnv.OnActivity(rootCauseIssuesActivity, mock.Anything, mock.Anything).Return(rootCause, nil)
s.workflowEnv.OnActivity(emitUsageLogsActivity, mock.Anything, mock.Anything).Return(nil)
Expand All @@ -157,7 +155,6 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
}
mockErr := errors.New("mockErr")
errExpected := fmt.Errorf("IdentifyIssues: %w", mockErr)
s.workflowEnv.OnActivity(retrieveWfExecutionHistoryActivity, mock.Anything, mock.Anything).Return(nil, nil)
s.workflowEnv.OnActivity(identifyIssuesActivity, mock.Anything, mock.Anything).Return(nil, mockErr)
s.workflowEnv.ExecuteWorkflow(diagnosticsWorkflow, params)
s.True(s.workflowEnv.IsWorkflowCompleted())
Expand Down
Loading