temporal
temporal copied to clipboard
Populate identity for child workflow
What changed?
Populate the identity for child workflows as the request
Why?
Please refer to the detailed information in the request
How did you test it?
Run local unite test.
Run a sample workflow and verify the result as below: We can see the foo as identity for the parent workflow below
{
"eventId": "1",
"eventTime": "2024-03-29T19:09:25.770790Z",
"eventType": "WorkflowExecutionStarted",
"version": "0",
"taskId": "1048587",
"workerMayIgnore": false,
"workflowExecutionStartedEventAttributes": {
"workflowType": {
"name": "SampleParentWorkflow"
},
"parentWorkflowNamespace": "",
"parentWorkflowNamespaceId": "",
"parentWorkflowExecution": null,
"parentInitiatedEventId": "0",
"taskQueue": {
"name": "child-workflow",
"kind": "Normal",
"normalName": ""
},
"input": null,
"workflowExecutionTimeout": "0s",
"workflowRunTimeout": "0s",
"workflowTaskTimeout": "10s",
"continuedExecutionRunId": "",
"initiator": "Unspecified",
"continuedFailure": null,
"lastCompletionResult": null,
"originalExecutionRunId": "2d2d20d7-8b97-4e76-9b3d-03365d4c0364",
"identity": "foo",
"firstExecutionRunId": "2d2d20d7-8b97-4e76-9b3d-03365d4c0364",
"retryPolicy": null,
"attempt": 1,
"workflowExecutionExpirationTime": null,
"cronSchedule": "",
"firstWorkflowTaskBackoff": "0s",
"memo": null,
"searchAttributes": null,
"prevAutoResetPoints": null,
"header": {
"fields": {}
},
"parentInitiatedEventVersion": "0",
"workflowId": "parent-workflow_7c061f28-1aa9-4c36-9bbe-24f71b91d73a",
"sourceVersionStamp": null
}
}
We can see the bar as an identity for both child workflow and WorkflowTaskCompleted event below
{
"eventId": "1",
"eventTime": "2024-03-29T19:09:25.828336Z",
"eventType": "WorkflowExecutionStarted",
"version": "0",
"taskId": "1048602",
"workerMayIgnore": false,
"workflowExecutionStartedEventAttributes": {
"workflowType": {
"name": "SampleChildWorkflow"
},
"parentWorkflowNamespace": "default",
"parentWorkflowNamespaceId": "f5488090-77a8-4877-a7f9-7e3698cd51ed",
"parentWorkflowExecution": {
"workflowId": "parent-workflow_7c061f28-1aa9-4c36-9bbe-24f71b91d73a",
"runId": "2d2d20d7-8b97-4e76-9b3d-03365d4c0364"
},
"parentInitiatedEventId": "5",
"taskQueue": {
"name": "child-workflow",
"kind": "Normal",
"normalName": ""
},
"input": {
"payloads": [
"World"
]
},
"workflowExecutionTimeout": "0s",
"workflowRunTimeout": "0s",
"workflowTaskTimeout": "10s",
"continuedExecutionRunId": "",
"initiator": "Unspecified",
"continuedFailure": null,
"lastCompletionResult": null,
"originalExecutionRunId": "7ac90c28-553e-428c-a15d-b9bf20020e3d",
"identity": "bar",
"firstExecutionRunId": "7ac90c28-553e-428c-a15d-b9bf20020e3d",
"retryPolicy": null,
"attempt": 1,
"workflowExecutionExpirationTime": null,
"cronSchedule": "",
"firstWorkflowTaskBackoff": "0s",
"memo": null,
"searchAttributes": null,
"prevAutoResetPoints": null,
"header": {
"fields": {}
},
"parentInitiatedEventVersion": "0",
"workflowId": "ABC-SIMPLE-CHILD-WORKFLOW-ID",
"sourceVersionStamp": null
}
}
{
"eventId": "4",
"eventTime": "2024-03-29T19:09:25.815689Z",
"eventType": "WorkflowTaskCompleted",
"version": "0",
"taskId": "1048597",
"workerMayIgnore": false,
"workflowTaskCompletedEventAttributes": {
"scheduledEventId": "2",
"startedEventId": "3",
"identity": "bar",
"binaryChecksum": "",
"workerVersion": {
"buildId": "66966b85de4395752a344892b04a75b2",
"bundleId": "",
"useVersioning": false
},
"sdkMetadata": {
"coreUsedFlags": [],
"langUsedFlags": [
3
],
"sdkName": "temporal-go",
"sdkVersion": "1.26.0"
},
"meteringMetadata": {
"nonfirstLocalActivityExecutionAttempts": 0
}
}
}
Potential risks
I am using the cache to retrieve the event history in order to get the identity of WorkflowTaskCompleted
event, if the cache is crushed then will result in a cache miss, so I will skip that case and keep the identity as empty to avoid stopping the entire child workflow.
Documentation
Is hotfix candidate?
What is the purpose of populating the field in this case? The child is clearly linked to the parent that already has the identity field populated.
What is the purpose of populating the field in this case? The child is clearly linked to the parent that already has the identity field populated.
Thank you for your review. From the request, this is an enhancement to ease people on tracking a child WF from a specific SDK client. Besides, this also keeps the consistency of the payload of the event by providing the identity. I may be not quite familiar on how the child WF links to its parent. But with this identity, it will help me to link the child WF to a SDK client as the request above. Let me know what's your thought.
Thank you!
It is better to keep information normalized. A child workflow WorkflowExecutionStarted contains information about the parent including parent_initiated_event_id. The parent contains ChildWorkflowExecutionInitiatedEvent with that id, which contains workflow_task_completed_event_id pointing to the WorkflowTaskCompletedEvent that contains an identity field.
WorkflowTaskCompletedEvent
Thank you for your feedback and your detailed explanation.
I have found the change I made matches the expectation in the request, but not match the way you described above. Since the child workflow is triggered in a manner as the way above. I agree that is a more normalized way to populate the identity for the child workflow. I will make a change according to the pattern above. Thank you!
So the change will based on below:
We want to populate the identity for the child workflow payload 1 below, we should find workflowTaskCompletedEventId in payload 2 below with parentInitiatedEventId
in payload 1, and use that to link to the identity in payload 3. In this case, the identity should be [email protected]@
instead of foo
.
Child workflow payload - 1:
{
"eventId": "1",
"eventTime": "2024-03-27T21:03:19.806526Z",
"eventType": "WorkflowExecutionStarted",
"version": "0",
"taskId": "1048661",
"workerMayIgnore": false,
"workflowExecutionStartedEventAttributes": {
"workflowType": {
"name": "SampleChildWorkflow"
},
"parentWorkflowNamespace": "default",
"parentWorkflowNamespaceId": "f323c048-dc6d-4509-ac12-cef6c896a57c",
"parentWorkflowExecution": {
"workflowId": "parent-workflow_9e46370c-ae3e-47eb-b637-6eb535a50726",
"runId": "17402b74-ba89-4d29-85cc-f9e4383b9512"
},
"parentInitiatedEventId": "5",
"taskQueue": {
"name": "child-workflow",
"kind": "Normal",
"normalName": ""
},
"input": {
"payloads": [
"World"
]
},
"workflowExecutionTimeout": "0s",
"workflowRunTimeout": "0s",
"workflowTaskTimeout": "10s",
"continuedExecutionRunId": "",
"initiator": "Unspecified",
"continuedFailure": null,
"lastCompletionResult": null,
"originalExecutionRunId": "c297462c-a185-45cc-bf08-22a7c0959183",
"identity": "foo",
"firstExecutionRunId": "c297462c-a185-45cc-bf08-22a7c0959183",
"retryPolicy": null,
"attempt": 1,
"workflowExecutionExpirationTime": null,
"cronSchedule": "",
"firstWorkflowTaskBackoff": "0s",
"memo": null,
"searchAttributes": null,
"prevAutoResetPoints": null,
"header": {
"fields": {}
},
"parentInitiatedEventVersion": "0",
"workflowId": "ABC-SIMPLE-CHILD-WORKFLOW-ID",
"sourceVersionStamp": null
}
}
StartChildWorkflowExecutionInitiated - 2
{
"eventId": "5",
"eventTime": "2024-03-27T21:03:19.805182Z",
"eventType": "StartChildWorkflowExecutionInitiated",
"version": "0",
"taskId": "1048657",
"workerMayIgnore": false,
"startChildWorkflowExecutionInitiatedEventAttributes": {
"namespace": "default",
"namespaceId": "f323c048-dc6d-4509-ac12-cef6c896a57c",
"workflowId": "ABC-SIMPLE-CHILD-WORKFLOW-ID",
"workflowType": {
"name": "SampleChildWorkflow"
},
"taskQueue": {
"name": "child-workflow",
"kind": "Normal",
"normalName": ""
},
"input": {
"payloads": [
"World"
]
},
"workflowExecutionTimeout": "0s",
"workflowRunTimeout": "0s",
"workflowTaskTimeout": "10s",
"parentClosePolicy": "Terminate",
"control": "",
"workflowTaskCompletedEventId": "4",
"workflowIdReusePolicy": "AllowDuplicate",
"retryPolicy": null,
"cronSchedule": "",
"header": {
"fields": {}
},
"memo": null,
"searchAttributes": null,
"useCompatibleVersion": true
}
}
WorkflowTaskCompleted - 3
{
"eventId": "4",
"eventTime": "2024-03-27T21:03:19.805095Z",
"eventType": "WorkflowTaskCompleted",
"version": "0",
"taskId": "1048656",
"workerMayIgnore": false,
"workflowTaskCompletedEventAttributes": {
"scheduledEventId": "2",
"startedEventId": "3",
"identity": "[email protected]@",
"binaryChecksum": "",
"workerVersion": {
"buildId": "7853417f7797e7a8743916615110acf2",
"bundleId": "",
"useVersioning": false
},
"sdkMetadata": {
"coreUsedFlags": [],
"langUsedFlags": [
3
],
"sdkName": "temporal-go",
"sdkVersion": "1.26.0"
},
"meteringMetadata": {
"nonfirstLocalActivityExecutionAttempts": 0
}
}
}