Skip to content

Commit 8fab168

Browse files
committed
Merge branch 'main' of github.com:smartcontractkit/chainlink-testing-framework into updateParrotVersion
2 parents 9893e65 + b3bb9fb commit 8fab168

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
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: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515
"github.com/fatih/color"
1616
"github.com/google/go-github/v50/github"
1717
"github.com/google/uuid"
18-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1918
"go.uber.org/ratelimit"
2019
"golang.org/x/oauth2"
2120
"golang.org/x/sync/errgroup"
21+
22+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
2223
)
2324

2425
const (
@@ -38,9 +39,10 @@ var (
3839
SlowTestThreshold = 5 * time.Minute
3940
ExtremelySlowTestThreshold = 10 * time.Minute
4041

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

4648
type GitHubActionsClient interface {
@@ -49,38 +51,38 @@ type GitHubActionsClient interface {
4951
}
5052

5153
type AnalysisConfig struct {
52-
Debug bool
53-
Owner string
54-
Repo string
55-
WorkflowName string
56-
TimeDaysBeforeStart int
57-
TimeStart time.Time
58-
TimeDaysBeforeEnd int
59-
TimeEnd time.Time
60-
Typ string
61-
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"`
6264
}
6365

6466
type Stat struct {
65-
Name string
66-
Successes int
67-
Failures int
68-
Cancels int
69-
ReRuns int
70-
P50 time.Duration
71-
P95 time.Duration
72-
P99 time.Duration
73-
TotalDuration time.Duration
74-
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:"-"`
7577
}
7678

7779
type Stats struct {
78-
Mu *sync.Mutex
79-
Runs int
80-
CancelledRuns int
81-
IgnoredRuns int
82-
Jobs map[string]*Stat
83-
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"`
8486
}
8587

8688
func calculatePercentiles(stat *Stat) *Stat {
@@ -102,7 +104,7 @@ func refreshDebugDirs() {
102104
}
103105
}
104106

105-
func writeStruct(enabled bool, dir, name string, data interface{}) error {
107+
func dumpResults(enabled bool, dir, name string, data interface{}) error {
106108
if enabled {
107109
d, err := json.MarshalIndent(data, "", " ")
108110
if err != nil {
@@ -135,6 +137,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
135137

136138
eg := &errgroup.Group{}
137139
for _, wr := range runs.WorkflowRuns {
140+
framework.L.Debug().Str("Name", *wr.Name).Msg("Analyzing workflow run")
138141
if !strings.Contains(*wr.Name, cfg.WorkflowName) {
139142
stats.IgnoredRuns++
140143
continue
@@ -143,7 +146,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
143146
// analyze workflow
144147
name := *wr.Name
145148
framework.L.Debug().Str("Name", name).Msg("Analyzing workflow run")
146-
_ = writeStruct(cfg.Debug, DebugSubDirWF, name, wr)
149+
_ = dumpResults(cfg.Debug, DebugSubDirWF, name, wr)
147150
eg.Go(func() error {
148151
rlJobs.Take()
149152
jobs, _, err := client.ListWorkflowJobs(ctx, cfg.Owner, cfg.Repo, *wr.ID, &github.ListWorkflowJobsOptions{
@@ -153,11 +156,11 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
153156
return err
154157
}
155158
// analyze jobs
159+
stats.Mu.Lock()
160+
defer stats.Mu.Unlock()
156161
for _, j := range jobs.Jobs {
157-
stats.Mu.Lock()
158-
defer stats.Mu.Unlock()
159162
name := *j.Name
160-
_ = writeStruct(cfg.Debug, DebugSubDirJobs, name, wr)
163+
_ = dumpResults(cfg.Debug, DebugSubDirJobs, name, wr)
161164
if skippedOrInProgressJob(j) {
162165
stats.IgnoredRuns++
163166
continue
@@ -281,6 +284,9 @@ func AnalyzeCIRuns(cfg *AnalysisConfig) (*Stats, error) {
281284
if err != nil {
282285
return nil, fmt.Errorf("failed to fetch workflow runs: %w", err)
283286
}
287+
if cfg.ResultsFile != "" {
288+
_ = dumpResults(true, DefaultResultsDir, DefaultResultsFile, stats)
289+
}
284290
return stats, nil
285291
}
286292

framework/cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010
"strings"
1111

1212
"github.com/pelletier/go-toml"
13-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1413
"github.com/urfave/cli/v2"
14+
15+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1516
)
1617

1718
//go:embed observability/*
@@ -262,6 +263,7 @@ func main() {
262263
TimeDaysBeforeStart: c.Int("start"),
263264
TimeDaysBeforeEnd: c.Int("end"),
264265
Typ: typ,
266+
ResultsFile: "ctf-ci.json",
265267
})
266268
return err
267269
},

0 commit comments

Comments
 (0)