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

Fix continue as new validation #3845

Merged
merged 2 commits into from
Jan 26, 2023
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
34 changes: 28 additions & 6 deletions service/history/commandChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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(
Expand Down
36 changes: 36 additions & 0 deletions service/history/commandChecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down