Skip to content

pkg/query: Modify source report to return matched filenames#6157

Merged
yomete merged 6 commits into
mainfrom
source-no-buildid
Jan 21, 2026
Merged

pkg/query: Modify source report to return matched filenames#6157
yomete merged 6 commits into
mainfrom
source-no-buildid

Conversation

@yomete
Copy link
Copy Markdown
Contributor

@yomete yomete commented Jan 20, 2026

This PR modifies the source report to return matching filenames for when the request is called without a buildId.

Changes

  • Skip buildId filtering when buildId is empty
  • Add suffix matching for filenames
  • Add filename column to Arrow response so clients know which file each line came from
  • Add unit tests for new changes

Updated the record filtering logic in sourceReportBuilder to treat an empty buildID as matching all records. So the new behaviour is:

When buildId is empty → it skips buildId filtering, aggregates metrics from all builds matching the filename

When buildId is provided → filters to that specific build
Introduces a matched_filenames field to the Source proto and related code, allowing clients to see all filenames that matched a query
@yomete yomete requested review from a team as code owners January 20, 2026 15:41
@alwaysmeticulous
Copy link
Copy Markdown

alwaysmeticulous Bot commented Jan 20, 2026

✅ Meticulous spotted 0 visual differences across 328 screens tested: view results.

Meticulous evaluated ~4 hours of user flows against your PR.

Expected differences? Click here. Last updated for commit b517813. This comment will update as new commits are pushed.

…ames

The Source report Arrow record now includes a dictionary-encoded filename column, along with line_number, cumulative, and flat columns.
@yomete yomete force-pushed the source-no-buildid branch from acb9398 to adc39ab Compare January 20, 2026 17:39
Comment thread pkg/query/sources.go Outdated
lineData map[int64]*lineMetrics
cumulative int64
lineData map[lineKey]*lineMetrics
filenameIntern map[string]string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need this anymore, do we?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Initially added this to deduplicate filename strings during processing i.e. if the same file appears 100 times in the profile, we'd create 100 separate string allocations as map keys.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we already do this via the lineKey, and I'm not even sure if this would have done anything in go, because strings are copied in most cases by the go runtime

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

or alteratively we make it map[string][]lineMetrics and add line number to the linemetrics struct and then we only need to sort the file names, and line metrics individually by file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i like that. i'll make the change

Comment thread pkg/query/sources.go
// It returns true if:
// - They are exactly equal, OR
// - profileFilename ends with queryFilename AND is preceded by a '/' (path boundary).
func filenameMatches(profileFilename, queryFilename []byte) bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is unused now?

Copy link
Copy Markdown
Contributor Author

@yomete yomete Jan 20, 2026

Choose a reason for hiding this comment

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

Hmm but this is what we use for actually implementing suffix matching for local and build paths.

So for example, if the client passes pkg/sources/server.go locally, but the profiling data has /home/ci/build/pkg/sources/server.go from the build, filenameMatches will help with suffix matching to get the actual file name.

Or you're thinking we just return the data for every file found in the profiling data and then in the client, do a filter with the source file we care about?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we do the latter that might mean a larger response size right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

apologies, you're right, in the future we should have this be part of the query against the database

@yomete yomete changed the title pkg/query: Modify source report to return matched filenames if present pkg/query: Modify source report to return matched filenames Jan 20, 2026
@yomete yomete enabled auto-merge (squash) January 21, 2026 12:57
@yomete yomete merged commit 62a8300 into main Jan 21, 2026
35 checks passed
@brancz brancz deleted the source-no-buildid branch January 21, 2026 13:22
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