Skip to content

Commit

Permalink
Merge branch 'moby:master' into os-mount-types-check
Browse files Browse the repository at this point in the history
  • Loading branch information
billywr authored Sep 24, 2024
2 parents 57ebe0a + 1da789b commit f6c280a
Show file tree
Hide file tree
Showing 35 changed files with 8,108 additions and 320 deletions.
2 changes: 2 additions & 0 deletions cmd/buildkitd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func setupDebugHandlers(addr string) error {

m.Handle("/metrics", promhttp.Handler())

setupDebugFlight(m)

// setting debugaddr is opt-in. permission is defined by listener address
trace.AuthRequest = func(_ *http.Request) (bool, bool) {
return true, true
Expand Down
87 changes: 87 additions & 0 deletions cmd/buildkitd/debug_flight.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"fmt"
"net/http"
"sync"
"time"

"golang.org/x/exp/trace"
)

type flightRecorder struct {
mu sync.Mutex
recorder *trace.FlightRecorder
}

func newFlightRecorder() *flightRecorder {
dbg := &flightRecorder{
recorder: trace.NewFlightRecorder(),
}
return dbg
}

func (r *flightRecorder) StartTrace(w http.ResponseWriter, req *http.Request) {
r.mu.Lock()
defer r.mu.Unlock()
if r.recorder.Enabled() {
http.Error(w, "flight recorder is already running", http.StatusConflict)
return
}
if err := r.recorder.Start(); err != nil {
http.Error(w, fmt.Sprintf("could not start flight recorder: %s", err), http.StatusInternalServerError)
return
}
}

func (r *flightRecorder) StopTrace(w http.ResponseWriter, req *http.Request) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.recorder.Enabled() {
http.Error(w, "flight recorder is not running", http.StatusConflict)
return
}
if err := r.recorder.Stop(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

func (r *flightRecorder) SetTracePeriod(w http.ResponseWriter, req *http.Request) {
r.mu.Lock()
defer r.mu.Unlock()
if r.recorder.Enabled() {
http.Error(w, "flight recorder is running, stop it to change its period", http.StatusPreconditionFailed)
return
}
periodValue := req.FormValue("period")
period, err := time.ParseDuration(periodValue)
if err != nil {
http.Error(w, fmt.Sprintf("invalid flight recorder period: %s", err), http.StatusBadRequest)
}
r.recorder.SetPeriod(period)
}

func (r *flightRecorder) Trace(w http.ResponseWriter, req *http.Request) {
r.mu.Lock()
defer r.mu.Unlock()
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", `attachment; filename="trace"`)
if _, err := r.recorder.WriteTo(w); err != nil {
http.Error(w, fmt.Sprintf("could not write in-flight trace: %s", err), http.StatusInternalServerError)
}
}

func setupDebugFlight(m *http.ServeMux) {
r := newFlightRecorder()

const (
flightPattern = "/debug/flight"
flightTracePattern = flightPattern + "/trace"
)

m.HandleFunc("POST "+flightTracePattern+"/start", r.StartTrace)
m.HandleFunc("POST "+flightTracePattern+"/stop", r.StopTrace)
m.HandleFunc("POST "+flightTracePattern+"/set_period", r.SetTracePeriod)
m.HandleFunc("GET "+flightTracePattern, r.Trace)
}
3 changes: 3 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package control
import (
"context"
"fmt"
"runtime/trace"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -343,6 +344,8 @@ func translateLegacySolveRequest(req *controlapi.SolveRequest) {
}

func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*controlapi.SolveResponse, error) {
defer trace.StartRegion(ctx, "Solve").End()
trace.Logf(ctx, "Request", "solve request: %v", req.Ref)
atomic.AddInt64(&c.buildCount, 1)
defer atomic.AddInt64(&c.buildCount, -1)

Expand Down
4 changes: 4 additions & 0 deletions docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Now that everything is setup, let's build a [simple _hello world_ image](https:/
This message shows that your installation appears to be working correctly.
"@
```

> **NOTE:** Writing to a file directly under `C:\` needs extra permissions that are `ContainerAdministrator`.
> The `ContainerUser` is default user for `nanoserver` image. See more details at [#4731](https://github.com/moby/buildkit/issues/4731).
1. Build and push to your registry (or set to `push=false`). For Docker Hub, make sure you've done `docker login`. See more details on registry configuration [here](../README.md#imageregistry)

```powershell
Expand Down
Loading

0 comments on commit f6c280a

Please sign in to comment.