Skip to content

Commit

Permalink
show task nesting via indentation in web ui
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 5, 2023
1 parent a23ffc6 commit a3efc65
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 44 deletions.
4 changes: 2 additions & 2 deletions pkg/coordinator/tasks/check_clients_are_healthy/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ func (t *Task) processCheck() {
totalClientCount++

checkResult := t.processClientCheck(client)
if checkResult != expectedResult {
if checkResult == expectedResult {
passResultCount++

} else {
failedClients = append(failedClients, client.Config.Name)
}
}
Expand Down
41 changes: 25 additions & 16 deletions pkg/coordinator/test/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type TaskScheduler struct {

type taskExecutionState struct {
index uint64
task types.Task
parentState *taskExecutionState
isStarted bool
isRunning bool
isTimeout bool
Expand Down Expand Up @@ -93,7 +95,7 @@ func (ts *TaskScheduler) AddCleanupTask(options *types.TaskOptions) (types.Task,
return task, nil
}

func (ts *TaskScheduler) newTask(options *types.TaskOptions, parent types.Task, isCleanupTask bool) (types.Task, error) {
func (ts *TaskScheduler) newTask(options *types.TaskOptions, parentState *taskExecutionState, isCleanupTask bool) (types.Task, error) {
// lookup task by name
var taskDescriptor *types.TaskDescriptor

Expand All @@ -112,12 +114,15 @@ func (ts *TaskScheduler) newTask(options *types.TaskOptions, parent types.Task,
var task types.Task

taskIdx := ts.taskCount
taskState := &taskExecutionState{
index: taskIdx,
parentState: parentState,
}
taskCtx := &types.TaskContext{
Scheduler: ts,
Index: taskIdx,
ParentTask: parent,
Scheduler: ts,
Index: taskIdx,
NewTask: func(options *types.TaskOptions) (types.Task, error) {
return ts.newTask(options, task, isCleanupTask)
return ts.newTask(options, taskState, isCleanupTask)
},
SetResult: func(result types.TaskResult) {
ts.setTaskResult(task, result, true)
Expand All @@ -135,9 +140,7 @@ func (ts *TaskScheduler) newTask(options *types.TaskOptions, parent types.Task,

// create internal execution state
ts.taskStateMutex.Lock()
taskState := &taskExecutionState{
index: taskIdx,
}
taskState.task = task
ts.taskStateMap[task] = taskState
ts.taskStateMutex.Unlock()

Expand Down Expand Up @@ -409,15 +412,21 @@ func (ts *TaskScheduler) GetTaskStatus(task types.Task) *types.TaskStatus {
return nil
}

return &types.TaskStatus{
Index: taskState.index,
IsStarted: taskState.isStarted,
IsRunning: taskState.isRunning,
StartTime: taskState.startTime,
StopTime: taskState.stopTime,
Result: taskState.taskResult,
Error: taskState.taskError,
taskStatus := &types.TaskStatus{
Index: taskState.index,
ParentIndex: 0,
IsStarted: taskState.isStarted,
IsRunning: taskState.isRunning,
StartTime: taskState.startTime,
StopTime: taskState.stopTime,
Result: taskState.taskResult,
Error: taskState.taskError,
}
if taskState.parentState != nil {
taskStatus.ParentIndex = taskState.parentState.index
}

return taskStatus
}

func (ts *TaskScheduler) GetTaskResultUpdateChan(task types.Task, oldResult types.TaskResult) <-chan bool {
Expand Down
17 changes: 4 additions & 13 deletions pkg/coordinator/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Test struct {
taskScheduler *TaskScheduler
log logrus.FieldLogger
config *Config
metrics Metrics

status types.TestStatus
startTime time.Time
Expand All @@ -24,11 +23,10 @@ type Test struct {

func CreateTest(coordinator types.Coordinator, config *Config) (types.Test, error) {
test := &Test{
name: config.Name,
log: coordinator.Logger().WithField("component", "test").WithField("test", config.Name),
config: config,
metrics: NewMetrics("sync_test_coordinator", config.Name),
status: types.TestStatusPending,
name: config.Name,
log: coordinator.Logger().WithField("component", "test").WithField("test", config.Name),
config: config,
status: types.TestStatusPending,
}
if test.config.Timeout.Duration > 0 {
test.timeout = test.config.Timeout.Duration
Expand Down Expand Up @@ -60,12 +58,6 @@ func CreateTest(coordinator types.Coordinator, config *Config) (types.Test, erro
return nil, err
}
}

// setup metrics
test.metrics.Register()

test.metrics.SetTestInfo(config.Name)
test.metrics.SetTotalTasks(float64(len(config.Tasks)))
}

return test, nil
Expand Down Expand Up @@ -127,7 +119,6 @@ func (t *Test) Run(ctx context.Context) error {
t.status = types.TestStatusRunning

defer func() {
t.metrics.SetTestDuration(float64(time.Since(t.startTime).Milliseconds()))
t.stopTime = time.Now()
}()

Expand Down
24 changes: 12 additions & 12 deletions pkg/coordinator/types/taskctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ type TaskScheduler interface {
}

type TaskStatus struct {
Index uint64
IsStarted bool
IsRunning bool
StartTime time.Time
StopTime time.Time
Result TaskResult
Error error
Index uint64
ParentIndex uint64
IsStarted bool
IsRunning bool
StartTime time.Time
StopTime time.Time
Result TaskResult
Error error
}

type TaskContext struct {
Scheduler TaskScheduler
Index uint64
ParentTask Task
NewTask func(options *TaskOptions) (Task, error)
SetResult func(result TaskResult)
Scheduler TaskScheduler
Index uint64
NewTask func(options *TaskOptions) (Task, error)
SetResult func(result TaskResult)
}
13 changes: 13 additions & 0 deletions pkg/coordinator/web/handlers/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type TestPage struct {

type TestPageTask struct {
Index uint64 `json:"index"`
ParentIndex uint64 `json:"parent_index"`
IndentPx uint64 `json:"indent_px"`
Name string `json:"name"`
Title string `json:"title"`
IsStarted bool `json:"started"`
Expand Down Expand Up @@ -141,11 +143,14 @@ func (fh *FrontendHandler) getTestPageData(testIdx int64) (*TestPage, error) {

taskScheduler := test.GetTaskScheduler()
if taskScheduler != nil {
indentationMap := map[uint64]int{}

for _, task := range taskScheduler.GetAllTasks() {
taskStatus := taskScheduler.GetTaskStatus(task)

taskData := &TestPageTask{
Index: taskStatus.Index,
ParentIndex: taskStatus.ParentIndex,
Name: task.Name(),
Title: task.Title(),
IsStarted: taskStatus.IsStarted,
Expand All @@ -156,6 +161,14 @@ func (fh *FrontendHandler) getTestPageData(testIdx int64) (*TestPage, error) {
HasTimeout: task.Timeout() > 0,
}

indentation := 0
if taskData.ParentIndex > 0 {
indentation = indentationMap[taskData.ParentIndex] + 1
}

indentationMap[taskData.Index] = indentation
taskData.IndentPx = uint64(20 * indentation)

switch {
case !taskStatus.IsStarted:
taskData.Status = "pending"
Expand Down
2 changes: 1 addition & 1 deletion pkg/coordinator/web/templates/test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h2 class="accordion-header">
</div>
{{ range $i, $task := .Tasks }}
<div class="accordion-item">
<h2 class="accordion-header">
<h2 class="accordion-header" style="padding-left: {{ $task.IndentPx }}px">
<button class="accordion-button task-header collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#task{{ $task.Index }}-panel" aria-expanded="true" aria-controls="task{{ $task.Index }}-panel">
<div class="container">
<div class="row">
Expand Down

0 comments on commit a3efc65

Please sign in to comment.