Skip to content

Commit b3bb9fb

Browse files
committed
dump ctf-ci results to a file
1 parent 2667c9b commit b3bb9fb

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

book/src/framework/components/analyze_ci.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ ctf ci -r "smartcontractkit/chainlink" -w "CI Core" -t jobs -s 5 -e 3
3535
ctf ci -r "smartcontractkit/chainlink-testing-framework" -w "Framework Golden Tests Examples" -t jobs -s 3
3636
```
3737
You can also use `-debug` flag to dump all the workflow runs/jobs to `ctf-ci-debug` folder.
38+
39+
All the results are also saved by default into `ctf-ci-$uuid.json` files so you can use this tool as CI performance linter.

framework/cmd/ci.go

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ var (
3939
SlowTestThreshold = 5 * time.Minute
4040
ExtremelySlowTestThreshold = 10 * time.Minute
4141

42-
DebugDirRoot = "ctf-ci-debug"
43-
DebugSubDirWF = filepath.Join(DebugDirRoot, "workflows")
44-
DebugSubDirJobs = filepath.Join(DebugDirRoot, "jobs")
42+
DebugSubDirWF = filepath.Join(DebugDirRoot, "workflows")
43+
DebugSubDirJobs = filepath.Join(DebugDirRoot, "jobs")
44+
DefaultResultsDir = "."
45+
DefaultResultsFile = "ctf-ci"
4546
)
4647

4748
type GitHubActionsClient interface {
@@ -50,38 +51,38 @@ type GitHubActionsClient interface {
5051
}
5152

5253
type AnalysisConfig struct {
53-
Debug bool
54-
Owner string
55-
Repo string
56-
WorkflowName string
57-
TimeDaysBeforeStart int
58-
TimeStart time.Time
59-
TimeDaysBeforeEnd int
60-
TimeEnd time.Time
61-
Typ string
62-
ResultsFile string
54+
Debug bool `json:"debug"`
55+
Owner string `json:"owner"`
56+
Repo string `json:"repo"`
57+
WorkflowName string `json:"workflow_name"`
58+
TimeDaysBeforeStart int `json:"time_days_before_start"`
59+
TimeStart time.Time `json:"time_start"`
60+
TimeDaysBeforeEnd int `json:"time_days_before_end"`
61+
TimeEnd time.Time `json:"time_end"`
62+
Typ string `json:"type"`
63+
ResultsFile string `json:"results_file"`
6364
}
6465

6566
type Stat struct {
66-
Name string
67-
Successes int
68-
Failures int
69-
Cancels int
70-
ReRuns int
71-
P50 time.Duration
72-
P95 time.Duration
73-
P99 time.Duration
74-
TotalDuration time.Duration
75-
Durations []time.Duration
67+
Name string `json:"name"`
68+
Successes int `json:"successes"`
69+
Failures int `json:"failures"`
70+
Cancels int `json:"cancels"`
71+
ReRuns int `json:"reRuns"`
72+
P50 time.Duration `json:"p50"`
73+
P95 time.Duration `json:"p95"`
74+
P99 time.Duration `json:"p99"`
75+
TotalDuration time.Duration `json:"totalDuration"`
76+
Durations []time.Duration `json:"-"`
7677
}
7778

7879
type Stats struct {
79-
Mu *sync.Mutex
80-
Runs int
81-
CancelledRuns int
82-
IgnoredRuns int
83-
Jobs map[string]*Stat
84-
Steps map[string]*Stat
80+
Mu *sync.Mutex `json:"-"`
81+
Runs int `json:"runs"`
82+
CancelledRuns int `json:"cancelled_runs"`
83+
IgnoredRuns int `json:"ignored_runs"`
84+
Jobs map[string]*Stat `json:"jobs"`
85+
Steps map[string]*Stat `json:"steps"`
8586
}
8687

8788
func calculatePercentiles(stat *Stat) *Stat {
@@ -103,7 +104,7 @@ func refreshDebugDirs() {
103104
}
104105
}
105106

106-
func writeStruct(enabled bool, dir, name string, data interface{}) error {
107+
func dumpResults(enabled bool, dir, name string, data interface{}) error {
107108
if enabled {
108109
d, err := json.MarshalIndent(data, "", " ")
109110
if err != nil {
@@ -145,7 +146,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
145146
// analyze workflow
146147
name := *wr.Name
147148
framework.L.Debug().Str("Name", name).Msg("Analyzing workflow run")
148-
_ = writeStruct(cfg.Debug, DebugSubDirWF, name, wr)
149+
_ = dumpResults(cfg.Debug, DebugSubDirWF, name, wr)
149150
eg.Go(func() error {
150151
rlJobs.Take()
151152
jobs, _, err := client.ListWorkflowJobs(ctx, cfg.Owner, cfg.Repo, *wr.ID, &github.ListWorkflowJobsOptions{
@@ -159,7 +160,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
159160
defer stats.Mu.Unlock()
160161
for _, j := range jobs.Jobs {
161162
name := *j.Name
162-
_ = writeStruct(cfg.Debug, DebugSubDirJobs, name, wr)
163+
_ = dumpResults(cfg.Debug, DebugSubDirJobs, name, wr)
163164
if skippedOrInProgressJob(j) {
164165
stats.IgnoredRuns++
165166
continue
@@ -283,6 +284,9 @@ func AnalyzeCIRuns(cfg *AnalysisConfig) (*Stats, error) {
283284
if err != nil {
284285
return nil, fmt.Errorf("failed to fetch workflow runs: %w", err)
285286
}
287+
if cfg.ResultsFile != "" {
288+
_ = dumpResults(true, DefaultResultsDir, DefaultResultsFile, stats)
289+
}
286290
return stats, nil
287291
}
288292

framework/cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func main() {
263263
TimeDaysBeforeStart: c.Int("start"),
264264
TimeDaysBeforeEnd: c.Int("end"),
265265
Typ: typ,
266+
ResultsFile: "ctf-ci.json",
266267
})
267268
return err
268269
},

0 commit comments

Comments
 (0)