Skip to content
Open
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: 30 additions & 4 deletions internal/temporalcli/commands.workflow_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,36 @@ type structuredHistoryEvent struct {
Time string `cli:",width=20"`
// We're going to set width to a semi-reasonable number for good header
// placement, but we expect it to extend past for larger
Type string `cli:",width=26"`
Type string `cli:",width=26"`
Details string
}

var structuredHistoryEventType = reflect.TypeOf(structuredHistoryEvent{})

func compactHistoryDetails(event *history.HistoryEvent) string {
switch a := event.Attributes.(type) {
case *history.HistoryEvent_WorkflowExecutionStartedEventAttributes:
return a.WorkflowExecutionStartedEventAttributes.GetWorkflowType().GetName()
case *history.HistoryEvent_WorkflowTaskScheduledEventAttributes:
return a.WorkflowTaskScheduledEventAttributes.GetTaskQueue().GetName()
case *history.HistoryEvent_ActivityTaskScheduledEventAttributes:
return a.ActivityTaskScheduledEventAttributes.GetActivityType().GetName()
case *history.HistoryEvent_StartChildWorkflowExecutionInitiatedEventAttributes:
return a.StartChildWorkflowExecutionInitiatedEventAttributes.GetWorkflowType().GetName()
case *history.HistoryEvent_WorkflowExecutionSignaledEventAttributes:
return a.WorkflowExecutionSignaledEventAttributes.GetSignalName()
case *history.HistoryEvent_WorkflowExecutionUpdateAdmittedEventAttributes:
return a.WorkflowExecutionUpdateAdmittedEventAttributes.GetRequest().GetInput().GetName()
case *history.HistoryEvent_WorkflowExecutionUpdateAcceptedEventAttributes:
return a.WorkflowExecutionUpdateAcceptedEventAttributes.GetAcceptedRequest().GetInput().GetName()
case *history.HistoryEvent_TimerStartedEventAttributes:
if timeout := a.TimerStartedEventAttributes.GetStartToFireTimeout(); timeout != nil {
return timeout.AsDuration().String()
}
}
return ""
}

func (s *structuredHistoryIter) Next() (any, error) {
event, err := s.NextRawEvent()
if err != nil {
Expand All @@ -868,9 +893,10 @@ func (s *structuredHistoryIter) Next() (any, error) {
typeName = coloredEventType(event.EventType)
}
data := structuredHistoryEvent{
ID: event.EventId,
Time: event.EventTime.AsTime().Format(time.RFC3339),
Type: typeName,
ID: event.EventId,
Time: event.EventTime.AsTime().Format(time.RFC3339),
Type: typeName,
Details: compactHistoryDetails(event),
}

// Follow continue as new (forward only; reverse traversal stays within the requested run)
Expand Down
24 changes: 24 additions & 0 deletions internal/temporalcli/commands.workflow_show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@ package temporalcli

import (
"testing"
"time"

"github.com/stretchr/testify/require"
"go.temporal.io/api/enums/v1"
historypb "go.temporal.io/api/history/v1"
updatepb "go.temporal.io/api/update/v1"
"google.golang.org/protobuf/types/known/durationpb"
)

func TestCompactHistoryDetails(t *testing.T) {
timer := &historypb.TimerStartedEventAttributes{StartToFireTimeout: durationpb.New(90 * time.Second)}
event := &historypb.HistoryEvent{Attributes: &historypb.HistoryEvent_TimerStartedEventAttributes{
TimerStartedEventAttributes: timer,
}}
require.Equal(t, "1m30s", compactHistoryDetails(event))
timer.StartToFireTimeout = nil
require.Empty(t, compactHistoryDetails(event))

// Accepted updates need not carry the original request.
accepted := &historypb.WorkflowExecutionUpdateAcceptedEventAttributes{}
updateEvent := &historypb.HistoryEvent{
Attributes: &historypb.HistoryEvent_WorkflowExecutionUpdateAcceptedEventAttributes{
WorkflowExecutionUpdateAcceptedEventAttributes: accepted,
},
}
require.Empty(t, compactHistoryDetails(updateEvent))
accepted.AcceptedRequest = &updatepb.Request{Input: &updatepb.Input{Name: "change-address"}}
require.Equal(t, "change-address", compactHistoryDetails(updateEvent))
}

func TestSystemNexusOpDisplayName(t *testing.T) {
const op = "SignalWithStartWorkflowExecution" // present in the global systemNexusOps registry
const futureOp = "FutureUnregisteredOperation" // intentionally NOT in the global registry
Expand Down
2 changes: 1 addition & 1 deletion internal/temporalcli/commands.workflow_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s *SharedServerSuite) testWorkflowShowFollow(detailed bool) {
s.Contains(output, "input[0]: ignored")
s.Contains(output, "signalName: my-signal")
} else {
s.Contains(output, "WorkflowExecutionSignaled")
s.ContainsOnSameLine(output, "WorkflowExecutionSignaled", "my-signal")
}
}

Expand Down