Repository navigation
Retain original throughput starts across iteration retries #539
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
Open
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package loadgen | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/temporalio/omes/loadgen/kitchensink" | ||
| "go.temporal.io/api/serviceerror" | ||
| "go.temporal.io/sdk/client" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| type startInputsClient struct { | ||
| client.Client | ||
| ids []string | ||
| inputs []int32 | ||
| } | ||
|
|
||
| func (c *startInputsClient) ExecuteWorkflow(ctx context.Context, opts client.StartWorkflowOptions, _ interface{}, args ...interface{}) (client.WorkflowRun, error) { | ||
| c.ids = append(c.ids, opts.ID) | ||
| c.inputs = append(c.inputs, args[0].(*kitchensink.WorkflowInput).ExpectedSignalCount) | ||
| if len(c.ids) == 1 { | ||
| return nil, serviceerror.NewDeadlineExceeded("start response unavailable") | ||
| } | ||
| return completedOriginalRun{id: opts.ID}, nil | ||
| } | ||
|
|
||
| type completedOriginalRun struct { | ||
| client.WorkflowRun | ||
| id string | ||
| } | ||
|
|
||
| func (r completedOriginalRun) GetID() string { return r.id } | ||
| func (r completedOriginalRun) GetRunID() string { return "original-run" } | ||
| func (r completedOriginalRun) Get(context.Context, interface{}) error { return nil } | ||
|
|
||
| func TestKitchenSinkOriginalStartFreezesRetryConstruction(t *testing.T) { | ||
| cl := &startInputsClient{} | ||
| generation := int32(0) | ||
| executor := KitchenSinkExecutor{ | ||
| TestInput: &kitchensink.TestInput{ | ||
| WorkflowInput: &kitchensink.WorkflowInput{}, | ||
| }, | ||
| UpdateWorkflowOptions: func(ctx context.Context, r *Run, o *KitchenSinkWorkflowOptions) error { | ||
| generation++ | ||
| o.StartOptions.ID = uuid.NewString() | ||
| o.Params.WorkflowInput.ExpectedSignalCount = generation | ||
| return nil | ||
| }, | ||
| } | ||
| executor.RecoverOriginalStart = true | ||
|
|
||
| info := ScenarioInfo{ | ||
| Client: cl, | ||
| Namespace: "default", | ||
| RunID: "frozen", | ||
| ExecutionID: "same", | ||
| Logger: zap.NewNop().Sugar(), | ||
| MetricsHandler: client.MetricsNopHandler, | ||
| Configuration: RunConfiguration{ | ||
| Iterations: 1, | ||
| MaxConcurrent: 1, | ||
| MaxIterationAttempts: 2, | ||
| DoNotRegisterSearchAttributes: true, | ||
| }, | ||
| } | ||
| require.NoError(t, executor.Run(t.Context(), info)) | ||
| require.Len(t, cl.ids, 2) | ||
| require.Equal(t, cl.ids[0], cl.ids[1]) | ||
| require.Equal(t, []int32{1, 1}, cl.inputs) | ||
| } | ||
|
|
||
| func TestKitchenSinkOriginalStartRejectsClientSequence(t *testing.T) { | ||
| for _, configuredByCallback := range []bool{false, true} { | ||
| t.Run(fmt.Sprintf("configured_by_callback=%t", configuredByCallback), func(t *testing.T) { | ||
| cl := &startInputsClient{} | ||
| seq := &kitchensink.ClientSequence{ActionSets: []*kitchensink.ClientActionSet{{}}} | ||
| executor := KitchenSinkExecutor{ | ||
| RecoverOriginalStart: true, | ||
| TestInput: &kitchensink.TestInput{WorkflowInput: &kitchensink.WorkflowInput{}}, | ||
| } | ||
| if configuredByCallback { | ||
| executor.UpdateWorkflowOptions = func(_ context.Context, _ *Run, o *KitchenSinkWorkflowOptions) error { | ||
| o.Params.ClientSequence = seq | ||
| return nil | ||
| } | ||
| } else { | ||
| executor.TestInput.ClientSequence = seq | ||
| } | ||
| info := ScenarioInfo{ | ||
| Client: cl, | ||
| Namespace: "default", | ||
| Logger: zap.NewNop().Sugar(), | ||
| MetricsHandler: client.MetricsNopHandler, | ||
| Configuration: RunConfiguration{ | ||
| Iterations: 1, | ||
| MaxConcurrent: 1, | ||
| DoNotRegisterSearchAttributes: true, | ||
| }, | ||
| } | ||
| err := executor.Run(t.Context(), info) | ||
| require.ErrorContains(t, err, "original start recovery does not support client sequences") | ||
| require.Empty(t, cl.ids, "invalid recovery must be rejected before starting a workflow") | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package kitchensink | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/google/uuid" | ||
| enumspb "go.temporal.io/api/enums/v1" | ||
| "go.temporal.io/sdk/client" | ||
| "go.temporal.io/sdk/converter" | ||
| "google.golang.org/protobuf/proto" | ||
| ) | ||
|
|
||
| const startIntentMemo = "omes.original-start" | ||
|
|
||
| type originalStart struct { | ||
| intent string | ||
| action *WithStartClientAction | ||
| update client.WorkflowUpdateHandle | ||
| } | ||
|
|
||
| func (e *ClientActionsExecutor) freezeStart(action *WithStartClientAction) { | ||
| e.originalStart = &originalStart{intent: uuid.NewString()} | ||
| memo := make(map[string]interface{}, len(e.WorkflowOptions.Memo)+1) | ||
| for k, v := range e.WorkflowOptions.Memo { | ||
| memo[k] = v | ||
| } | ||
| memo[startIntentMemo] = e.originalStart.intent | ||
| e.WorkflowOptions.Memo = memo | ||
| e.WorkflowOptions.WorkflowExecutionErrorWhenAlreadyStarted = true | ||
| e.WorkflowOptions.WorkflowIDReusePolicy = enumspb.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE | ||
| e.WorkflowOptions.WorkflowIDConflictPolicy = enumspb.WORKFLOW_ID_CONFLICT_POLICY_FAIL | ||
| if upd := action.GetDoUpdate(); upd != nil && upd.UpdateId == "" { | ||
| upd.UpdateId = uuid.NewString() | ||
| } | ||
| if action != nil { | ||
| e.originalStart.action = proto.Clone(action).(*WithStartClientAction) | ||
| } | ||
| } | ||
|
|
||
| func (e *ClientActionsExecutor) attachOriginalStart(ctx context.Context, runID string) error { | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
| history := e.Client.GetWorkflowHistory(ctx, e.WorkflowOptions.ID, runID, false, enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT) | ||
| event, err := history.Next() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| attrs := event.GetWorkflowExecutionStartedEventAttributes() | ||
| if attrs == nil { | ||
| return errors.New("original start history is missing its start event") | ||
| } | ||
| if attrs.GetMemo().GetFields()[startIntentMemo] == nil { | ||
| return errors.New("existing workflow has no original start identity") | ||
| } | ||
| var intent string | ||
| if err := converter.GetDefaultDataConverter().FromPayload(attrs.GetMemo().GetFields()[startIntentMemo], &intent); err != nil { | ||
| return fmt.Errorf("reading original start identity: %w", err) | ||
| } | ||
| if intent != e.originalStart.intent || | ||
| attrs.GetWorkflowType().GetName() != e.WorkflowType || | ||
| attrs.GetTaskQueue().GetName() != e.WorkflowOptions.TaskQueue { | ||
| return errors.New("existing workflow does not match the original start intent") | ||
| } | ||
| // Bind the history-verified run, never a later execution selected by workflow ID. | ||
| e.Handle = e.Client.GetWorkflow(ctx, e.WorkflowOptions.ID, runID) | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.