aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/controller
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-01-31 12:38:41 +0100
committerAleksandr Nogikh <nogikh@google.com>2025-02-04 14:57:28 +0000
commit2cfec537a35f8e7bcb50a3302d73bb98be70e426 (patch)
tree27f60eebd3368729e00a35b1662662771948d0df /syz-cluster/controller
parent10f46061d0a00f1bfb6c1f0f34509e1656a3bb23 (diff)
syz-cluster: store session test logs
Record the logs from the build and fuzzing steps.
Diffstat (limited to 'syz-cluster/controller')
-rw-r--r--syz-cluster/controller/api.go2
-rw-r--r--syz-cluster/controller/api_test.go1
-rw-r--r--syz-cluster/controller/services.go34
3 files changed, 29 insertions, 8 deletions
diff --git a/syz-cluster/controller/api.go b/syz-cluster/controller/api.go
index e5cb18a27..3e25b2ba4 100644
--- a/syz-cluster/controller/api.go
+++ b/syz-cluster/controller/api.go
@@ -102,7 +102,7 @@ func (c ControllerAPI) uploadTest(w http.ResponseWriter, r *http.Request) {
if req == nil {
return
}
- // TODO: add parameters validation.
+ // TODO: add parameters validation (and also of the Log size).
err := c.testService.Save(r.Context(), req)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
diff --git a/syz-cluster/controller/api_test.go b/syz-cluster/controller/api_test.go
index bc205392b..99532bc77 100644
--- a/syz-cluster/controller/api_test.go
+++ b/syz-cluster/controller/api_test.go
@@ -67,6 +67,7 @@ func TestAPISaveFinding(t *testing.T) {
BaseBuildID: buildResp.ID,
TestName: "test",
Result: api.TestRunning,
+ Log: []byte("some log"),
})
assert.NoError(t, err)
diff --git a/syz-cluster/controller/services.go b/syz-cluster/controller/services.go
index 1ec178956..fc1ce183b 100644
--- a/syz-cluster/controller/services.go
+++ b/syz-cluster/controller/services.go
@@ -143,28 +143,48 @@ func (s *BuildService) LastBuild(ctx context.Context, req *api.LastBuildReq) (*a
}
type SessionTestService struct {
- testRepo *db.SessionTestRepository
+ testRepo *db.SessionTestRepository
+ blobStorage blob.Storage
}
func NewSessionTestService(env *app.AppEnvironment) *SessionTestService {
return &SessionTestService{
- testRepo: db.NewSessionTestRepository(env.Spanner),
+ testRepo: db.NewSessionTestRepository(env.Spanner),
+ blobStorage: env.BlobStorage,
}
}
func (s *SessionTestService) Save(ctx context.Context, req *api.TestResult) error {
- entity := &db.SessionTest{
- SessionID: req.SessionID,
- TestName: req.TestName,
- Result: req.Result,
- UpdatedAt: time.Now(),
+ entity, err := s.testRepo.Get(ctx, req.SessionID, req.TestName)
+ if err != nil {
+ return fmt.Errorf("failed to query the test: %w", err)
+ } else if entity == nil {
+ entity = &db.SessionTest{
+ SessionID: req.SessionID,
+ TestName: req.TestName,
+ }
}
+ entity.Result = req.Result
+ entity.UpdatedAt = time.Now()
if req.BaseBuildID != "" {
entity.BaseBuildID = spanner.NullString{StringVal: req.BaseBuildID, Valid: true}
}
if req.PatchedBuildID != "" {
entity.PatchedBuildID = spanner.NullString{StringVal: req.PatchedBuildID, Valid: true}
}
+ if entity.LogURI != "" {
+ err := s.blobStorage.Update(entity.LogURI, bytes.NewReader(req.Log))
+ if err != nil {
+ return fmt.Errorf("failed to update the log: %w", err)
+ }
+ } else if len(req.Log) > 0 {
+ // TODO: it will leak if we fail to save the entity.
+ uri, err := s.blobStorage.Store(bytes.NewReader(req.Log))
+ if err != nil {
+ return fmt.Errorf("failed to save the log: %w", err)
+ }
+ entity.LogURI = uri
+ }
return s.testRepo.InsertOrUpdate(context.Background(), entity)
}