From 2cfec537a35f8e7bcb50a3302d73bb98be70e426 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 31 Jan 2025 12:38:41 +0100 Subject: syz-cluster: store session test logs Record the logs from the build and fuzzing steps. --- syz-cluster/controller/api.go | 2 +- syz-cluster/controller/api_test.go | 1 + syz-cluster/controller/services.go | 34 +++++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 8 deletions(-) (limited to 'syz-cluster/controller') 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) } -- cgit mrf-deployment