Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions go/cmd/vanir_sandbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,17 @@ func (s *sandboxServer) handleGenerate(w http.ResponseWriter, r *http.Request) {
//nolint:gosec // G115: uidBase + (n % uidSpan) is always in [10000, 59999].
uid := uint32(uidBase + (n % uidSpan))

start := time.Now()
logger.InfoContext(ctx, "Generating Vanir signatures",
slog.String("vuln_id", meta.ID),
slog.Int64("seq", n))

sigs, err := s.executeRequest(ctx, n, uid, meta.ID, &req)
if err != nil {
logger.ErrorContext(ctx, "Sandbox execution failed",
slog.String("vuln_id", meta.ID),
slog.Int64("seq", n),
slog.Duration("duration", time.Since(start)),
slog.Any("error", err))
status := http.StatusInternalServerError
if errors.Is(err, errChildTimeout) {
Expand All @@ -191,6 +197,12 @@ func (s *sandboxServer) handleGenerate(w http.ResponseWriter, r *http.Request) {
return
}

logger.InfoContext(ctx, "Generated Vanir signatures",
slog.String("vuln_id", meta.ID),
slog.Int64("seq", n),
slog.Bool("has_signatures", len(sigs) > 2),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not len(sigs) > 0 for has_signatures?

slog.Duration("duration", time.Since(start)))

respBytes, err := json.Marshal(GenerateResponse{Signatures: sigs})
if err != nil {
http.Error(w, fmt.Sprintf("failed to marshal response: %v", err), http.StatusInternalServerError)
Expand Down
33 changes: 27 additions & 6 deletions go/internal/vanir/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,30 @@ func (r *Runner) Run(ctx context.Context) error {
var allFailedIDs []string

for outcome := range outcomeCh {
prevMilestone := totalProcessed / 100
totalProcessed += outcome.processed
totalGenerated += outcome.generated
allFailedIDs = append(allFailedIDs, outcome.failedIDs...)
if totalProcessed/100 > prevMilestone {
logger.InfoContext(ctx, "Vanir signature generation progress",
slog.Int("processed", totalProcessed),
slog.Int("generated", totalGenerated),
slog.Int("failed", len(allFailedIDs)))
}
}

if fatalErr != nil {
return fatalErr
}

logger.InfoContext(ctx, "Finished Vanir signature generation",
slog.Int("processed", totalProcessed),
slog.Int("generated", totalGenerated))

slices.Sort(allFailedIDs)
uniqueFailedIDs := slices.Compact(allFailedIDs)

logger.InfoContext(ctx, "Finished Vanir signature generation",
slog.Int("processed", totalProcessed),
slog.Int("generated", totalGenerated),
slog.Int("failed", len(uniqueFailedIDs)))

if r.Config.DryRun {
logger.InfoContext(ctx, "Dry run: would have updated last_run", slog.Time("last_run", currentRun))
if len(uniqueFailedIDs) > 0 {
Expand Down Expand Up @@ -236,11 +244,23 @@ func (r *Runner) processBatch(ctx context.Context, batch []*osvschema.Vulnerabil
return 0, nil
}

logger.InfoContext(ctx, "Processing batch of vulnerabilities", slog.Int("count", len(batch)))
if len(batch) == 1 {
logger.InfoContext(ctx, "Processing vulnerability", slog.String("id", batch[0].GetId()))
} else {
logger.InfoContext(ctx, "Processing batch of vulnerabilities", slog.Int("count", len(batch)))
}

sigMap, err := r.Generator.GenerateBatch(ctx, batch)
if err != nil {
logger.ErrorContext(ctx, "Failed to generate Vanir signatures for batch", slog.Int("count", len(batch)), slog.Any("error", err))
if len(batch) == 1 {
logger.ErrorContext(ctx, "Failed to generate Vanir signatures",
slog.String("id", batch[0].GetId()),
slog.Any("error", err))
} else {
logger.ErrorContext(ctx, "Failed to generate Vanir signatures for batch",
slog.Int("count", len(batch)),
slog.Any("error", err))
}
ids := make([]string, 0, len(batch))
for _, v := range batch {
ids = append(ids, v.GetId())
Expand Down Expand Up @@ -276,6 +296,7 @@ func (r *Runner) processBatch(ctx context.Context, batch []*osvschema.Vulnerabil
continue
}
if updated {
logger.InfoContext(ctx, "Updated vulnerability with Vanir signatures", slog.String("id", id))
updatedCount++
}
}
Expand Down
Loading