Skip to content

dashboard/app: add a helper to fix up build arches#7409

Draft
a-nogikh wants to merge 1 commit into
google:masterfrom
a-nogikh:features/patch-builds
Draft

dashboard/app: add a helper to fix up build arches#7409
a-nogikh wants to merge 1 commit into
google:masterfrom
a-nogikh:features/patch-builds

Conversation

@a-nogikh

Copy link
Copy Markdown
Collaborator

Before sending a pull request, please review Contribution Guidelines:
https://github.com/google/syzkaller/blob/master/docs/contributing.md


@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new admin endpoint patchBuildArchs to update build architectures for a specified namespace. The review feedback highlights critical improvements for the implementation: optimizing the Datastore query by filtering on the architecture directly to prevent potential OOMs, postponing HTTP header writes until after fallible operations to ensure proper error handling, and simplifying the update logic by removing the temporary mapping.

Comment thread dashboard/app/admin.go
Comment on lines +434 to +481
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintf(w, "Patching builds for namespace %q (dry_run=%v)\n", ns, dryRun)

var builds []*Build
keys, err := db.NewQuery("Build").
Filter("Namespace=", ns).
GetAll(ctx, &builds)
if err != nil {
return fmt.Errorf("failed to query builds: %w", err)
}

var toUpdate []*db.Key
newArchs := make(map[string]string)

for i, build := range builds {
if build.Arch != "x86_64" {
continue
}

targetArch := "amd64"
if arm64Re.MatchString(build.Manager) {
targetArch = "arm64"
}
if targetArch == build.Arch {
continue
}

key := keys[i]
toUpdate = append(toUpdate, key)
newArchs[key.String()] = targetArch

fmt.Fprintf(w, "Build %q (Manager: %q) %q -> %q\n", build.ID, build.Manager, build.Arch, targetArch)
}

fmt.Fprintf(w, "Found %d builds to patch.\n", len(toUpdate))

if dryRun {
fmt.Fprintf(w, "Dry run, skipping datastore update.\n")
return nil
}

return updateBatch(ctx, toUpdate, func(key *db.Key, b *Build) {
targetArch, ok := newArchs[key.String()]
if !ok {
panic("unknown build key")
}
b.Arch = targetArch
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are a few significant improvement opportunities in this helper function:

  1. Efficiency: Instead of querying all builds for the namespace and filtering them in memory, you can filter by Arch = "x86_64" directly in the Datastore query. For namespaces with a large history (like upstream), loading all builds can cause Out Of Memory (OOM) errors or request timeouts.
  2. Correctness: Setting headers and writing to the response writer before performing fallible operations (like Datastore queries) is an anti-pattern. If the query fails, the error handler will try to write an HTML error page, but the Content-Type header is already set to text/plain, causing the browser to render raw HTML.
  3. Simplicity: The newArchs map and key stringification can be completely eliminated by re-evaluating the target architecture inside the updateBatch callback.
	var builds []*Build
	keys, err := db.NewQuery("Build").
		Filter("Namespace=", ns).
		Filter("Arch=", "x86_64").
		GetAll(ctx, &builds)
	if err != nil {
		return fmt.Errorf("failed to query builds: %w", err)
	}

	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	fmt.Fprintf(w, "Patching builds for namespace %q (dry_run=%v)\n", ns, dryRun)

	var toUpdate []*db.Key
	for i, build := range builds {
		targetArch := "amd64"
		if arm64Re.MatchString(build.Manager) {
			targetArch = "arm64"
		}

		key := keys[i]
		toUpdate = append(toUpdate, key)

		fmt.Fprintf(w, "Build %q (Manager: %q) %q -> %q\n", build.ID, build.Manager, build.Arch, targetArch)
	}

	fmt.Fprintf(w, "Found %d builds to patch.\n", len(toUpdate))

	if dryRun {
		fmt.Fprintf(w, "Dry run, skipping datastore update.\n")
		return nil
	}

	return updateBatch(ctx, toUpdate, func(key *db.Key, b *Build) {
		if arm64Re.MatchString(b.Manager) {
			b.Arch = "arm64"
		} else {
			b.Arch = "amd64"
		}
	})

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.7%. Comparing base (9a5a7e5) to head (1da7d27).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
dashboard/app/admin.go 0.0% 44 Missing ⚠️
dashboard/app/main.go 0.0% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
dashboard/app/main.go 66.9% <0.0%> (-1.6%) ⬇️
dashboard/app/admin.go 1.9% <0.0%> (-0.3%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant