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

debug: add trace flight recorder #5337

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

fiam
Copy link
Contributor

@fiam fiam commented Sep 14, 2024

debug: add trace flight recorder

Use golang.org/x/exp/trace to implement an trace recorder that saves the trace
to a circular buffer and can be retrieved at any time.

Debug endpoints have been added under /debug/flight to start and stop the trace
as well as to set its period.

Due to golang.org/x/exp/trace, the minimum go version has been bumped to 1.22

@github-actions github-actions bot added area/hack building buildkit itself area/dependencies Pull requests that update a dependency file area/buildkitd area/solver labels Sep 14, 2024
@@ -1,6 +1,6 @@
module github.com/moby/buildkit

go 1.21.0
go 1.22.0
Copy link
Member

Choose a reason for hiding this comment

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

can just be 1.22

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! 1.22 makes more sense to me, but since the same file was using 1.21.0 I kept it pinned to a patch release just in case there was some BuiltKit convention I was not aware of. I've updated it to use 1.22.

Copy link
Member

@crazy-max crazy-max Sep 16, 2024

Choose a reason for hiding this comment

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

but since the same file was using 1.21.0

this was because of a dep forcing it, see #5118 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

ah actually I was wrong, exp/trace also set patch so we need it as well https://cs.opensource.google/go/x/exp/+/master:go.mod;l=3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, good point. I've changed it back to 1.22.0.

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

@fiam fiam force-pushed the alberto/debug-flight-record branch from f9678a2 to 34f4993 Compare September 16, 2024 09:33
@fiam
Copy link
Contributor Author

fiam commented Sep 16, 2024

check missing DCO https://github.com/moby/buildkit/pull/5337/checks

Thanks! I've added it.

@fiam fiam force-pushed the alberto/debug-flight-record branch from 34f4993 to 9f0a241 Compare September 16, 2024 09:54
m.HandleFunc("POST "+flightTracePattern+"/set_period", r.SetTracePeriod)
m.HandleFunc("GET "+flightTracePattern, r.Trace)

m.HandleFunc("POST "+flightCPUPattern+"/start", r.StartCPUProfile)
Copy link
Member

Choose a reason for hiding this comment

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

These are already available in /debug/pprof/profile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are not exactly the same. The default ones require you to specify the profile duration beforehand, while these ones allow you start a continous CPU profile and stop it later (e.g. in response to some event).

Copy link
Member

Choose a reason for hiding this comment

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

The default does seem safer. If we want to keep the new ones then:

  • Why do these make sense under /flight as it is just plain CPU profile.
  • StartCPUProfile should stop the profiling when connection drops and request context gets cancelled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it might be better to remove the CPU profiler endpoints from this PR and focus on the trace recorder. We can add the CPU profilers in a subsequent PR. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've left only the trace profiler. PTAL.

http.Error(w, fmt.Sprintf("could not start CPU profile: %s", err), http.StatusInternalServerError)
return
}

Copy link
Member

@tonistiigi tonistiigi Sep 19, 2024

Choose a reason for hiding this comment

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

Technically, a Stop request can come in here before the Wait() and cause this function to hang forever. Especially if r.mu is already locked from other flight requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, we've split this part into a separate PR.

@fiam fiam changed the title debug: add trace and CPU flight recorder debug: add trace flight recorder Sep 23, 2024
@fiam fiam force-pushed the alberto/debug-flight-record branch from 9f0a241 to 902ba23 Compare September 23, 2024 18:58

type flightRecorder struct {
mu sync.Mutex
cond *sync.Cond
Copy link
Member

Choose a reason for hiding this comment

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

cond is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! It should be good now.

Use golang.org/x/exp/trace to implement an trace recorder that saves the trace
to a circular buffer and can be retrieved at any time.

Debug endpoints have been added under /debug/flight to start and stop the trace
as well as to set its period.

Due to golang.org/x/exp/trace, the minimum go version has been bumped to 1.22

Signed-off-by: Alberto Garcia Hierro <damaso.hierro@docker.com>
@fiam fiam force-pushed the alberto/debug-flight-record branch from 902ba23 to 892e756 Compare September 23, 2024 20:01
@tonistiigi tonistiigi merged commit a146d2a into moby:master Sep 23, 2024
90 of 91 checks passed
@fiam
Copy link
Contributor Author

fiam commented Sep 23, 2024

Thanks @tonistiigi and @crazy-max 🤝

@fiam fiam deleted the alberto/debug-flight-record branch September 23, 2024 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/buildkitd area/dependencies Pull requests that update a dependency file area/hack building buildkit itself area/solver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants