Skip to content

Commit 0688f5e

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

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-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: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ 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+
DebugDirRoot = "ctf-ci-debug"
43+
DebugSubDirWF = filepath.Join(DebugDirRoot, "workflows")
44+
DebugSubDirJobs = filepath.Join(DebugDirRoot, "jobs")
45+
DefaultResultsDir = "."
46+
DefaultResultsFile = "ctf-ci"
4547
)
4648

4749
type GitHubActionsClient interface {
@@ -50,38 +52,38 @@ type GitHubActionsClient interface {
5052
}
5153

5254
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
55+
Debug bool `json:"debug"`
56+
Owner string `json:"owner"`
57+
Repo string `json:"repo"`
58+
WorkflowName string `json:"workflow_name"`
59+
TimeDaysBeforeStart int `json:"time_days_before_start"`
60+
TimeStart time.Time `json:"time_start"`
61+
TimeDaysBeforeEnd int `json:"time_days_before_end"`
62+
TimeEnd time.Time `json:"time_end"`
63+
Typ string `json:"type"`
64+
ResultsFile string `json:"results_file"`
6365
}
6466

6567
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
68+
Name string `json:"name"`
69+
Successes int `json:"successes"`
70+
Failures int `json:"failures"`
71+
Cancels int `json:"cancels"`
72+
ReRuns int `json:"reRuns"`
73+
P50 time.Duration `json:"p50"`
74+
P95 time.Duration `json:"p95"`
75+
P99 time.Duration `json:"p99"`
76+
TotalDuration time.Duration `json:"totalDuration"`
77+
Durations []time.Duration `json:"-"`
7678
}
7779

7880
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
81+
Mu *sync.Mutex `json:"-"`
82+
Runs int `json:"runs"`
83+
CancelledRuns int `json:"cancelled_runs"`
84+
IgnoredRuns int `json:"ignored_runs"`
85+
Jobs map[string]*Stat `json:"jobs"`
86+
Steps map[string]*Stat `json:"steps"`
8587
}
8688

8789
func calculatePercentiles(stat *Stat) *Stat {
@@ -103,7 +105,7 @@ func refreshDebugDirs() {
103105
}
104106
}
105107

106-
func writeStruct(enabled bool, dir, name string, data interface{}) error {
108+
func dumpResults(enabled bool, dir, name string, data interface{}) error {
107109
if enabled {
108110
d, err := json.MarshalIndent(data, "", " ")
109111
if err != nil {
@@ -145,7 +147,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
145147
// analyze workflow
146148
name := *wr.Name
147149
framework.L.Debug().Str("Name", name).Msg("Analyzing workflow run")
148-
_ = writeStruct(cfg.Debug, DebugSubDirWF, name, wr)
150+
_ = dumpResults(cfg.Debug, DebugSubDirWF, name, wr)
149151
eg.Go(func() error {
150152
rlJobs.Take()
151153
jobs, _, err := client.ListWorkflowJobs(ctx, cfg.Owner, cfg.Repo, *wr.ID, &github.ListWorkflowJobsOptions{
@@ -159,7 +161,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
159161
defer stats.Mu.Unlock()
160162
for _, j := range jobs.Jobs {
161163
name := *j.Name
162-
_ = writeStruct(cfg.Debug, DebugSubDirJobs, name, wr)
164+
_ = dumpResults(cfg.Debug, DebugSubDirJobs, name, wr)
163165
if skippedOrInProgressJob(j) {
164166
stats.IgnoredRuns++
165167
continue
@@ -283,6 +285,9 @@ func AnalyzeCIRuns(cfg *AnalysisConfig) (*Stats, error) {
283285
if err != nil {
284286
return nil, fmt.Errorf("failed to fetch workflow runs: %w", err)
285287
}
288+
if cfg.ResultsFile != "" {
289+
_ = dumpResults(true, DefaultResultsDir, DefaultResultsFile, stats)
290+
}
286291
return stats, nil
287292
}
288293

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)