Skip to content

perf(osv-linter): stream output, parallelize unzip, and skip unchanged uploads - #6509

Open
jess-lowe wants to merge 4 commits into
google:masterfrom
jess-lowe:perf/osv-linter-worker
Open

jess-lowe wants to merge 4 commits into
google:masterfrom
jess-lowe:perf/osv-linter-worker

Conversation

@jess-lowe

Copy link
Copy Markdown
Contributor

Overview

Improves runtime, peak memory, disk usage, and GCS write efficiency in osv-linter-worker without changing external behavior or output formats.

Details

  • Stream osv-linter JSON into typed structs: Replaces cmd.Output() + map[string][]map[string]any with cmd.StdoutPipe() + json.NewDecoder into map[string][]linterFinding (including omitempty Suppressed / SuppressedReason fields to keep suppressed result.json output byte-for-byte identical), draining stdout before cmd.Wait() and logging stderr on invalid/empty output.
  • Parallel unzip & archive cleanup: Hardens safeJoin with filepath.IsLocal (rejecting empty, absolute, and .. traversal paths), deduplicates parent directories once before extracting with a bounded errgroup worker pool, and removes the temporary GCS-downloaded all.zip after extraction (preserving -local-data).
  • Reuse storage.Client: Passes run()'s existing storageClient into prepareData() instead of creating a second client.
  • Align --parallel with CPU quota: Adds a -parallel flag defaulting to runtime.GOMAXPROCS(0) (cgroup-aware, clamped to >= 1) instead of hardcoded --parallel 10.
  • Lazy marshaling & CRC32C skip for unchanged uploads: Marshals per-source result.json lazily inside upload workers and compares Castagnoli CRC32C against attrs.CRC32C returned by ImportFindingsStore.ListResultSources (map[string]uint32), skipping redundant GCS writes (which also preserves GCS generation/updated timestamps for the website cache).

Testing

  • Added unit tests in go/cmd/osv-linter-worker/main_test.go covering parallel nested unzip + path-traversal rejection and CRC32C skip / changed upload / stale delete.
  • Ran inside go/:
    • gofmt -s -l ./cmd/osv-linter-worker ./internal/models ./internal/database/datastore (clean)
    • go vet ./cmd/osv-linter-worker/... ./internal/models/... ./internal/database/datastore/... (clean)
    • go build ./... (clean)
    • go test -count=1 -race -shuffle=on ./cmd/osv-linter-worker/... ./internal/gcs/... ./internal/website/... (all pass)
    • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 run ./cmd/osv-linter-worker/... ./internal/models/... ./internal/database/datastore/... (0 issues)

(This PR was authored with AI assistance.)

@codecov-commenter

codecov-commenter commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.50980% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.94%. Comparing base (f6b775a) to head (e061271).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
go/cmd/osv-linter-worker/main.go 76.00% 24 Missing ⚠️
go/internal/database/datastore/import_finding.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6509      +/-   ##
==========================================
+ Coverage   58.61%   58.94%   +0.32%     
==========================================
  Files         228      228              
  Lines       24740    24773      +33     
==========================================
+ Hits        14502    14602     +100     
+ Misses      10235    10168      -67     
  Partials        3        3              
Flag Coverage Δ
go 62.80% <74.50%> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

This branch has not been deployed

No deployments
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.

2 participants