Skip to content

Commit

Permalink
[Wf-Diagnostics] generate random wf-id for diagnostics when input bas…
Browse files Browse the repository at this point in the history
…ed ID is too long
  • Loading branch information
sankari165 committed Jan 28, 2025
1 parent 7d3786d commit c9deeac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
15 changes: 14 additions & 1 deletion service/frontend/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,22 @@ func (wh *WorkflowHandler) DiagnoseWorkflowExecution(ctx context.Context, reques
return nil, validate.ErrExecutionNotSet
}

scope := getMetricsScopeWithDomain(metrics.FrontendPollForActivityTaskScope, request, wh.GetMetricsClient()).Tagged(metrics.GetContextTags(ctx)...)

wfExecution := request.GetWorkflowExecution()
diagnosticWorkflowID := fmt.Sprintf("%s-%s-%s", request.GetDomain(), wfExecution.GetWorkflowID(), wfExecution.GetRunID())
diagnosticWorkflowDomain := "cadence-system"
diagnosticWorkflowID := fmt.Sprintf("%s-%s-%s", request.GetDomain(), wfExecution.GetWorkflowID(), wfExecution.GetRunID())
if !common.IsValidIDLength(
diagnosticWorkflowID,
scope,
wh.config.MaxIDLengthWarnLimit(),
wh.config.WorkflowIDMaxLength(request.GetDomain()),
metrics.CadenceErrWorkflowIDExceededWarnLimit,
request.GetDomain(),
wh.GetLogger(),
tag.IDTypeWorkflowID) {
diagnosticWorkflowID = uuid.New().String()
}

diagnosticWorkflowInput := diagnostics.DiagnosticsStarterWorkflowInput{
Domain: request.GetDomain(),
Expand Down
29 changes: 29 additions & 0 deletions service/frontend/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,35 @@ func (s *workflowHandlerSuite) TestDiagnoseWorkflowExecution_Success() {
s.Equal(resp, result)
}

func (s *workflowHandlerSuite) TestDiagnoseWorkflowExecution_Failed_InvalidID() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))

req := &types.DiagnoseWorkflowExecutionRequest{
Domain: testDomain,
WorkflowExecution: &types.WorkflowExecution{
WorkflowID: testWorkflowID,
RunID: testRunID,
},
Identity: "",
}
diagnosticWfDomain := "cadence-system"
diagnosticWfRunID := "123"
resp := &types.DiagnoseWorkflowExecutionResponse{
Domain: diagnosticWfDomain,
DiagnosticWorkflowExecution: &types.WorkflowExecution{
RunID: diagnosticWfRunID,
},
}

s.mockDomainCache.EXPECT().GetDomainID(diagnosticWfDomain).Return(s.testDomainID, nil).Times(2)
wh.config.WorkflowIDMaxLength = dc.GetIntPropertyFilteredByDomain(36)
s.mockHistoryClient.EXPECT().StartWorkflowExecution(gomock.Any(), gomock.Any()).Return(&types.StartWorkflowExecutionResponse{RunID: diagnosticWfRunID}, nil)
result, err := wh.DiagnoseWorkflowExecution(context.Background(), req)
s.NoError(err)
s.Equal(resp.GetDiagnosticWorkflowExecution().GetRunID(), result.GetDiagnosticWorkflowExecution().GetRunID())
s.Equal(resp.GetDomain(), result.GetDomain())
}

func (s *workflowHandlerSuite) TestDiagnoseWorkflowExecution_Failed_RequestNotSet() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))

Expand Down

0 comments on commit c9deeac

Please sign in to comment.