Skip to content

Commit 51cbb1c

Browse files
authored
Merge pull request #138 from trickest/fix/run-machines
Fix run machines data type and add parallelism
2 parents 7fe844b + bb308ae commit 51cbb1c

File tree

5 files changed

+25
-77
lines changed

5 files changed

+25
-77
lines changed

cmd/get/json_output.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type JSONRun struct {
3232
FleetName string `json:"fleet_name"`
3333
UseStaticIPs bool `json:"use_static_ips"`
3434
Machines int `json:"machines"`
35+
Parallelism int `json:"parallelism"`
3536
IPAddresses []string `json:"ip_addresses"`
3637

3738
RunInsights *trickest.RunSubJobInsights `json:"run_insights,omitempty"`
@@ -78,6 +79,8 @@ func NewJSONRun(run *trickest.Run, subjobs []trickest.SubJob, taskGroupStatsMap
7879
UseStaticIPs: *run.UseStaticIPs,
7980
IPAddresses: run.IPAddresses,
8081
RunInsights: run.RunInsights,
82+
Machines: run.Machines,
83+
Parallelism: run.Parallelism,
8184
}
8285

8386
if run.Status == "RUNNING" {
@@ -86,12 +89,6 @@ func NewJSONRun(run *trickest.Run, subjobs []trickest.SubJob, taskGroupStatsMap
8689
jsonRun.Duration = trickest.Duration{Duration: run.CompletedDate.Sub(*run.StartedDate)}
8790
}
8891

89-
if run.Machines.Default != nil {
90-
jsonRun.Machines = *run.Machines.Default
91-
} else if run.Machines.SelfHosted != nil {
92-
jsonRun.Machines = *run.Machines.SelfHosted
93-
}
94-
9592
jsonRun.SubJobs = make([]JSONSubJob, len(subjobs))
9693
for i, subjob := range subjobs {
9794
jsonRun.SubJobs[i] = *NewJSONSubJob(&subjob, taskGroupStatsMap)

cmd/help/help.go

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"sort"
88
"strconv"
99
"strings"
10-
"time"
1110

1211
"github.com/charmbracelet/glamour"
1312
"github.com/trickest/trickest-cli/cmd/execute"
@@ -81,36 +80,14 @@ func generateHelpMarkdown(workflow *trickest.Workflow, labeledPrimitiveNodes []*
8180
sb.WriteString(fmt.Sprintf("%s\n\n", workflow.Description))
8281
}
8382

84-
runStats := []struct {
85-
date time.Time
86-
machines int
87-
duration time.Duration
88-
url string
89-
}{}
90-
for _, run := range runs {
91-
machines := run.Machines.Default
92-
if machines == nil {
93-
machines = run.Machines.SelfHosted
94-
}
95-
date := *run.StartedDate
96-
duration := run.CompletedDate.Sub(date)
97-
runURL := fmt.Sprintf("%s?run=%s", workflowURL, run.ID)
98-
runStats = append(runStats, struct {
99-
date time.Time
100-
machines int
101-
duration time.Duration
102-
url string
103-
}{date, *machines, duration, runURL})
104-
}
105-
10683
machineCount := defaultMachineCount
10784
if maxMachines > 0 && maxMachines < defaultMachineCount {
10885
machineCount = maxMachines
109-
} else if len(runStats) > 0 {
86+
} else if len(runs) > 0 {
11087
highestMachineCount := 0
111-
for _, runStat := range runStats {
112-
if runStat.machines > highestMachineCount {
113-
highestMachineCount = runStat.machines
88+
for _, run := range runs {
89+
if run.Parallelism > highestMachineCount {
90+
highestMachineCount = run.Parallelism
11491
}
11592
}
11693
machineCount = highestMachineCount
@@ -185,20 +162,20 @@ func generateHelpMarkdown(workflow *trickest.Workflow, labeledPrimitiveNodes []*
185162
}
186163

187164
// Past runs section
188-
if len(runStats) > 0 {
165+
if len(runs) > 0 {
189166
sb.WriteString("## Past Runs\n\n")
190-
sb.WriteString("| Started at | Machines | Duration | URL |\n")
191-
sb.WriteString("|------------|----------|----------|-----|\n")
192-
for _, runStat := range runStats {
193-
machines := runStat.machines
194-
date := runStat.date.Format("2006-01-02 15:04")
195-
duration := runStat.duration
167+
sb.WriteString("| Started at | Parallelism | Duration | URL |\n")
168+
sb.WriteString("|------------|-------------|----------|-----|\n")
169+
for _, run := range runs {
170+
machines := run.Parallelism
171+
date := run.StartedDate.Format("2006-01-02 15:04")
172+
duration := run.CompletedDate.Sub(*run.StartedDate)
196173
durationStr := display.FormatDuration(duration)
197-
runURL := runStat.url
174+
runURL := fmt.Sprintf("%s?run=%s", workflowURL, run.ID)
198175
sb.WriteString(fmt.Sprintf("| %s | %d | %s | [View](%s) |\n", date, machines, durationStr, runURL))
199176
}
200177
sb.WriteString("\n")
201-
sb.WriteString("Use the `--machines` flag to set the number of machines to run the workflow on.\n\n")
178+
sb.WriteString("Use the `--machines` flag to set the number of machines (maximum parallelism) to run the workflow on.\n\n")
202179
}
203180

204181
// Long description (README content)

pkg/display/run/printer.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func (p *RunPrinter) PrintAll(run *trickest.Run, subJobs []trickest.SubJob, vers
5858
// Print basic run details
5959
output.WriteString(p.formatKeyValue("Name", run.WorkflowName))
6060
output.WriteString(p.formatKeyValue("Status", run.Status))
61-
output.WriteString(p.formatKeyValue("Machines", formatMachines(run.Machines)))
61+
output.WriteString(p.formatKeyValue("Machines", fmt.Sprintf("%d", run.Machines)))
62+
output.WriteString(p.formatKeyValue("Parallelism", fmt.Sprintf("%d", run.Parallelism)))
6263
output.WriteString(p.formatKeyValue("Fleet", run.FleetName))
6364
output.WriteString("\n")
6465

@@ -120,17 +121,6 @@ func (p *RunPrinter) PrintAll(run *trickest.Run, subJobs []trickest.SubJob, vers
120121
fmt.Fprint(p.writer, output.String())
121122
}
122123

123-
// formatMachines formats the machine allocation for the run
124-
func formatMachines(machines trickest.Machines) string {
125-
if machines.Default != nil && *machines.Default > 0 {
126-
return fmt.Sprintf("%d", *machines.Default)
127-
}
128-
if machines.SelfHosted != nil && *machines.SelfHosted > 0 {
129-
return fmt.Sprintf("%d", *machines.SelfHosted)
130-
}
131-
return ""
132-
}
133-
134124
// formatKeyValue formats a key-value pair with a fixed width
135125
func (p *RunPrinter) formatKeyValue(key, value string) string {
136126
return fmt.Sprintf("%-18s %v\n", key+":", value)

pkg/trickest/run.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type Run struct {
1616
ID *uuid.UUID `json:"id,omitempty"`
1717
Name string `json:"name,omitempty"`
1818
Status string `json:"status,omitempty"`
19-
Machines Machines `json:"machines,omitempty"`
19+
Machines int `json:"machines,omitempty"`
20+
Parallelism int `json:"parallelism,omitempty"`
2021
WorkflowVersionInfo *uuid.UUID `json:"workflow_version_info,omitempty"`
2122
WorkflowInfo *uuid.UUID `json:"workflow_info,omitempty"`
2223
WorkflowName string `json:"workflow_name,omitempty"`
@@ -53,16 +54,6 @@ func (d *Duration) MarshalJSON() ([]byte, error) {
5354
return json.Marshal(fmt.Sprintf("%dm %ds", seconds/60, seconds%60))
5455
}
5556

56-
// Machines represents machine configuration
57-
type Machines struct {
58-
Default *int `json:"default,omitempty"`
59-
SelfHosted *int `json:"self_hosted,omitempty"`
60-
}
61-
62-
type Parallelism struct {
63-
Parallelism int `json:"parallelism"`
64-
}
65-
6657
type RunSubJobInsights struct {
6758
Total int `json:"total"`
6859
Pending int `json:"pending"`
@@ -189,16 +180,7 @@ func (c *Client) CreateRun(ctx context.Context, versionID uuid.UUID, machines in
189180
Fleet: &fleet.ID,
190181
Vault: &fleet.Vault,
191182
UseStaticIPs: &useStaticIPs,
192-
}
193-
194-
if fleet.Type == FleetTypeSelfHosted {
195-
run.Machines = Machines{
196-
SelfHosted: &machines,
197-
}
198-
} else {
199-
run.Machines = Machines{
200-
Default: &machines,
201-
}
183+
Parallelism: machines,
202184
}
203185

204186
var createdRun Run

pkg/trickest/workflow.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ScheduleInfo struct {
3636
Date *time.Time `json:"date,omitempty"`
3737
Workflow string `json:"workflow,omitempty"`
3838
RepeatPeriod int `json:"repeat_period,omitempty"`
39-
Machines *Machines `json:"machines,omitempty"`
39+
Parallelism int `json:"parallelism,omitempty"`
4040
}
4141

4242
// WorkflowVersion represents a workflow version
@@ -299,7 +299,9 @@ func (c *Client) GetLatestWorkflowVersion(ctx context.Context, workflowID uuid.U
299299

300300
// GetWorkflowVersionMaxMachines retrieves the maximum machines for a workflow version
301301
func (c *Client) GetWorkflowVersionMaxMachines(ctx context.Context, versionID uuid.UUID, fleetID uuid.UUID) (int, error) {
302-
var parallelism Parallelism
302+
var parallelism struct {
303+
Parallelism int `json:"parallelism"`
304+
}
303305
path := fmt.Sprintf("/workflow-version/%s/max-machines/?fleet=%s", versionID, fleetID)
304306

305307
if err := c.Hive.doJSON(ctx, http.MethodGet, path, nil, &parallelism); err != nil {

0 commit comments

Comments
 (0)