Skip to content

Commit cbd133b

Browse files
authored
Expose parent and root execution in describe call (#781)
1 parent 1a88da6 commit cbd133b

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

temporalcli/commands.workflow_view.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func (c *TemporalWorkflowDescribeCommand) run(cctx *CommandContext, args []strin
117117
StateTransitionCount int64
118118
HistoryLength int64
119119
HistorySize int64
120+
ParentWorkflowId string `cli:",cardOmitEmpty"`
121+
ParentRunId string `cli:",cardOmitEmpty"`
122+
RootWorkflowId string `cli:",cardOmitEmpty"`
123+
RootRunId string `cli:",cardOmitEmpty"`
120124
}{
121125
WorkflowId: info.Execution.WorkflowId,
122126
RunId: info.Execution.RunId,
@@ -132,6 +136,10 @@ func (c *TemporalWorkflowDescribeCommand) run(cctx *CommandContext, args []strin
132136
StateTransitionCount: info.StateTransitionCount,
133137
HistoryLength: info.HistoryLength,
134138
HistorySize: info.HistorySizeBytes,
139+
ParentWorkflowId: info.GetParentExecution().GetWorkflowId(),
140+
ParentRunId: info.GetParentExecution().GetRunId(),
141+
RootWorkflowId: info.GetRootExecution().GetWorkflowId(),
142+
RootRunId: info.GetRootExecution().GetRunId(),
135143
}, printer.StructuredOptions{})
136144

137145
extendedInfo := resp.WorkflowExtendedInfo

temporalcli/commands.workflow_view_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,3 +993,64 @@ func (s *SharedServerSuite) TestWorkflow_Describe_WorkflowMetadata() {
993993
s.NotNil(jsonOut.ExecutionConfig.UserMetadata.Summary)
994994
s.NotNil(jsonOut.ExecutionConfig.UserMetadata.Details)
995995
}
996+
997+
func (s *SharedServerSuite) TestWorkflow_Describe_RootWorkflow() {
998+
s.Worker().OnDevWorkflow(func(ctx workflow.Context, input any) (any, error) {
999+
if input.(string) == "child" {
1000+
return "done", nil
1001+
}
1002+
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
1003+
StartToCloseTimeout: 10 * time.Second,
1004+
})
1005+
childHandle := workflow.ExecuteChildWorkflow(ctx, DevWorkflow, "child")
1006+
var childWE workflow.Execution
1007+
err := childHandle.GetChildWorkflowExecution().Get(ctx, &childWE)
1008+
if err != nil {
1009+
return nil, err
1010+
}
1011+
err = childHandle.Get(ctx, nil)
1012+
if err != nil {
1013+
return nil, err
1014+
}
1015+
return childWE.ID, err
1016+
})
1017+
1018+
run, err := s.Client.ExecuteWorkflow(
1019+
s.Context,
1020+
client.StartWorkflowOptions{TaskQueue: s.Worker().Options.TaskQueue},
1021+
DevWorkflow,
1022+
"ignored",
1023+
)
1024+
s.NoError(err)
1025+
var wfRes string
1026+
err = run.Get(s.Context, &wfRes)
1027+
s.NoError(err)
1028+
1029+
// Text
1030+
res := s.Execute(
1031+
"workflow", "describe",
1032+
"--address", s.Address(),
1033+
"-w", wfRes,
1034+
)
1035+
s.NoError(res.Err)
1036+
out := res.Stdout.String()
1037+
s.ContainsOnSameLine(out, "ParentWorkflowId", run.GetID())
1038+
s.ContainsOnSameLine(out, "ParentRunId", run.GetRunID())
1039+
s.ContainsOnSameLine(out, "RootWorkflowId", run.GetID())
1040+
s.ContainsOnSameLine(out, "RootRunId", run.GetRunID())
1041+
1042+
// JSON
1043+
res = s.Execute(
1044+
"workflow", "describe",
1045+
"-o", "json",
1046+
"--address", s.Address(),
1047+
"-w", wfRes,
1048+
)
1049+
s.NoError(res.Err)
1050+
var jsonOut workflowservice.DescribeWorkflowExecutionResponse
1051+
s.NoError(temporalcli.UnmarshalProtoJSONWithOptions(res.Stdout.Bytes(), &jsonOut, true))
1052+
s.Equal(run.GetID(), jsonOut.WorkflowExecutionInfo.ParentExecution.GetWorkflowId())
1053+
s.Equal(run.GetRunID(), jsonOut.WorkflowExecutionInfo.ParentExecution.GetRunId())
1054+
s.Equal(run.GetID(), jsonOut.WorkflowExecutionInfo.RootExecution.GetWorkflowId())
1055+
s.Equal(run.GetRunID(), jsonOut.WorkflowExecutionInfo.RootExecution.GetRunId())
1056+
}

0 commit comments

Comments
 (0)