Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack: Parse all functions #111

Merged
merged 8 commits into from
Oct 23, 2023
Merged

stack: Parse all functions #111

merged 8 commits into from
Oct 23, 2023

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Oct 21, 2023

Adds support to the stack parser for reading the full list of functions
for a stack trace.

NOTE:
This includes the function that created the stack trace;
it's the bottom of the stack.

We don't maintain the order of the functions
since that's not something we need at this time.
The functions are all placed in a set.

This unblocks #41 (PR incoming)
and allows implementing an IgnoreAnyFunction option
(similar to #80 that has since stalled).

Depends on #110

@codecov
Copy link

codecov bot commented Oct 21, 2023

Codecov Report

Merging #111 (5b4de07) into master (25cbb67) will increase coverage by 0.31%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #111      +/-   ##
==========================================
+ Coverage   98.18%   98.50%   +0.31%     
==========================================
  Files           6        6              
  Lines         276      334      +58     
==========================================
+ Hits          271      329      +58     
  Misses          4        4              
  Partials        1        1              
Files Coverage Δ
internal/stack/stacks.go 96.89% <100.00%> (+1.74%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@abhinav
Copy link
Collaborator Author

abhinav commented Oct 21, 2023

One thing that I'd really like input on is this:
Should "created by" be considered part of the function stack?

I'm torn on this.
It is the source of the stack, but it's not necessarily in the stack.
WDYT?

CC @prashantv

internal/stack/stacks.go Outdated Show resolved Hide resolved
internal/stack/stacks.go Show resolved Hide resolved
want: "example.com/foo/bar.baz",
},
{
name: "created by/in goroutine", // Go 1.21
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we add some testdata of real stack traces from go 1.20 / 1.21 and ensure they parse correctly too?

@abhinav
Copy link
Collaborator Author

abhinav commented Oct 22, 2023

Update:

  • Addressed most comments
  • Don't have testdata traces yet
  • Dropped "created by" from the trace per chat earlier
  • Guard against "tracebackancestors=N" being set

Base automatically changed from parse-flow to master October 22, 2023 18:15
Adds support to the stack parser
for reading the full list of functions
for a stack trace.

This includes the function that created the stack trace;
it's the bottom of the stack.

We don't maintain the order of the functions
since that's not something we need at this time.
The functions are all placed in a set.
In Go 1.20, the "created by" lines
do not include the "in goroutine" portion.
`Full()` was accidentally dropping the file names from the full traces.
The function tha created a goroutine
should not be considered part of its stack.

However, we can use that entry to mark the end of a stack trace.
Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

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

LGTM, can also do testdata traces in a follow-up, doesn't have to be part of this PR.

To verify the stacktrace parsing logic,
generate real stack traces under the following conditions:

- Go 1.21
- Go 1.20 installed with gimme
- Go 1.21 with tracebackancestors=10 set

The test verifies that the parsed stack traces
do not include functions that we did not expect to see
in a goroutine's trace.
@abhinav
Copy link
Collaborator Author

abhinav commented Oct 22, 2023

We should set up a codecov configuration that we actually follow. This is just ignored right now.

image

@abhinav abhinav merged commit 91de685 into master Oct 23, 2023
7 checks passed
@abhinav abhinav deleted the parse-stack branch October 23, 2023 04:16
abhinav added a commit that referenced this pull request Oct 23, 2023
Instead of matching for built-in functions with strings.Contains,
use the parsed stack information to match function names exactly.

Following this change, the only remaining strings.Contains are
to match on the goroutine state:

```
% rg strings.Contains
utils_test.go
84:             if strings.Contains(s.State(), "run") {

internal/stack/stacks_test.go
249:            if strings.Contains(s.State(), "run") {
```

Resolves #41
Depends on #111
abhinav added a commit that referenced this pull request Oct 23, 2023
Adds a new IgnoreAnyFunction option to ignore stacks
that have the provided function anywhere in the stack,
not just the top.

To test this better, the helper blockedG.run function
was split into two.

Supersedes #80
Depends on #111
@mway mway mentioned this pull request Oct 24, 2023
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.

None yet

2 participants