vcs/source: strip Go major version segment from symbol file paths#5075
vcs/source: strip Go major version segment from symbol file paths#5075simonswine wants to merge 2 commits into
Conversation
Go module paths for major versions >= 2 include a version suffix (e.g. github.com/grafana/pyroscope/v2/pkg/foo.go). After stripping the GitHub repo prefix, a "v2/" segment remains which does not exist as a directory in the GitHub repo. Strip the major version path element so that file lookups succeed for symbols from v2+ binaries.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit 28cfc0e. Configure here.
v0 and v1 are not valid Go module path suffixes, so a leading v1/ directory is a legitimate repo path and must not be stripped.
| if seg := path[:i]; len(seg) > 1 && seg[0] == 'v' && isDigits(seg[1:]) { | ||
| if majorVer, _ := strconv.Atoi(seg[1:]); majorVer >= 2 { | ||
| path = path[i+1:] | ||
| } | ||
| } |
There was a problem hiding this comment.
Nit: Are isDigits and Atoi redundant? e.g
if seg := path[:i]; len(seg) > 1 && seg[0] == 'v' {
if majorVer, err := strconv.Atoi(seg[1:]); err == nil && majorVer >= 2 {
path = path[i+1:]
}
}|
I guess there could be repos that use v2 or v3 directories for versioning, instead of tags https://go.dev/ref/mod#vcs-version
Not sure how common that is, we could do a fetch with it stripped and another one without the strip if we get a 404 - or we could wait for this to get reported as a real problem. |
|
I don't think this is a correct fix, might not even be a problem. At least for loki with vendor we would break that. Let's revisit this later |

Summary
Go module paths for major versions ≥ 2 include a version suffix (e.g.
github.com/grafana/pyroscope/v2/pkg/foo.go). When resolving source files for VCS linking, the code strips the GitHub repo prefix — but this leaves av2/segment that doesn't exist as a directory in the GitHub repo, causing file lookups to fail.This PR strips the major version path element (any
vN/segment immediately after the repo prefix) so that source file lookups work correctly for symbols from v2+ binaries.Test plan
path_with_relative_repository_prefix_and_major_versionandpath_with_absolute_repository_prefix_and_major_versioninfind_go_test.gocover the fixTest_tryFindGoFilecases continue to passNote
Medium Risk
Adjusts path normalization in VCS source lookup, which could change which files are fetched for some repos (e.g., if a real
v2/directory exists). Coverage is added for common v2/v1 cases, reducing regression risk.Overview
Fixes Go source-file resolution for module paths that include a major version suffix by stripping a leading
vN/segment (only forN >= 2) after the repo prefix intryFindGoFile.Adds targeted tests ensuring
v2/paths (absolute and relative) resolve to the repo root file, while a legitimatev1/directory is not stripped.Reviewed by Cursor Bugbot for commit 0714f30. Bugbot is set up for automated code reviews on this repo. Configure here.