Skip to content

vcs/source: strip Go major version segment from symbol file paths#5075

Draft
simonswine wants to merge 2 commits into
grafana:mainfrom
simonswine:fix-vcs-source-finder-major-version-strip
Draft

vcs/source: strip Go major version segment from symbol file paths#5075
simonswine wants to merge 2 commits into
grafana:mainfrom
simonswine:fix-vcs-source-finder-major-version-strip

Conversation

@simonswine
Copy link
Copy Markdown
Contributor

@simonswine simonswine commented Apr 17, 2026

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 a v2/ 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

  • New test cases path_with_relative_repository_prefix_and_major_version and path_with_absolute_repository_prefix_and_major_version in find_go_test.go cover the fix
  • All existing Test_tryFindGoFile cases continue to pass

Note

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 for N >= 2) after the repo prefix in tryFindGoFile.

Adds targeted tests ensuring v2/ paths (absolute and relative) resolve to the repo root file, while a legitimate v1/ directory is not stripped.

Reviewed by Cursor Bugbot for commit 0714f30. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

Comment thread pkg/frontend/vcs/source/find_go.go
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.
Copy link
Copy Markdown
Contributor

@marcsanmi marcsanmi left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +210 to +214
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:]
}
}
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.

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:]
    }
}

@aleks-p
Copy link
Copy Markdown
Contributor

aleks-p commented Apr 17, 2026

I guess there could be repos that use v2 or v3 directories for versioning, instead of tags

https://go.dev/ref/mod#vcs-version

If a module is defined in the repository root directory or in a major version subdirectory of the root directory, then each version tag name is equal to the corresponding 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.

@simonswine simonswine marked this pull request as draft April 17, 2026 14:54
@simonswine
Copy link
Copy Markdown
Contributor Author

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

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.

3 participants