diff --git a/service/history/commandChecker.go b/service/history/commandChecker.go index d0f28da67f6..65496daf877 100644 --- a/service/history/commandChecker.go +++ b/service/history/commandChecker.go @@ -643,9 +643,30 @@ func (v *commandAttrValidator) validateContinueAsNewWorkflowExecutionAttributes( attributes.WorkflowTaskTimeout = timestamp.DurationPtr(timestamp.DurationValue(executionInfo.DefaultWorkflowTaskTimeout)) } + attributes.WorkflowRunTimeout = timestamp.DurationPtr( + common.OverrideWorkflowRunTimeout( + timestamp.DurationValue(attributes.GetWorkflowRunTimeout()), + timestamp.DurationValue(executionInfo.GetWorkflowExecutionTimeout()), + ), + ) + + attributes.WorkflowTaskTimeout = timestamp.DurationPtr( + common.OverrideWorkflowTaskTimeout( + namespace.String(), + timestamp.DurationValue(attributes.GetWorkflowTaskTimeout()), + timestamp.DurationValue(attributes.GetWorkflowRunTimeout()), + v.config.DefaultWorkflowTaskTimeout, + ), + ) + + if err := v.validateWorkflowRetryPolicy(namespace, attributes.RetryPolicy); err != nil { + return failedCause, err + } + if err = v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), namespace.String(), visibilityIndexName); err != nil { return enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES, err } + return enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED, nil } @@ -703,7 +724,7 @@ func (v *commandAttrValidator) validateStartChildExecutionAttributes( return failedCause, serviceerror.NewInvalidArgument("Invalid WorkflowTaskTimeout.") } - if err := v.validateWorkflowRetryPolicy(attributes); err != nil { + if err := v.validateWorkflowRetryPolicy(namespace.Name(attributes.GetNamespace()), attributes.RetryPolicy); err != nil { return failedCause, err } @@ -789,17 +810,18 @@ func (v *commandAttrValidator) validateActivityRetryPolicy( } func (v *commandAttrValidator) validateWorkflowRetryPolicy( - attributes *commandpb.StartChildWorkflowExecutionCommandAttributes, + namespaceName namespace.Name, + retryPolicy *commonpb.RetryPolicy, ) error { - if attributes.RetryPolicy == nil { + if retryPolicy == nil { // By default, if the user does not explicitly set a retry policy for a Child Workflow, do not perform any retries. return nil } // Otherwise, for any unset fields on the retry policy, set with defaults - defaultWorkflowRetrySettings := common.FromConfigToDefaultRetrySettings(v.getDefaultWorkflowRetrySettings(attributes.GetNamespace())) - common.EnsureRetryPolicyDefaults(attributes.RetryPolicy, defaultWorkflowRetrySettings) - return common.ValidateRetryPolicy(attributes.RetryPolicy) + defaultWorkflowRetrySettings := common.FromConfigToDefaultRetrySettings(v.getDefaultWorkflowRetrySettings(namespaceName.String())) + common.EnsureRetryPolicyDefaults(retryPolicy, defaultWorkflowRetrySettings) + return common.ValidateRetryPolicy(retryPolicy) } func (v *commandAttrValidator) validateCrossNamespaceCall( diff --git a/service/history/commandChecker_test.go b/service/history/commandChecker_test.go index d8e487dc48f..38873a00c03 100644 --- a/service/history/commandChecker_test.go +++ b/service/history/commandChecker_test.go @@ -119,6 +119,7 @@ func (s *commandAttrValidatorSuite) SetupTest() { DefaultActivityRetryPolicy: dynamicconfig.GetMapPropertyFnWithNamespaceFilter(common.GetDefaultRetryPolicyConfigOptions()), DefaultWorkflowRetryPolicy: dynamicconfig.GetMapPropertyFnWithNamespaceFilter(common.GetDefaultRetryPolicyConfigOptions()), EnableCrossNamespaceCommands: dynamicconfig.GetBoolPropertyFn(true), + DefaultWorkflowTaskTimeout: dynamicconfig.GetDurationPropertyFnFilteredByNamespace(common.DefaultWorkflowTaskTimeout), } s.validator = newCommandAttrValidator( s.mockNamespaceCache, @@ -213,6 +214,41 @@ func (s *commandAttrValidatorSuite) TestValidateUpsertWorkflowSearchAttributes() s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED, fc) } +func (s *commandAttrValidatorSuite) TestValidateContinueAsNewWorkflowExecutionAttributes() { + executionTimeout := time.Hour + workflowTypeName := "workflowType" + taskQueue := "taskQueue" + + attributes := &commandpb.ContinueAsNewWorkflowExecutionCommandAttributes{ + // workflow type name and task queue name should be retrieved from existing workflow info + + // WorkflowRunTimeout should be shorten to execution timeout + WorkflowRunTimeout: timestamp.DurationPtr(executionTimeout * 2), + // WorkflowTaskTimeout should be shorten to max workflow task timeout + WorkflowTaskTimeout: timestamp.DurationPtr(common.MaxWorkflowTaskStartToCloseTimeout * 2), + } + + executionInfo := &persistencespb.WorkflowExecutionInfo{ + WorkflowTypeName: workflowTypeName, + TaskQueue: taskQueue, + WorkflowExecutionTimeout: timestamp.DurationPtr(executionTimeout), + } + + fc, err := s.validator.validateContinueAsNewWorkflowExecutionAttributes( + tests.Namespace, + attributes, + executionInfo, + "index-name", + ) + s.NoError(err) + s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED, fc) + + s.Equal(workflowTypeName, attributes.GetWorkflowType().GetName()) + s.Equal(taskQueue, attributes.GetTaskQueue().GetName()) + s.Equal(executionTimeout, *attributes.GetWorkflowRunTimeout()) + s.Equal(common.MaxWorkflowTaskStartToCloseTimeout, *attributes.GetWorkflowTaskTimeout()) +} + func (s *commandAttrValidatorSuite) TestValidateModifyWorkflowProperties() { namespace := namespace.Name("tests.Namespace") var attributes *commandpb.ModifyWorkflowPropertiesCommandAttributes