aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/batch_main.go
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-10-07 14:09:32 +0200
committerTaras Madan <tarasmadan@google.com>2024-10-11 09:26:22 +0000
commit5e7b4bcaa61e8bb9b1d1fbca21684fe490f69133 (patch)
treed3ce0eaf57e6d169b7688215f0dbd68268269e40 /dashboard/app/batch_main.go
parentcd942402d6bc82fa3ea87e5c43509e1ec6cfafe2 (diff)
dashboard/app: introduce batch_reproexport
This PR exports the latest reproducer for every bug. Reproducers are exported to the "bug_id/repro_id.c" files. This approach allows to add some metadata files or export more reproducers/bug later. All the files are then archived and uploaded to the preconfigured location.
Diffstat (limited to 'dashboard/app/batch_main.go')
-rw-r--r--dashboard/app/batch_main.go99
1 files changed, 99 insertions, 0 deletions
diff --git a/dashboard/app/batch_main.go b/dashboard/app/batch_main.go
new file mode 100644
index 000000000..acf37ee8f
--- /dev/null
+++ b/dashboard/app/batch_main.go
@@ -0,0 +1,99 @@
+// Copyright 2017 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package main
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+
+ "cloud.google.com/go/batch/apiv1"
+ "cloud.google.com/go/batch/apiv1/batchpb"
+ "github.com/google/uuid"
+ "google.golang.org/appengine/v2/log"
+ "google.golang.org/protobuf/types/known/durationpb"
+)
+
+func initBatchProcessors() {
+ http.HandleFunc("/cron/batch_coverage", handleBatchCoverage)
+ http.HandleFunc("/cron/batch_reproexport", handleBatchReproExport)
+}
+
+// from https://cloud.google.com/batch/docs/samples/batch-create-script-job
+func createScriptJob(ctx context.Context, projectID, jobNamePrefix, script string,
+ timeout int64, sa *batchpb.ServiceAccount) error {
+ region := "us-central1"
+ jobName := fmt.Sprintf("%s-%s", jobNamePrefix, uuid.New().String())
+
+ batchClient, err := batch.NewClient(ctx)
+ if err != nil {
+ return fmt.Errorf("failed NewClient: %w", err)
+ }
+ defer batchClient.Close()
+
+ taskGroups := []*batchpb.TaskGroup{
+ {
+ TaskSpec: &batchpb.TaskSpec{
+ Runnables: []*batchpb.Runnable{{
+ Executable: &batchpb.Runnable_Script_{
+ Script: &batchpb.Runnable_Script{Command: &batchpb.Runnable_Script_Text{
+ Text: script,
+ }},
+ },
+ }},
+ ComputeResource: &batchpb.ComputeResource{
+ // CpuMilli is milliseconds per cpu-second. This means the task requires 2 whole CPUs.
+ CpuMilli: 4000,
+ MemoryMib: 12 * 1024,
+ },
+ MaxRunDuration: &durationpb.Duration{
+ Seconds: timeout,
+ },
+ },
+ },
+ }
+
+ // Policies are used to define on what kind of virtual machines the tasks will run on.
+ // In this case, we tell the system to use "e2-standard-4" machine type.
+ // Read more about machine types here: https://cloud.google.com/compute/docs/machine-types
+ allocationPolicy := &batchpb.AllocationPolicy{
+ Instances: []*batchpb.AllocationPolicy_InstancePolicyOrTemplate{{
+ PolicyTemplate: &batchpb.AllocationPolicy_InstancePolicyOrTemplate_Policy{
+ Policy: &batchpb.AllocationPolicy_InstancePolicy{
+ ProvisioningModel: batchpb.AllocationPolicy_SPOT,
+ MachineType: "c3-standard-4",
+ },
+ },
+ }},
+ ServiceAccount: sa,
+ }
+
+ logsPolicy := &batchpb.LogsPolicy{
+ Destination: batchpb.LogsPolicy_CLOUD_LOGGING,
+ }
+
+ // The job's parent is the region in which the job will run.
+ parent := fmt.Sprintf("projects/%s/locations/%s", projectID, region)
+
+ job := batchpb.Job{
+ TaskGroups: taskGroups,
+ AllocationPolicy: allocationPolicy,
+ LogsPolicy: logsPolicy,
+ }
+
+ req := &batchpb.CreateJobRequest{
+ Parent: parent,
+ JobId: jobName,
+ Job: &job,
+ }
+
+ createdJob, err := batchClient.CreateJob(ctx, req)
+ if err != nil {
+ return fmt.Errorf("unable to create job: %w", err)
+ }
+
+ log.Infof(ctx, "job created: %v\n", createdJob)
+
+ return nil
+}