Skip to content

Commit 8d018ec

Browse files
shuyama1SirGitsalot
authored andcommitted
Split nightly test data ingestion from ticket creation (#16240)
1 parent 9abfa87 commit 8d018ec

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

.ci/gcb-ingest-test-data.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
steps:
3+
- name: 'gcr.io/graphite-docker-images/go-plus'
4+
id: collect-nightly-test-status
5+
entrypoint: '/workspace/.ci/scripts/go-plus/magician/exec.sh'
6+
secretEnv: ["TEAMCITY_TOKEN"]
7+
args:
8+
- 'collect-nightly-test-status'
9+
- $_CUSTOM_DATE
10+
11+
timeout: 3600s
12+
options:
13+
machineType: 'N1_HIGHCPU_32'
14+
15+
logsBucket: 'gs://cloudbuild-ingest-test-data-logs'
16+
availableSecrets:
17+
secretManager:
18+
- versionName: projects/673497134629/secrets/teamcity-token/versions/latest
19+
env: TEAMCITY_TOKEN

.ci/gcb-test-failure-ticket.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
---
22
steps:
3-
- name: 'gcr.io/graphite-docker-images/go-plus'
4-
id: collect-nightly-test-status
5-
entrypoint: '/workspace/.ci/scripts/go-plus/magician/exec.sh'
6-
secretEnv: ["TEAMCITY_TOKEN"]
7-
args:
8-
- 'collect-nightly-test-status'
9-
- $_CUSTOM_DATE
103
- name: 'gcr.io/graphite-docker-images/go-plus'
114
id: create-test-failure-ticket
125
entrypoint: '/workspace/.ci/scripts/go-plus/magician/exec.sh'
136
secretEnv: ["GITHUB_TOKEN"]
147
waitFor: ["collect-nightly-test-status"]
158
args:
169
- 'create-test-failure-ticket'
17-
- name: 'ubuntu'
18-
args: ['sleep', '120']
1910
- name: 'gcr.io/graphite-docker-images/go-plus'
2011
id: manage-test-failure-ticket
2112
entrypoint: '/workspace/.ci/scripts/go-plus/magician/exec.sh'
@@ -31,7 +22,5 @@ options:
3122
logsBucket: 'gs://cloudbuild-test-failure-ticket-logs'
3223
availableSecrets:
3324
secretManager:
34-
- versionName: projects/673497134629/secrets/teamcity-token/versions/latest
35-
env: TEAMCITY_TOKEN
3625
- versionName: projects/673497134629/secrets/github-classic--repo-workflow/versions/latest
3726
env: GITHUB_TOKEN

.ci/magician/cmd/collect_nightly_test_status.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,27 @@ var collectNightlyTestStatusCmd = &cobra.Command{
8484
tc := teamcity.NewClient(env["TEAMCITY_TOKEN"])
8585
gcs := cloudstorage.NewClient()
8686

87-
now := time.Now()
88-
8987
loc, err := time.LoadLocation("America/Los_Angeles")
9088
if err != nil {
9189
return fmt.Errorf("Error loading location: %s", err)
9290
}
93-
date := now.In(loc)
91+
92+
now := time.Now().In(loc)
93+
year, month, day := now.Date()
94+
9495
customDate := args[0]
9596
// check if a specific date is provided
9697
if customDate != "" {
9798
parsedDate, err := time.Parse("2006-01-02", customDate) // input format YYYY-MM-DD
98-
// Set the time to 7pm PT
99-
date = time.Date(parsedDate.Year(), parsedDate.Month(), parsedDate.Day(), 19, 0, 0, 0, loc)
10099
if err != nil {
101100
return fmt.Errorf("invalid input time format: %w", err)
102101
}
102+
year, month, day = parsedDate.Date()
103103
}
104104

105+
// Set the time to 7pm PT
106+
date := time.Date(year, month, day, 19, 0, 0, 0, loc)
107+
105108
return execCollectNightlyTestStatus(date, tc, gcs)
106109
},
107110
}
@@ -134,10 +137,31 @@ func execCollectNightlyTestStatus(now time.Time, tc TeamcityClient, gcs Cloudsto
134137
}
135138

136139
func createTestReport(pVersion provider.Version, tc TeamcityClient, gcs CloudstorageClient, formattedStartCut, formattedFinishCut, date string) error {
140+
141+
// Check Queued Builds
142+
queuedBuilds, err := tc.GetBuilds("queued", pVersion.TeamCityNightlyProjectName(), formattedFinishCut, formattedStartCut)
143+
if err != nil {
144+
return fmt.Errorf("failed to get queued builds: %w", err)
145+
}
146+
if len(queuedBuilds.Builds) > 0 {
147+
fmt.Printf("%s Test unfinished: there are still %d builds queued.\n", strings.ToUpper(pVersion.String()), len(queuedBuilds.Builds))
148+
return nil
149+
}
150+
151+
// Check Running Builds
152+
runningBuilds, err := tc.GetBuilds("running", pVersion.TeamCityNightlyProjectName(), formattedFinishCut, formattedStartCut)
153+
if err != nil {
154+
return fmt.Errorf("failed to get running builds: %w", err)
155+
}
156+
if len(runningBuilds.Builds) > 0 {
157+
fmt.Printf("%s Test unfinished: there are still %d builds running.\n", strings.ToUpper(pVersion.String()), len(runningBuilds.Builds))
158+
return nil
159+
}
160+
137161
// Get all service test builds
138-
builds, err := tc.GetBuilds(pVersion.TeamCityNightlyProjectName(), formattedFinishCut, formattedStartCut)
162+
builds, err := tc.GetBuilds("finished", pVersion.TeamCityNightlyProjectName(), formattedFinishCut, formattedStartCut)
139163
if err != nil {
140-
return err
164+
return fmt.Errorf("failed to get finished builds: %w", err)
141165
}
142166

143167
var testInfoList []TestInfo

.ci/magician/cmd/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type CloudstorageClient interface {
5050
}
5151

5252
type TeamcityClient interface {
53-
GetBuilds(project, finishCut, startCut string) (teamcity.Builds, error)
53+
GetBuilds(state, project, finishCut, startCut string) (teamcity.Builds, error)
5454
GetTestResults(build teamcity.Build) (teamcity.TestResults, error)
5555
}
5656

.ci/magician/teamcity/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ type FirstFailed struct {
5454
Href string `json:"href"`
5555
}
5656

57-
func (tc *Client) GetBuilds(project, finishCut, startCut string) (Builds, error) {
58-
url := fmt.Sprintf("https://hashicorp.teamcity.com/app/rest/builds?locator=count:500,tag:cron-trigger,project:%s,branch:refs/heads/nightly-test,queuedDate:(date:%s,condition:before),queuedDate:(date:%s,condition:after)&fields=build(id,buildTypeId,buildConfName,webUrl,number,queuedDate,startDate,finishDate)", project, finishCut, startCut)
57+
func (tc *Client) GetBuilds(state, project, finishCut, startCut string) (Builds, error) {
58+
url := fmt.Sprintf("https://hashicorp.teamcity.com/app/rest/builds?locator=state:%s,count:500,tag:cron-trigger,project:%s,branch:refs/heads/nightly-test,queuedDate:(date:%s,condition:before),queuedDate:(date:%s,condition:after)&fields=build(id,buildTypeId,buildConfName,webUrl,number,queuedDate,startDate,finishDate)", state, project, finishCut, startCut)
5959

6060
var builds Builds
6161

0 commit comments

Comments
 (0)