Skip to content

Commit

Permalink
Add frontend to trace command (#233)
Browse files Browse the repository at this point in the history
* Add frontend to trace command

* Fix defs-cmds

* Fix GetNumberOfEvents() and depth fetching

* comments

* comments

* comments

---------

Co-authored-by: feedmeapples <aksenov.ro@outlook.com>
  • Loading branch information
sebneira and feedmeapples committed May 26, 2023
1 parent 5dcaa37 commit f8c84ed
Show file tree
Hide file tree
Showing 18 changed files with 1,168 additions and 75 deletions.
2 changes: 1 addition & 1 deletion common/defs-cmds.go
Expand Up @@ -546,7 +546,7 @@ const WorkflowDeleteUsageText = `The ` + "`" + `temporal workflow delete` + "`"
Use the options listed below to change the command's behavior.`

const WorkflowTraceUsageText = `The ` + "`" + `temporal workflow trace` + "`" + ` command tracks the progress of a [Workflow Execution](/concepts/what-is-a-workflow-execution) and any [Child Workflows](/concepts/what-is-a-child-workflow-execution) it generates.
const WorkflowTraceUsageText = `The ` + "`" + `temporal workflow trace` + "`" + ` command tracks the progress of a [Workflow Execution](/concepts/what-is-a-workflow-execution) and any [Child Workflows](/concepts/what-is-a-child-workflow-execution) it generates.
Use the options listed below to change the command's behavior.`

Expand Down
2 changes: 1 addition & 1 deletion common/defs-flags.go
Expand Up @@ -77,7 +77,7 @@ const (
FlagSkipBaseDefinition = "Skip a Workflow Execution if the base Run is not the current Workflow Run."
FlagNonDeterministicDefinition = "Reset Workflow Execution if its last Event is `WorkflowTaskFailed` with a nondeterministic error."
FlagDryRunDefinition = "Simulate reset without resetting any Workflow Executions."
FlagDepthDefinition = "Number of Child Workflows to expand. Use -1 to expand all Child Workflows."
FlagDepthDefinition = "Depth of child workflows to fetch. Use -1 to fetch child workflows at any depth."
FlagConcurrencyDefinition = "Request concurrency."
FlagNoFoldDefinition = "Disable folding. All Child Workflows within the set depth will be fetched and displayed."

Expand Down
102 changes: 102 additions & 0 deletions trace/execution_icons.go
@@ -0,0 +1,102 @@
package trace

import (
"github.com/fatih/color"
"go.temporal.io/api/enums/v1"
)

var (
StatusRunning string = color.BlueString("▷")
StatusCompleted string = color.GreenString("✓")
StatusTerminated string = color.RedString("x")
StatusCanceled string = color.YellowString("x")
StatusFailed string = color.RedString("!")
StatusContinueAsNew string = color.GreenString("»")
StatusTimedOut string = color.RedString("⏱")
StatusUnspecifiedScheduled string = "•"
StatusCancelRequested string = color.YellowString("▷")
StatusTimerWaiting string = color.BlueString("⧖")
StatusTimerFired string = color.GreenString("⧖")
StatusTimerCanceled string = color.YellowString("⧖")
)

var workflowIcons = map[enums.WorkflowExecutionStatus]string{
enums.WORKFLOW_EXECUTION_STATUS_UNSPECIFIED: StatusUnspecifiedScheduled,
enums.WORKFLOW_EXECUTION_STATUS_RUNNING: StatusRunning,
enums.WORKFLOW_EXECUTION_STATUS_COMPLETED: StatusCompleted,
enums.WORKFLOW_EXECUTION_STATUS_TERMINATED: StatusTerminated,
enums.WORKFLOW_EXECUTION_STATUS_CANCELED: StatusCanceled,
enums.WORKFLOW_EXECUTION_STATUS_FAILED: StatusFailed,
enums.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW: StatusContinueAsNew,
enums.WORKFLOW_EXECUTION_STATUS_TIMED_OUT: StatusTimedOut,
}
var activityIcons = map[ActivityExecutionStatus]string{
ACTIVITY_EXECUTION_STATUS_UNSPECIFIED: StatusUnspecifiedScheduled,
ACTIVITY_EXECUTION_STATUS_SCHEDULED: StatusUnspecifiedScheduled,
ACTIVITY_EXECUTION_STATUS_RUNNING: StatusRunning,
ACTIVITY_EXECUTION_STATUS_COMPLETED: StatusCompleted,
ACTIVITY_EXECUTION_STATUS_CANCEL_REQUESTED: StatusCancelRequested,
ACTIVITY_EXECUTION_STATUS_CANCELED: StatusCanceled,
ACTIVITY_EXECUTION_STATUS_FAILED: StatusFailed,
ACTIVITY_EXECUTION_STATUS_TIMED_OUT: StatusTimedOut,
}
var timerIcons = map[TimerExecutionStatus]string{
TIMER_STATUS_WAITING: StatusTimerWaiting,
TIMER_STATUS_FIRED: StatusTimerFired,
TIMER_STATUS_CANCELED: StatusTimerCanceled,
}

// ExecutionStatus returns the icon (with color) for a given ExecutionState's status.
func ExecutionStatus(exec ExecutionState) string {
switch e := exec.(type) {
case *WorkflowExecutionState:
if icon, ok := workflowIcons[e.Status]; ok {
return icon
}
case *ActivityExecutionState:
if icon, ok := activityIcons[e.Status]; ok {
return icon
}
case *TimerExecutionState:
if icon, ok := timerIcons[e.Status]; ok {
return icon
}
}
return "?"
}

// StatusIcon has names for each status (useful for help messages).
type StatusIcon struct {
Name string
Icon string
}

var StatusIconsLegend = []StatusIcon{
{
Name: "Unspecified or Scheduled", Icon: StatusUnspecifiedScheduled,
},
{
Name: "Running", Icon: StatusRunning,
},
{
Name: "Completed", Icon: StatusCompleted,
},
{
Name: "Continue As New", Icon: StatusContinueAsNew,
},
{
Name: "Failed", Icon: StatusFailed,
},
{
Name: "Timed Out", Icon: StatusTimedOut,
},
{
Name: "Cancel Requested", Icon: StatusCancelRequested,
},
{
Name: "Canceled", Icon: StatusCanceled,
},
{
Name: "Terminated", Icon: StatusTerminated,
},
}
18 changes: 10 additions & 8 deletions trace/execution_state.go
Expand Up @@ -246,6 +246,9 @@ func (state *WorkflowExecutionState) Update(event *history.HistoryEvent) {
state.StartTime = event.EventTime
state.Attempt = attrs.GetAttempt()
state.Type = attrs.GetWorkflowType()
if state.Execution.GetRunId() == "" {
state.Execution.RunId = attrs.GetOriginalExecutionRunId()
}

state.ParentWorkflowExecution = attrs.ParentWorkflowExecution

Expand Down Expand Up @@ -392,14 +395,13 @@ func (state *WorkflowExecutionState) Update(event *history.HistoryEvent) {
// This method iteratively sums the LastEventId (the sequential id of the last event processed) and the HistoryLength for all child workflows
func (state *WorkflowExecutionState) GetNumberOfEvents() (int64, int64) {
var current, total int64
if state.ChildStates == nil {
return 0, 0
}
for _, child := range state.ChildStates {
if childWf, ok := child.(*WorkflowExecutionState); ok {
c, t := childWf.GetNumberOfEvents()
current += c
total += t
if state.ChildStates != nil {
for _, child := range state.ChildStates {
if childWf, ok := child.(*WorkflowExecutionState); ok {
c, t := childWf.GetNumberOfEvents()
current += c
total += t
}
}
}
return current + state.LastEventId, total + state.HistoryLength
Expand Down

0 comments on commit f8c84ed

Please sign in to comment.