Skip to content

Commit

Permalink
[Wf-Diagnostics] Failure of usage logs emission should'nt fail the wo…
Browse files Browse the repository at this point in the history
…rkflow
  • Loading branch information
sankari165 committed Jan 27, 2025
1 parent cd71f46 commit da7c69e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion service/worker/diagnostics/parent_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package diagnostics

import (
"fmt"
"github.com/uber/cadence/common/log/tag"
"time"

"go.uber.org/cadence/workflow"
Expand Down Expand Up @@ -85,6 +86,7 @@ func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params Diagnostics
workflowResult.DiagnosticsCompleted = true
childWfEnd = workflow.Now(ctx)

info := workflow.GetInfo(ctx)
activityOptions := workflow.ActivityOptions{
ScheduleToCloseTimeout: time.Second * 10,
ScheduleToStartTimeout: time.Second * 5,
Expand All @@ -103,7 +105,10 @@ func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params Diagnostics
DiagnosticsEndTime: childWfEnd,
}).Get(ctx, nil)
if err != nil {
return nil, fmt.Errorf("EmitUsageLogs: %w", err)
w.logger.Error("wf-diagnostics usage logs emission failed",
tag.Error(err),
tag.WorkflowID(info.WorkflowExecution.ID),
tag.WorkflowRunID(info.WorkflowExecution.RunID))
}

return &workflowResult, nil
Expand Down
16 changes: 16 additions & 0 deletions service/worker/diagnostics/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (s *diagnosticsWorkflowTestSuite) SetupTest() {
mockResource := resource.NewTest(s.T(), controller, metrics.Worker)
publicClient := mockResource.GetSDKClient()
s.dw = &dw{
logger: mockResource.GetLogger(),
svcClient: publicClient,
clientBean: mockResource.ClientBean,
metricsClient: mockResource.GetMetricsClient(),
Expand Down Expand Up @@ -164,6 +165,21 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
s.EqualError(s.workflowEnv.GetWorkflowError(), errExpected.Error())
}

func (s *diagnosticsWorkflowTestSuite) TestWorkflow_NoErrorIfEmitLogsActivityFails() {
params := &DiagnosticsWorkflowInput{
Domain: "test",
WorkflowID: "123",
RunID: "abc",
}
mockErr := errors.New("mockErr")
s.workflowEnv.OnActivity(identifyIssuesActivity, mock.Anything, mock.Anything).Return(nil, nil)
s.workflowEnv.OnActivity(rootCauseIssuesActivity, mock.Anything, mock.Anything).Return(nil, nil)
s.workflowEnv.OnActivity(emitUsageLogsActivity, mock.Anything, mock.Anything).Return(mockErr)
s.workflowEnv.ExecuteWorkflow(diagnosticsStarterWorkflow, params)
s.True(s.workflowEnv.IsWorkflowCompleted())
s.NoError(s.workflowEnv.GetWorkflowError())
}

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

0 comments on commit da7c69e

Please sign in to comment.