Skip to content

Commit

Permalink
roll.go: add a flag to make buildbucket jobs a child of another task
Browse files Browse the repository at this point in the history
When the parent task is killed, the child jobs should be canceled too

Bug: dawn:1940
Change-Id: I489796ff16ce4ff87dacaf3d3a83049ead9c87f1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/147620
Kokoro: Kokoro <[email protected]>
Commit-Queue: Austin Eng <[email protected]>
Auto-Submit: Austin Eng <[email protected]>
Reviewed-by: Ben Clayton <[email protected]>
  • Loading branch information
austinEng authored and Dawn LUCI CQ committed Aug 21, 2023
1 parent 260ae98 commit 76130f0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
10 changes: 8 additions & 2 deletions tools/src/buildbucket/buildbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,24 @@ func (r *Buildbucket) StartBuild(
ctx context.Context,
ps gerrit.Patchset,
builder Builder,
parentSwarmingRunId string,
forceBuild bool) (Build, error) {

id := ""
if !forceBuild {
id = utils.Hash(ps, builder)
}

build, err := r.client.ScheduleBuild(ctx, &bbpb.ScheduleBuildRequest{
req := &bbpb.ScheduleBuildRequest{
RequestId: id,
Builder: builder.pb(),
GerritChanges: []*bbpb.GerritChange{gerritChange(ps)},
})
}
if parentSwarmingRunId != "" {
req.Swarming.ParentRunId = parentSwarmingRunId
}

build, err := r.client.ScheduleBuild(ctx, req)
if err != nil {
return Build{}, fmt.Errorf("failed to start build for patchset %+v on builder %+v: %w", ps, builder, err)
}
Expand Down
3 changes: 2 additions & 1 deletion tools/src/cmd/cts/common/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func GetOrStartBuildsAndWait(
cfg Config,
ps gerrit.Patchset,
bb *buildbucket.Buildbucket,
parentSwarmingRunId string,
retest bool) (BuildsByName, error) {

builds := BuildsByName{}
Expand Down Expand Up @@ -151,7 +152,7 @@ func GetOrStartBuildsAndWait(
// Kick any missing builds
for name, builder := range cfg.Builders {
if build, found := builds[name]; !found || shouldKick(build) {
build, err := bb.StartBuild(ctx, ps, builder, retest)
build, err := bb.StartBuild(ctx, ps, builder, parentSwarmingRunId, retest)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion tools/src/cmd/cts/common/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (r *ResultSource) GetResults(ctx context.Context, cfg Config, auth auth.Opt
// Obtain the patchset's results, kicking a build if there are no results
// already available.
log.Printf("fetching results from cl %v ps %v...", ps.Change, ps.Patchset)
builds, err := GetOrStartBuildsAndWait(ctx, cfg, *ps, bb, false)
builds, err := GetOrStartBuildsAndWait(ctx, cfg, *ps, bb, "", false)
if err != nil {
return nil, err
}
Expand Down
65 changes: 34 additions & 31 deletions tools/src/cmd/cts/roll/roll.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ const (
)

type rollerFlags struct {
gitPath string
npmPath string
nodePath string
auth authcli.Flags
cacheDir string
force bool // Create a new roll, even if CTS is up to date
rebuild bool // Rebuild the expectations file from scratch
preserve bool // If false, abandon past roll changes
sendToGardener bool // If true, automatically send to the gardener for review
gitPath string
npmPath string
nodePath string
auth authcli.Flags
cacheDir string
force bool // Create a new roll, even if CTS is up to date
rebuild bool // Rebuild the expectations file from scratch
preserve bool // If false, abandon past roll changes
sendToGardener bool // If true, automatically send to the gardener for review
parentSwarmingRunId string
}

type cmd struct {
Expand Down Expand Up @@ -104,7 +105,7 @@ func (c *cmd) RegisterFlags(ctx context.Context, cfg common.Config) ([]string, e
flag.BoolVar(&c.flags.rebuild, "rebuild", false, "rebuild the expectation file from scratch")
flag.BoolVar(&c.flags.preserve, "preserve", false, "do not abandon existing rolls")
flag.BoolVar(&c.flags.sendToGardener, "send-to-gardener", false, "send the CL to the WebGPU gardener for review")

flag.StringVar(&c.flags.parentSwarmingRunId, "parent-swarming-run-id", "", "parent swarming run id. All triggered tasks will be children of this task and will be canceled if the parent is canceled.")
return nil, nil
}

Expand Down Expand Up @@ -164,31 +165,33 @@ func (c *cmd) Run(ctx context.Context, cfg common.Config) error {

// Construct the roller, and roll
r := roller{
cfg: cfg,
flags: c.flags,
auth: auth,
bb: bb,
rdb: rdb,
git: git,
gerrit: gerrit,
chromium: chromium,
dawn: dawn,
ctsDir: ctsDir,
cfg: cfg,
flags: c.flags,
auth: auth,
bb: bb,
parentSwarmingRunId: c.flags.parentSwarmingRunId,
rdb: rdb,
git: git,
gerrit: gerrit,
chromium: chromium,
dawn: dawn,
ctsDir: ctsDir,
}
return r.roll(ctx)
}

type roller struct {
cfg common.Config
flags rollerFlags
auth auth.Options
bb *buildbucket.Buildbucket
rdb *resultsdb.ResultsDB
git *git.Git
gerrit *gerrit.Gerrit
chromium *gitiles.Gitiles
dawn *gitiles.Gitiles
ctsDir string
cfg common.Config
flags rollerFlags
auth auth.Options
bb *buildbucket.Buildbucket
parentSwarmingRunId string
rdb *resultsdb.ResultsDB
git *git.Git
gerrit *gerrit.Gerrit
chromium *gitiles.Gitiles
dawn *gitiles.Gitiles
ctsDir string
}

func (r *roller) roll(ctx context.Context) error {
Expand Down Expand Up @@ -335,7 +338,7 @@ func (r *roller) roll(ctx context.Context) error {
for attempt := 0; ; attempt++ {
// Kick builds
log.Printf("building (attempt %v)...\n", attempt)
builds, err := common.GetOrStartBuildsAndWait(ctx, r.cfg, ps, r.bb, false)
builds, err := common.GetOrStartBuildsAndWait(ctx, r.cfg, ps, r.bb, r.parentSwarmingRunId, false)
if err != nil {
return err
}
Expand Down

0 comments on commit 76130f0

Please sign in to comment.