Skip to content

feat(coverage): detect -cover from Go build info before the symbol scan - #4984

Open
Gauravsingh096 wants to merge 3 commits into
mainfrom
feat/go-code-coverage
Open

Gauravsingh096 wants to merge 3 commits into
mainfrom
feat/go-code-coverage

Conversation

@Gauravsingh096

@Gauravsingh096 Gauravsingh096 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Describe the changes that are made

  • checkForCoverFlag (pkg/platform/coverage/golang/utils.go) now reads the binary's Go build info first: -cover=true in its build settings means the app was built with -cover. Only when build info says nothing does it fall back to the existing symbol scan.
  • Fixes a miss: a -cover binary built with -ldflags='-s -w' has -cover=true in build info but no internal/coverage symbols, so the old check said "not built with -cover". Works on Mach-O too.
  • Scope: native runs only (the only caller, golang.go:41); OSS aggregate coverage, not the per-test path.

Links & References

Issue: Part of keploy/k8s-proxy#1133 — https://github.com/keploy/k8s-proxy/issues/1133

🔗 Related PRs

🐞 Related Issues

📄 Related Documents

  • NA

What type of PR is this? (check all applicable)

  • 📦 Chore
  • 🍕 Feature
  • 🐞 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🔁 CI
  • ⏩ Revert

Added e2e test pipeline?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added comments for hard-to-understand areas?

  • 👍 yes
  • 🙅 no, because the code is self-explanatory

Added to documentation?

  • 📜 README.md
  • 📓 Wiki
  • 🙅 no documentation needed

Are there any sample code or steps to test the changes?

  • 👍 yes, mentioned below
  • 🙅 no, because it is not needed

go test ./pkg/platform/coverage/golang/ — the new utils_test.go checks builtWithCover on build-settings lists only (it builds no binary). The fix itself was checked by running checkForCoverFlag on real Go 1.27.1 binaries: -cover -ldflags='-s -w' gives false on the merge base and true here; -cover gives true on both; a plain build gives false on both.

Known limit (not changed here): a plain binary that imports go-sdk links runtime/coverage, so the symbol fallback can still say "covered" for it.

Self Review done?

  • ✅ yes
  • ❌ no, because I need help

Any relevant screenshots, recordings or logs?

  • NA

Additional checklist:

🤖 Generated with Claude Code

…an (O1)

Signed-off-by: Gaurav Singh <singhgaurav07122004@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:22

Copilot AI left a comment

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.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

@github-actions

Copy link
Copy Markdown

🚀 Keploy Performance Test Results

Multi-Run Validation: Tests run 3 times, pipeline fails only if 2+ runs show regression.

Run P50 P90 P99 RPS Error Rate Status
1 3.01ms 3.9ms 5.35ms 100.02 0.00% ✅ PASS
2 2.85ms 3.65ms 5.07ms 100.00 0.00% ✅ PASS
3 2.77ms 3.52ms 5.1ms 100.02 0.00% ✅ PASS

Thresholds: P50 < 5ms, P90 < 15ms, P99 < 70ms, RPS >= 100 (±1% tolerance), Error Rate < 1%

✅ Result: PASSED - Only 0 out of 3 runs failed (threshold: 2)

P50, P90, and P99 percentiles naturally filter out outliers

@github-actions

Copy link
Copy Markdown

🚀 Keploy Performance Test Results

Multi-Run Validation: Tests run 3 times, pipeline fails only if 2+ runs show regression.

Run P50 P90 P99 RPS Error Rate Status
1 2.2ms 2.85ms 3.95ms 100.02 0.00% ✅ PASS
2 2.1ms 2.65ms 3.9ms 100.02 0.00% ✅ PASS
3 2.09ms 2.64ms 3.66ms 100.02 0.00% ✅ PASS

Thresholds: P50 < 5ms, P90 < 15ms, P99 < 70ms, RPS >= 100 (±1% tolerance), Error Rate < 1%

✅ Result: PASSED - Only 0 out of 3 runs failed (threshold: 2)

P50, P90, and P99 percentiles naturally filter out outliers

@Gauravsingh096 Gauravsingh096 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Principal review: #4984 at 5645641, approve with follow-ups

Reviewed as one set with go-sdk#208, enterprise#3136, api-server#2420, enterprise-ui#2027 and k8s-proxy#1163, each repo at its own PR head. I read the diff, utils.go in full and its only caller (golang.go:41). I ran checkForCoverFlag on real binaries. Not run live.

Verified fine:

  • The fix works. I built three binaries with Go 1.27.1 and called checkForCoverFlag on each, at the merge base and at this head:

    • -cover -ldflags='-s -w': false on the base, true at the head.
    • -cover: true on both.
    • plain build: false on both.

    go version -m shows build -cover=true on both cover binaries.

  • Build info first, symbol scan second. A binary with no build info, or no -cover=true, still falls through to the old symbol scan, so nothing that was detected before is lost.

  • The known limit is real and correctly stated. A plain binary that imports runtime/coverage gives true from the symbol fallback (probe).

Gates:

  • go test -count=1 -v ./pkg/platform/coverage/golang/: PASS.
  • The new test does not compile on the merge base (undefined: builtWithCover).
  • With the call at utils.go:35 disabled at the head, the test still passes (M1).

Earlier reviews

Reviewer Point Status
copilot-pull-request-reviewer "unable to review any files" n/a

Minor

M1. The test passes with the fix removed, and the PR body describes a test that does not exist. (inline)

Claims ledger

Claim Status Evidence
-cover=true in build info means built with -cover Verified (L) go version -m; cmd/go load/pkg.go:2483 appends it
A -s -w cover binary was missed before Verified (L) base false, head true
Works on Mach-O too Unverified (not run) debug/buildinfo is format-agnostic, so the true path returns before elf.Open
Scope: native only, the only caller is golang.go:41 Verified (C) grep
"new utils_test.go builds a -cover -ldflags='-s -w' binary and a plain one" Refuted The test only builds []debug.BuildSetting literals
Known limit: a plain binary importing go-sdk is detected as covered Verified (L) probe

Cross-repo / linked PRs

Independent of the others: this is the OSS aggregate-coverage path, not the per-test path. It can merge in any order.

@github-actions

Copy link
Copy Markdown

🚀 Keploy Performance Test Results

Multi-Run Validation: Tests run 3 times, pipeline fails only if 2+ runs show regression.

Run P50 P90 P99 RPS Error Rate Status
1 2.68ms 3.33ms 4.95ms 100.00 0.00% ✅ PASS
2 2.6ms 3.21ms 4.7ms 100.02 0.00% ✅ PASS
3 2.58ms 3.2ms 4.57ms 100.00 0.00% ✅ PASS

Thresholds: P50 < 5ms, P90 < 15ms, P99 < 70ms, RPS >= 100 (±1% tolerance), Error Rate < 1%

✅ Result: PASSED - Only 0 out of 3 runs failed (threshold: 2)

P50, P90, and P99 percentiles naturally filter out outliers

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