mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
deps: update buildkit, vendor changes
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
13
vendor/github.com/moby/buildkit/client/client.go
generated
vendored
13
vendor/github.com/moby/buildkit/client/client.go
generated
vendored
@ -59,9 +59,6 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
|
||||
var creds *withCredentials
|
||||
|
||||
for _, o := range opts {
|
||||
if _, ok := o.(*withFailFast); ok {
|
||||
gopts = append(gopts, grpc.FailOnNonTempDialError(true))
|
||||
}
|
||||
if credInfo, ok := o.(*withCredentials); ok {
|
||||
if creds == nil {
|
||||
creds = &withCredentials{}
|
||||
@ -205,7 +202,7 @@ func (c *Client) Wait(ctx context.Context) error {
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
return context.Cause(ctx)
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
c.conn.ResetConnectBackoff()
|
||||
@ -216,14 +213,6 @@ func (c *Client) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
type withFailFast struct{}
|
||||
|
||||
func (*withFailFast) isClientOpt() {}
|
||||
|
||||
func WithFailFast() ClientOpt {
|
||||
return &withFailFast{}
|
||||
}
|
||||
|
||||
type withDialer struct {
|
||||
dialer func(context.Context, string) (net.Conn, error)
|
||||
}
|
||||
|
2
vendor/github.com/moby/buildkit/client/llb/async.go
generated
vendored
2
vendor/github.com/moby/buildkit/client/llb/async.go
generated
vendored
@ -61,7 +61,7 @@ func (as *asyncState) Do(ctx context.Context, c *Constraints) error {
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if errors.Is(err, ctx.Err()) {
|
||||
if errors.Is(err, context.Cause(ctx)) {
|
||||
return res, err
|
||||
}
|
||||
default:
|
||||
|
12
vendor/github.com/moby/buildkit/client/solve.go
generated
vendored
12
vendor/github.com/moby/buildkit/client/solve.go
generated
vendored
@ -106,8 +106,8 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
|
||||
}
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
statusContext, cancelStatus := context.WithCancel(context.Background())
|
||||
defer cancelStatus()
|
||||
statusContext, cancelStatus := context.WithCancelCause(context.Background())
|
||||
defer cancelStatus(errors.WithStack(context.Canceled))
|
||||
|
||||
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
|
||||
statusContext = trace.ContextWithSpan(statusContext, span)
|
||||
@ -230,16 +230,16 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
|
||||
frontendAttrs[k] = v
|
||||
}
|
||||
|
||||
solveCtx, cancelSolve := context.WithCancel(ctx)
|
||||
solveCtx, cancelSolve := context.WithCancelCause(ctx)
|
||||
var res *SolveResponse
|
||||
eg.Go(func() error {
|
||||
ctx := solveCtx
|
||||
defer cancelSolve()
|
||||
defer cancelSolve(errors.WithStack(context.Canceled))
|
||||
|
||||
defer func() { // make sure the Status ends cleanly on build errors
|
||||
go func() {
|
||||
<-time.After(3 * time.Second)
|
||||
cancelStatus()
|
||||
cancelStatus(errors.WithStack(context.Canceled))
|
||||
}()
|
||||
if !opt.SessionPreInitialized {
|
||||
bklog.G(ctx).Debugf("stopping session")
|
||||
@ -298,7 +298,7 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
|
||||
select {
|
||||
case <-solveCtx.Done():
|
||||
case <-time.After(5 * time.Second):
|
||||
cancelSolve()
|
||||
cancelSolve(errors.WithStack(context.Canceled))
|
||||
}
|
||||
|
||||
return err
|
||||
|
9
vendor/github.com/moby/buildkit/frontend/dockerui/config.go
generated
vendored
9
vendor/github.com/moby/buildkit/frontend/dockerui/config.go
generated
vendored
@ -95,7 +95,7 @@ type Source struct {
|
||||
|
||||
type ContextOpt struct {
|
||||
NoDockerignore bool
|
||||
LocalOpts []llb.LocalOption
|
||||
AsyncLocalOpts func() []llb.LocalOption
|
||||
Platform *ocispecs.Platform
|
||||
ResolveMode string
|
||||
CaptureDigest *digest.Digest
|
||||
@ -473,11 +473,8 @@ func (bc *Client) NamedContext(ctx context.Context, name string, opt ContextOpt)
|
||||
}
|
||||
pname := name + "::" + platforms.Format(platforms.Normalize(pp))
|
||||
st, img, err := bc.namedContext(ctx, name, pname, opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if st != nil {
|
||||
return st, img, nil
|
||||
if err != nil || st != nil {
|
||||
return st, img, err
|
||||
}
|
||||
return bc.namedContext(ctx, name, name, opt)
|
||||
}
|
||||
|
55
vendor/github.com/moby/buildkit/frontend/dockerui/namedcontext.go
generated
vendored
55
vendor/github.com/moby/buildkit/frontend/dockerui/namedcontext.go
generated
vendored
@ -6,12 +6,14 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/distribution/reference"
|
||||
"github.com/moby/buildkit/client/llb"
|
||||
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
||||
"github.com/moby/buildkit/exporter/containerimage/image"
|
||||
"github.com/moby/buildkit/frontend/gateway/client"
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
"github.com/moby/buildkit/util/imageutil"
|
||||
"github.com/moby/patternmatcher/ignorefile"
|
||||
"github.com/pkg/errors"
|
||||
@ -212,12 +214,15 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
|
||||
}
|
||||
}
|
||||
}
|
||||
st = llb.Local(vv[1],
|
||||
llb.WithCustomName("[context "+nameWithPlatform+"] load from client"),
|
||||
llb.SessionID(bc.bopts.SessionID),
|
||||
llb.SharedKeyHint("context:"+nameWithPlatform),
|
||||
llb.ExcludePatterns(excludes),
|
||||
)
|
||||
|
||||
localOutput := &asyncLocalOutput{
|
||||
name: vv[1],
|
||||
nameWithPlatform: nameWithPlatform,
|
||||
sessionID: bc.bopts.SessionID,
|
||||
excludes: excludes,
|
||||
extraOpts: opt.AsyncLocalOpts,
|
||||
}
|
||||
st = llb.NewState(localOutput)
|
||||
return &st, nil, nil
|
||||
case "input":
|
||||
inputs, err := bc.client.Inputs(ctx)
|
||||
@ -251,3 +256,41 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
|
||||
return nil, nil, errors.Errorf("unsupported context source %s for %s", vv[0], nameWithPlatform)
|
||||
}
|
||||
}
|
||||
|
||||
// asyncLocalOutput is an llb.Output that computes an llb.Local
|
||||
// on-demand instead of at the time of initialization.
|
||||
type asyncLocalOutput struct {
|
||||
llb.Output
|
||||
name string
|
||||
nameWithPlatform string
|
||||
sessionID string
|
||||
excludes []string
|
||||
extraOpts func() []llb.LocalOption
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (a *asyncLocalOutput) ToInput(ctx context.Context, constraints *llb.Constraints) (*pb.Input, error) {
|
||||
a.once.Do(a.do)
|
||||
return a.Output.ToInput(ctx, constraints)
|
||||
}
|
||||
|
||||
func (a *asyncLocalOutput) Vertex(ctx context.Context, constraints *llb.Constraints) llb.Vertex {
|
||||
a.once.Do(a.do)
|
||||
return a.Output.Vertex(ctx, constraints)
|
||||
}
|
||||
|
||||
func (a *asyncLocalOutput) do() {
|
||||
var extraOpts []llb.LocalOption
|
||||
if a.extraOpts != nil {
|
||||
extraOpts = a.extraOpts()
|
||||
}
|
||||
opts := append([]llb.LocalOption{
|
||||
llb.WithCustomName("[context " + a.nameWithPlatform + "] load from client"),
|
||||
llb.SessionID(a.sessionID),
|
||||
llb.SharedKeyHint("context:" + a.nameWithPlatform),
|
||||
llb.ExcludePatterns(a.excludes),
|
||||
}, extraOpts...)
|
||||
|
||||
st := llb.Local(a.name, opts...)
|
||||
a.Output = st.Output()
|
||||
}
|
||||
|
15
vendor/github.com/moby/buildkit/frontend/gateway/grpcclient/client.go
generated
vendored
15
vendor/github.com/moby/buildkit/frontend/gateway/grpcclient/client.go
generated
vendored
@ -43,8 +43,9 @@ type GrpcClient interface {
|
||||
}
|
||||
|
||||
func New(ctx context.Context, opts map[string]string, session, product string, c pb.LLBBridgeClient, w []client.WorkerInfo) (GrpcClient, error) {
|
||||
pingCtx, pingCancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
defer pingCancel()
|
||||
pingCtx, pingCancel := context.WithCancelCause(ctx)
|
||||
pingCtx, _ = context.WithTimeoutCause(pingCtx, 15*time.Second, errors.WithStack(context.DeadlineExceeded))
|
||||
defer pingCancel(errors.WithStack(context.Canceled))
|
||||
resp, err := c.Ping(pingCtx, &pb.PingRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -616,7 +617,7 @@ func (b *procMessageForwarder) Close() {
|
||||
type messageForwarder struct {
|
||||
client pb.LLBBridgeClient
|
||||
ctx context.Context
|
||||
cancel func()
|
||||
cancel func(error)
|
||||
eg *errgroup.Group
|
||||
mu sync.Mutex
|
||||
pids map[string]*procMessageForwarder
|
||||
@ -630,7 +631,7 @@ type messageForwarder struct {
|
||||
}
|
||||
|
||||
func newMessageForwarder(ctx context.Context, client pb.LLBBridgeClient) *messageForwarder {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
return &messageForwarder{
|
||||
client: client,
|
||||
@ -719,7 +720,7 @@ func (m *messageForwarder) Send(msg *pb.ExecMessage) error {
|
||||
}
|
||||
|
||||
func (m *messageForwarder) Release() error {
|
||||
m.cancel()
|
||||
m.cancel(errors.WithStack(context.Canceled))
|
||||
return m.eg.Wait()
|
||||
}
|
||||
|
||||
@ -949,7 +950,7 @@ func (ctr *container) Start(ctx context.Context, req client.StartRequest) (clien
|
||||
closeDoneOnce.Do(func() {
|
||||
close(done)
|
||||
})
|
||||
return ctx.Err()
|
||||
return context.Cause(ctx)
|
||||
}
|
||||
|
||||
if file := msg.GetFile(); file != nil {
|
||||
@ -1145,7 +1146,7 @@ func grpcClientConn(ctx context.Context) (context.Context, *grpc.ClientConn, err
|
||||
return nil, nil, errors.Wrap(err, "failed to create grpc client")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
_ = cancel
|
||||
// go monitorHealth(ctx, cc, cancel)
|
||||
|
||||
|
4
vendor/github.com/moby/buildkit/session/filesync/filesync.go
generated
vendored
4
vendor/github.com/moby/buildkit/session/filesync/filesync.go
generated
vendored
@ -195,8 +195,8 @@ func FSSync(ctx context.Context, c session.Caller, opt FSSendRequestOpt) error {
|
||||
|
||||
opts[keyDirName] = []string{opt.Name}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
|
||||
client := NewFileSyncClient(c.Conn())
|
||||
|
||||
|
5
vendor/github.com/moby/buildkit/session/group.go
generated
vendored
5
vendor/github.com/moby/buildkit/session/group.go
generated
vendored
@ -72,8 +72,9 @@ func (sm *Manager) Any(ctx context.Context, g Group, f func(context.Context, str
|
||||
return errors.Errorf("no active sessions")
|
||||
}
|
||||
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
timeoutCtx, cancel := context.WithCancelCause(ctx)
|
||||
timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 5*time.Second, errors.WithStack(context.DeadlineExceeded))
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
c, err := sm.Get(timeoutCtx, id, false)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
|
12
vendor/github.com/moby/buildkit/session/grpc.go
generated
vendored
12
vendor/github.com/moby/buildkit/session/grpc.go
generated
vendored
@ -74,14 +74,14 @@ func grpcClientConn(ctx context.Context, conn net.Conn) (context.Context, *grpc.
|
||||
return nil, nil, errors.Wrap(err, "failed to create grpc client")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
go monitorHealth(ctx, cc, cancel)
|
||||
|
||||
return ctx, cc, nil
|
||||
}
|
||||
|
||||
func monitorHealth(ctx context.Context, cc *grpc.ClientConn, cancelConn func()) {
|
||||
defer cancelConn()
|
||||
func monitorHealth(ctx context.Context, cc *grpc.ClientConn, cancelConn func(error)) {
|
||||
defer cancelConn(errors.WithStack(context.Canceled))
|
||||
defer cc.Close()
|
||||
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
@ -104,9 +104,11 @@ func monitorHealth(ctx context.Context, cc *grpc.ClientConn, cancelConn func())
|
||||
healthcheckStart := time.Now()
|
||||
|
||||
timeout := time.Duration(math.Max(float64(defaultHealthcheckDuration), float64(lastHealthcheckDuration)*1.5))
|
||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
ctx, _ = context.WithTimeoutCause(ctx, timeout, errors.WithStack(context.DeadlineExceeded))
|
||||
_, err := healthClient.Check(ctx, &grpc_health_v1.HealthCheckRequest{})
|
||||
cancel()
|
||||
cancel(errors.WithStack(context.Canceled))
|
||||
|
||||
lastHealthcheckDuration = time.Since(healthcheckStart)
|
||||
logFields := logrus.Fields{
|
||||
|
10
vendor/github.com/moby/buildkit/session/manager.go
generated
vendored
10
vendor/github.com/moby/buildkit/session/manager.go
generated
vendored
@ -99,8 +99,8 @@ func (sm *Manager) HandleConn(ctx context.Context, conn net.Conn, opts map[strin
|
||||
|
||||
// caller needs to take lock, this function will release it
|
||||
func (sm *Manager) handleConn(ctx context.Context, conn net.Conn, opts map[string][]string) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
|
||||
opts = canonicalHeaders(opts)
|
||||
|
||||
@ -156,8 +156,8 @@ func (sm *Manager) Get(ctx context.Context, id string, noWait bool) (Caller, err
|
||||
id = p[1]
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
@ -173,7 +173,7 @@ func (sm *Manager) Get(ctx context.Context, id string, noWait bool) (Caller, err
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
sm.mu.Unlock()
|
||||
return nil, errors.Wrapf(ctx.Err(), "no active session for %s", id)
|
||||
return nil, errors.Wrapf(context.Cause(ctx), "no active session for %s", id)
|
||||
default:
|
||||
}
|
||||
var ok bool
|
||||
|
6
vendor/github.com/moby/buildkit/session/session.go
generated
vendored
6
vendor/github.com/moby/buildkit/session/session.go
generated
vendored
@ -42,7 +42,7 @@ type Session struct {
|
||||
name string
|
||||
sharedKey string
|
||||
ctx context.Context
|
||||
cancelCtx func()
|
||||
cancelCtx func(error)
|
||||
done chan struct{}
|
||||
grpcServer *grpc.Server
|
||||
conn net.Conn
|
||||
@ -107,11 +107,11 @@ func (s *Session) Run(ctx context.Context, dialer Dialer) error {
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
s.cancelCtx = cancel
|
||||
s.done = make(chan struct{})
|
||||
|
||||
defer cancel()
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
defer close(s.done)
|
||||
|
||||
meta := make(map[string][]string)
|
||||
|
4
vendor/github.com/moby/buildkit/session/sshforward/copy.go
generated
vendored
4
vendor/github.com/moby/buildkit/session/sshforward/copy.go
generated
vendored
@ -39,7 +39,7 @@ func Copy(ctx context.Context, conn io.ReadWriteCloser, stream Stream, closeStre
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
conn.Close()
|
||||
return ctx.Err()
|
||||
return context.Cause(ctx)
|
||||
default:
|
||||
}
|
||||
if _, err := conn.Write(p.Data); err != nil {
|
||||
@ -65,7 +65,7 @@ func Copy(ctx context.Context, conn io.ReadWriteCloser, stream Stream, closeStre
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
return context.Cause(ctx)
|
||||
default:
|
||||
}
|
||||
p := &BytesMessage{Data: buf[:n]}
|
||||
|
2
vendor/github.com/moby/buildkit/session/sshforward/ssh.go
generated
vendored
2
vendor/github.com/moby/buildkit/session/sshforward/ssh.go
generated
vendored
@ -26,7 +26,7 @@ func (s *server) run(ctx context.Context, l net.Listener, id string) error {
|
||||
|
||||
eg.Go(func() error {
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
return context.Cause(ctx)
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
|
2
vendor/github.com/moby/buildkit/solver/errdefs/context.go
generated
vendored
2
vendor/github.com/moby/buildkit/solver/errdefs/context.go
generated
vendored
@ -14,7 +14,7 @@ func IsCanceled(ctx context.Context, err error) bool {
|
||||
return true
|
||||
}
|
||||
// grpc does not set cancel correctly when stream gets cancelled and then Recv is called
|
||||
if err != nil && ctx.Err() == context.Canceled {
|
||||
if err != nil && context.Cause(ctx) == context.Canceled {
|
||||
// when this error comes from containerd it is not typed at all, just concatenated string
|
||||
if strings.Contains(err.Error(), "EOF") {
|
||||
return true
|
||||
|
8
vendor/github.com/moby/buildkit/util/appcontext/appcontext.go
generated
vendored
8
vendor/github.com/moby/buildkit/util/appcontext/appcontext.go
generated
vendored
@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/moby/buildkit/util/bklog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var appContextCache context.Context
|
||||
@ -27,16 +28,17 @@ func Context() context.Context {
|
||||
ctx = f(ctx)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
appContextCache = ctx
|
||||
|
||||
go func() {
|
||||
for {
|
||||
<-signals
|
||||
cancel()
|
||||
retries++
|
||||
err := errors.Errorf("got %d SIGTERM/SIGINTs, forcing shutdown", retries)
|
||||
cancel(err)
|
||||
if retries >= exitLimit {
|
||||
bklog.G(ctx).Errorf("got %d SIGTERM/SIGINTs, forcing shutdown", retries)
|
||||
bklog.G(ctx).Errorf(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
18
vendor/github.com/moby/buildkit/util/flightcontrol/flightcontrol.go
generated
vendored
18
vendor/github.com/moby/buildkit/util/flightcontrol/flightcontrol.go
generated
vendored
@ -90,7 +90,7 @@ type call[T any] struct {
|
||||
fn func(ctx context.Context) (T, error)
|
||||
once sync.Once
|
||||
|
||||
closeProgressWriter func()
|
||||
closeProgressWriter func(error)
|
||||
progressState *progressState
|
||||
progressCtx context.Context
|
||||
}
|
||||
@ -115,9 +115,9 @@ func newCall[T any](fn func(ctx context.Context) (T, error)) *call[T] {
|
||||
}
|
||||
|
||||
func (c *call[T]) run() {
|
||||
defer c.closeProgressWriter()
|
||||
ctx, cancel := context.WithCancel(c.ctx)
|
||||
defer cancel()
|
||||
defer c.closeProgressWriter(errors.WithStack(context.Canceled))
|
||||
ctx, cancel := context.WithCancelCause(c.ctx)
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
v, err := c.fn(ctx)
|
||||
c.mu.Lock()
|
||||
c.result = v
|
||||
@ -155,8 +155,8 @@ func (c *call[T]) wait(ctx context.Context) (v T, err error) {
|
||||
c.progressState.add(pw)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
|
||||
c.ctxs = append(c.ctxs, ctx)
|
||||
|
||||
@ -175,7 +175,7 @@ func (c *call[T]) wait(ctx context.Context) (v T, err error) {
|
||||
if ok {
|
||||
c.progressState.close(pw)
|
||||
}
|
||||
return empty, ctx.Err()
|
||||
return empty, context.Cause(ctx)
|
||||
case <-c.ready:
|
||||
return c.result, c.err // shared not implemented yet
|
||||
}
|
||||
@ -262,7 +262,9 @@ func (sc *sharedContext[T]) checkDone() bool {
|
||||
for _, ctx := range sc.ctxs {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
err = ctx.Err()
|
||||
// Cause can't be used here because this error is returned for Err() in custom context
|
||||
// implementation and unfortunately stdlib does not allow defining Cause() for custom contexts
|
||||
err = ctx.Err() //nolint: forbidigo
|
||||
default:
|
||||
sc.mu.Unlock()
|
||||
return false
|
||||
|
19
vendor/github.com/moby/buildkit/util/progress/multireader.go
generated
vendored
19
vendor/github.com/moby/buildkit/util/progress/multireader.go
generated
vendored
@ -11,14 +11,15 @@ type MultiReader struct {
|
||||
main Reader
|
||||
initialized bool
|
||||
done chan struct{}
|
||||
writers map[*progressWriter]func()
|
||||
doneCause error
|
||||
writers map[*progressWriter]func(error)
|
||||
sent []*Progress
|
||||
}
|
||||
|
||||
func NewMultiReader(pr Reader) *MultiReader {
|
||||
mr := &MultiReader{
|
||||
main: pr,
|
||||
writers: make(map[*progressWriter]func()),
|
||||
writers: make(map[*progressWriter]func(error)),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
return mr
|
||||
@ -46,9 +47,9 @@ func (mr *MultiReader) Reader(ctx context.Context) Reader {
|
||||
|
||||
go func() {
|
||||
if isBehind {
|
||||
close := func() {
|
||||
close := func(err error) {
|
||||
w.Close()
|
||||
closeWriter()
|
||||
closeWriter(err)
|
||||
}
|
||||
i := 0
|
||||
for {
|
||||
@ -58,11 +59,11 @@ func (mr *MultiReader) Reader(ctx context.Context) Reader {
|
||||
if count == 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
close()
|
||||
close(context.Cause(ctx))
|
||||
mr.mu.Unlock()
|
||||
return
|
||||
case <-mr.done:
|
||||
close()
|
||||
close(mr.doneCause)
|
||||
mr.mu.Unlock()
|
||||
return
|
||||
default:
|
||||
@ -77,7 +78,7 @@ func (mr *MultiReader) Reader(ctx context.Context) Reader {
|
||||
if i%100 == 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
close()
|
||||
close(context.Cause(ctx))
|
||||
return
|
||||
default:
|
||||
}
|
||||
@ -110,10 +111,12 @@ func (mr *MultiReader) handle() error {
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
mr.mu.Lock()
|
||||
cancelErr := context.Canceled
|
||||
for w, c := range mr.writers {
|
||||
w.Close()
|
||||
c()
|
||||
c(cancelErr)
|
||||
}
|
||||
mr.doneCause = cancelErr
|
||||
close(mr.done)
|
||||
mr.mu.Unlock()
|
||||
return nil
|
||||
|
8
vendor/github.com/moby/buildkit/util/progress/progress.go
generated
vendored
8
vendor/github.com/moby/buildkit/util/progress/progress.go
generated
vendored
@ -56,7 +56,7 @@ type WriterOption func(Writer)
|
||||
// NewContext returns a new context and a progress reader that captures all
|
||||
// progress items writtern to this context. Last returned parameter is a closer
|
||||
// function to signal that no new writes will happen to this context.
|
||||
func NewContext(ctx context.Context) (Reader, context.Context, func()) {
|
||||
func NewContext(ctx context.Context) (Reader, context.Context, func(error)) {
|
||||
pr, pw, cancel := pipe()
|
||||
ctx = WithProgress(ctx, pw)
|
||||
return pr, ctx, cancel
|
||||
@ -141,7 +141,7 @@ func (pr *progressReader) Read(ctx context.Context) ([]*Progress, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
pr.mu.Unlock()
|
||||
return nil, ctx.Err()
|
||||
return nil, context.Cause(ctx)
|
||||
default:
|
||||
}
|
||||
dmap := pr.dirty
|
||||
@ -185,8 +185,8 @@ func (pr *progressReader) append(pw *progressWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
func pipe() (*progressReader, *progressWriter, func()) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
func pipe() (*progressReader, *progressWriter, func(error)) {
|
||||
ctx, cancel := context.WithCancelCause(context.Background())
|
||||
pr := &progressReader{
|
||||
ctx: ctx,
|
||||
writers: make(map[*progressWriter]struct{}),
|
||||
|
2
vendor/github.com/moby/buildkit/util/progress/progressui/display.go
generated
vendored
2
vendor/github.com/moby/buildkit/util/progress/progressui/display.go
generated
vendored
@ -99,7 +99,7 @@ func (d Display) UpdateFrom(ctx context.Context, ch chan *client.SolveStatus) ([
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
return nil, context.Cause(ctx)
|
||||
case <-ticker.C:
|
||||
d.disp.refresh()
|
||||
case ss, ok := <-ch:
|
||||
|
5
vendor/github.com/moby/buildkit/util/testutil/integration/registry.go
generated
vendored
5
vendor/github.com/moby/buildkit/util/testutil/integration/registry.go
generated
vendored
@ -67,8 +67,9 @@ http:
|
||||
}
|
||||
deferF.Append(stop)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
ctx, cancel := context.WithCancelCause(context.Background())
|
||||
ctx, _ = context.WithTimeoutCause(ctx, 5*time.Second, errors.WithStack(context.DeadlineExceeded))
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
url, err = detectPort(ctx, rc)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
|
7
vendor/github.com/moby/buildkit/util/testutil/integration/run.go
generated
vendored
7
vendor/github.com/moby/buildkit/util/testutil/integration/run.go
generated
vendored
@ -423,3 +423,10 @@ func prepareValueMatrix(tc testConf) []matrixValue {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Skips tests on Windows
|
||||
func SkipOnPlatform(t *testing.T, goos string) {
|
||||
if runtime.GOOS == goos {
|
||||
t.Skipf("Skipped on %s", goos)
|
||||
}
|
||||
}
|
||||
|
2
vendor/github.com/moby/buildkit/util/testutil/integration/sandbox.go
generated
vendored
2
vendor/github.com/moby/buildkit/util/testutil/integration/sandbox.go
generated
vendored
@ -99,7 +99,7 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
|
||||
|
||||
b, closer, err := w.New(ctx, cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, errors.Wrap(err, "creating worker")
|
||||
}
|
||||
deferF.Append(closer)
|
||||
|
||||
|
15
vendor/github.com/moby/buildkit/util/testutil/integration/util.go
generated
vendored
15
vendor/github.com/moby/buildkit/util/testutil/integration/util.go
generated
vendored
@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@ -100,13 +99,11 @@ func StartCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
|
||||
}, nil
|
||||
}
|
||||
|
||||
func WaitUnix(address string, d time.Duration, cmd *exec.Cmd) error {
|
||||
address = strings.TrimPrefix(address, "unix://")
|
||||
addr, err := net.ResolveUnixAddr("unix", address)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed resolving unix addr: %s", address)
|
||||
}
|
||||
|
||||
// WaitSocket will dial a socket opened by a command passed in as cmd.
|
||||
// On Linux this socket is typically a Unix socket,
|
||||
// while on Windows this will be a named pipe.
|
||||
func WaitSocket(address string, d time.Duration, cmd *exec.Cmd) error {
|
||||
address = strings.TrimPrefix(address, socketScheme)
|
||||
step := 50 * time.Millisecond
|
||||
i := 0
|
||||
for {
|
||||
@ -114,7 +111,7 @@ func WaitUnix(address string, d time.Duration, cmd *exec.Cmd) error {
|
||||
return errors.Errorf("process exited: %s", cmd.String())
|
||||
}
|
||||
|
||||
if conn, err := net.DialUnix("unix", nil, addr); err == nil {
|
||||
if conn, err := dialPipe(address); err == nil {
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
|
23
vendor/github.com/moby/buildkit/util/testutil/integration/util_unix.go
generated
vendored
Normal file
23
vendor/github.com/moby/buildkit/util/testutil/integration/util_unix.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var socketScheme = "unix://"
|
||||
|
||||
// abstracted function to handle pipe dialing on unix.
|
||||
// some simplification has been made to discard
|
||||
// laddr for unix -- left as nil.
|
||||
func dialPipe(address string) (net.Conn, error) {
|
||||
addr, err := net.ResolveUnixAddr("unix", address)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed resolving unix addr: %s", address)
|
||||
}
|
||||
return net.DialUnix("unix", nil, addr)
|
||||
}
|
15
vendor/github.com/moby/buildkit/util/testutil/integration/util_windows.go
generated
vendored
Normal file
15
vendor/github.com/moby/buildkit/util/testutil/integration/util_windows.go
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
)
|
||||
|
||||
var socketScheme = "npipe://"
|
||||
|
||||
// abstracted function to handle pipe dialing on windows.
|
||||
// some simplification has been made to discard timeout param.
|
||||
func dialPipe(address string) (net.Conn, error) {
|
||||
return winio.DialPipe(address, nil)
|
||||
}
|
26
vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go
generated
vendored
26
vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go
generated
vendored
@ -88,9 +88,11 @@ func (c *Containerd) New(ctx context.Context, cfg *integration.BackendConfig) (b
|
||||
if err := integration.LookupBinary(c.Containerd); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := integration.LookupBinary("buildkitd"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := requireRoot(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -117,6 +119,7 @@ func (c *Containerd) New(ctx context.Context, cfg *integration.BackendConfig) (b
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if rootless {
|
||||
if err := os.Chown(tmpdir, c.UID, c.GID); err != nil {
|
||||
return nil, nil, err
|
||||
@ -125,7 +128,7 @@ func (c *Containerd) New(ctx context.Context, cfg *integration.BackendConfig) (b
|
||||
|
||||
deferF.Append(func() error { return os.RemoveAll(tmpdir) })
|
||||
|
||||
address := filepath.Join(tmpdir, "containerd.sock")
|
||||
address := getContainerdSock(tmpdir)
|
||||
config := fmt.Sprintf(`root = %q
|
||||
state = %q
|
||||
# CRI plugins listens on 10010/tcp for stream server.
|
||||
@ -137,8 +140,11 @@ disabled_plugins = ["cri"]
|
||||
|
||||
[debug]
|
||||
level = "debug"
|
||||
address = %q
|
||||
`, filepath.Join(tmpdir, "root"), filepath.Join(tmpdir, "state"), address, filepath.Join(tmpdir, "debug.sock"))
|
||||
address = %q`,
|
||||
filepath.Join(tmpdir, "root"),
|
||||
filepath.Join(tmpdir, "state"),
|
||||
address, getContainerdDebugSock(tmpdir),
|
||||
)
|
||||
|
||||
var snBuildkitdArgs []string
|
||||
if c.Snapshotter != "" {
|
||||
@ -185,19 +191,23 @@ disabled_plugins = ["cri"]
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := integration.WaitUnix(address, 10*time.Second, cmd); err != nil {
|
||||
if err := integration.WaitSocket(address, 10*time.Second, cmd); err != nil {
|
||||
ctdStop()
|
||||
return nil, nil, errors.Wrapf(err, "containerd did not start up: %s", integration.FormatLogs(cfg.Logs))
|
||||
}
|
||||
deferF.Append(ctdStop)
|
||||
|
||||
buildkitdArgs := append([]string{"buildkitd",
|
||||
"--oci-worker=false",
|
||||
// handles only windows case, no effect on unix
|
||||
address = normalizeAddress(address)
|
||||
buildkitdArgs := []string{
|
||||
"buildkitd",
|
||||
"--containerd-worker-gc=false",
|
||||
"--containerd-worker=true",
|
||||
"--containerd-worker-addr", address,
|
||||
"--containerd-worker-labels=org.mobyproject.buildkit.worker.sandbox=true", // Include use of --containerd-worker-labels to trigger https://github.com/moby/buildkit/pull/603
|
||||
}, snBuildkitdArgs...)
|
||||
}
|
||||
buildkitdArgs = applyBuildkitdPlatformFlags(buildkitdArgs)
|
||||
buildkitdArgs = append(buildkitdArgs, snBuildkitdArgs...)
|
||||
|
||||
if runtime.GOOS != "windows" && c.Snapshotter != "native" {
|
||||
c.ExtraEnv = append(c.ExtraEnv, "BUILDKIT_DEBUG_FORCE_OVERLAY_DIFF=true")
|
||||
@ -266,7 +276,7 @@ func runStargzSnapshotter(cfg *integration.BackendConfig) (address string, cl fu
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err = integration.WaitUnix(address, 10*time.Second, cmd); err != nil {
|
||||
if err = integration.WaitSocket(address, 10*time.Second, cmd); err != nil {
|
||||
snStop()
|
||||
return "", nil, errors.Wrapf(err, "containerd-stargz-grpc did not start up: %s", integration.FormatLogs(cfg.Logs))
|
||||
}
|
||||
|
2
vendor/github.com/moby/buildkit/util/testutil/workers/dockerd.go
generated
vendored
2
vendor/github.com/moby/buildkit/util/testutil/workers/dockerd.go
generated
vendored
@ -159,7 +159,7 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
|
||||
}
|
||||
deferF.Append(d.StopWithError)
|
||||
|
||||
if err := integration.WaitUnix(d.Sock(), 5*time.Second, nil); err != nil {
|
||||
if err := integration.WaitSocket(d.Sock(), 5*time.Second, nil); err != nil {
|
||||
return nil, nil, errors.Errorf("dockerd did not start up: %q, %s", err, integration.FormatLogs(cfg.Logs))
|
||||
}
|
||||
|
||||
|
23
vendor/github.com/moby/buildkit/util/testutil/workers/oci.go
generated
vendored
23
vendor/github.com/moby/buildkit/util/testutil/workers/oci.go
generated
vendored
@ -4,31 +4,18 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/moby/buildkit/util/bklog"
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// InitOCIWorker registers an integration test worker, which enables the --oci-worker
|
||||
// flag in the test buildkitd instance and disables the --containerd-worker flag. This
|
||||
// integration test worker is not supported on Windows.
|
||||
func InitOCIWorker() {
|
||||
integration.Register(&OCI{ID: "oci"})
|
||||
|
||||
// the rootless uid is defined in Dockerfile
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
||||
var uid, gid int
|
||||
if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil {
|
||||
bklog.L.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s)
|
||||
}
|
||||
if integration.RootlessSupported(uid) {
|
||||
integration.Register(&OCI{ID: "oci-rootless", UID: uid, GID: gid})
|
||||
}
|
||||
}
|
||||
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_SNAPSHOTTER"); s != "" {
|
||||
integration.Register(&OCI{ID: "oci-snapshotter-" + s, Snapshotter: s})
|
||||
}
|
||||
// calling platform specific
|
||||
initOCIWorker()
|
||||
}
|
||||
|
||||
type OCI struct {
|
||||
|
31
vendor/github.com/moby/buildkit/util/testutil/workers/oci_unix.go
generated
vendored
Normal file
31
vendor/github.com/moby/buildkit/util/testutil/workers/oci_unix.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/moby/buildkit/util/bklog"
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
)
|
||||
|
||||
func initOCIWorker() {
|
||||
integration.Register(&OCI{ID: "oci"})
|
||||
|
||||
// the rootless uid is defined in Dockerfile
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
||||
var uid, gid int
|
||||
if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil {
|
||||
bklog.L.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s)
|
||||
}
|
||||
if integration.RootlessSupported(uid) {
|
||||
integration.Register(&OCI{ID: "oci-rootless", UID: uid, GID: gid})
|
||||
}
|
||||
}
|
||||
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_SNAPSHOTTER"); s != "" {
|
||||
integration.Register(&OCI{ID: "oci-snapshotter-" + s, Snapshotter: s})
|
||||
}
|
||||
}
|
7
vendor/github.com/moby/buildkit/util/testutil/workers/oci_windows.go
generated
vendored
Normal file
7
vendor/github.com/moby/buildkit/util/testutil/workers/oci_windows.go
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
package workers
|
||||
|
||||
import "github.com/moby/buildkit/util/bklog"
|
||||
|
||||
func initOCIWorker() {
|
||||
bklog.L.Info("OCI Worker not supported on Windows.")
|
||||
}
|
23
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_unix.go
generated
vendored
23
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_unix.go
generated
vendored
@ -1,23 +0,0 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{
|
||||
Setsid: true, // stretch sudo needs this for sigterm
|
||||
}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "otel-grpc.sock")
|
||||
}
|
21
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_windows.go
generated
vendored
21
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_windows.go
generated
vendored
@ -1,21 +0,0 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "//./pipe/buildkitd-" + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return `\\.\pipe\buildkit-otel-grpc-` + filepath.Base(tmpdir)
|
||||
}
|
157
vendor/github.com/moby/buildkit/util/testutil/workers/util.go
generated
vendored
157
vendor/github.com/moby/buildkit/util/testutil/workers/util.go
generated
vendored
@ -1,98 +1,17 @@
|
||||
package workers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func requireRoot() error {
|
||||
if os.Getuid() != 0 {
|
||||
return errors.Wrap(integration.ErrRequirements, "requires root")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []string, logs map[string]*bytes.Buffer, uid, gid int, extraEnv []string) (address string, cl func() error, err error) {
|
||||
deferF := &integration.MultiCloser{}
|
||||
cl = deferF.F()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
deferF.F()()
|
||||
cl = nil
|
||||
}
|
||||
}()
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "bktest_buildkitd")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := os.Chown(tmpdir, uid, gid); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(tmpdir, "tmp"), 0711); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := os.Chown(filepath.Join(tmpdir, "tmp"), uid, gid); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(func() error { return os.RemoveAll(tmpdir) })
|
||||
|
||||
cfgfile, err := integration.WriteConfig(append(conf.DaemonConfig, withOTELSocketPath(getTraceSocketPath(tmpdir))))
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(func() error {
|
||||
return os.RemoveAll(filepath.Dir(cfgfile))
|
||||
})
|
||||
args = append(args, "--config="+cfgfile)
|
||||
|
||||
address = getBuildkitdAddr(tmpdir)
|
||||
|
||||
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
|
||||
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
|
||||
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
|
||||
cmd.Env = append(cmd.Env, extraEnv...)
|
||||
cmd.SysProcAttr = getSysProcAttr()
|
||||
|
||||
stop, err := integration.StartCmd(cmd, logs)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(stop)
|
||||
|
||||
if err := integration.WaitUnix(address, 15*time.Second, cmd); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
deferF.Append(func() error {
|
||||
f, err := os.Open("/proc/self/mountinfo")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open mountinfo")
|
||||
}
|
||||
defer f.Close()
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if strings.Contains(s.Text(), tmpdir) {
|
||||
return errors.Errorf("leaked mountpoint for %s", tmpdir)
|
||||
}
|
||||
}
|
||||
return s.Err()
|
||||
})
|
||||
|
||||
return address, cl, err
|
||||
}
|
||||
|
||||
func withOTELSocketPath(socketPath string) integration.ConfigUpdater {
|
||||
return otelSocketPath(socketPath)
|
||||
}
|
||||
@ -106,3 +25,79 @@ func (osp otelSocketPath) UpdateConfigFile(in string) string {
|
||||
socketPath = %q
|
||||
`, in, osp)
|
||||
}
|
||||
|
||||
func runBuildkitd(
|
||||
ctx context.Context,
|
||||
conf *integration.BackendConfig,
|
||||
args []string,
|
||||
logs map[string]*bytes.Buffer,
|
||||
uid, gid int,
|
||||
extraEnv []string,
|
||||
) (address string, cl func() error, err error) {
|
||||
deferF := &integration.MultiCloser{}
|
||||
cl = deferF.F()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
deferF.F()()
|
||||
cl = nil
|
||||
}
|
||||
}()
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "bktest_buildkitd")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := chown(tmpdir, uid, gid); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Join(tmpdir, "tmp"), 0711); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := chown(filepath.Join(tmpdir, "tmp"), uid, gid); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(func() error { return os.RemoveAll(tmpdir) })
|
||||
|
||||
cfgfile, err := integration.WriteConfig(
|
||||
append(conf.DaemonConfig, withOTELSocketPath(getTraceSocketPath(tmpdir))))
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(func() error {
|
||||
return os.RemoveAll(filepath.Dir(cfgfile))
|
||||
})
|
||||
|
||||
args = append(args, "--config="+cfgfile)
|
||||
address = getBuildkitdAddr(tmpdir)
|
||||
|
||||
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
|
||||
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
|
||||
cmd.Env = append(
|
||||
os.Environ(),
|
||||
"BUILDKIT_DEBUG_EXEC_OUTPUT=1",
|
||||
"BUILDKIT_DEBUG_PANIC_ON_ERROR=1",
|
||||
"TMPDIR="+filepath.Join(tmpdir, "tmp"))
|
||||
cmd.Env = append(cmd.Env, extraEnv...)
|
||||
cmd.SysProcAttr = getSysProcAttr()
|
||||
|
||||
stop, err := integration.StartCmd(cmd, logs)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(stop)
|
||||
|
||||
if err := integration.WaitSocket(address, 15*time.Second, cmd); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
// separated out since it's not required in windows
|
||||
deferF.Append(func() error {
|
||||
return mountInfo(tmpdir)
|
||||
})
|
||||
|
||||
return address, cl, err
|
||||
}
|
||||
|
74
vendor/github.com/moby/buildkit/util/testutil/workers/util_unix.go
generated
vendored
Normal file
74
vendor/github.com/moby/buildkit/util/testutil/workers/util_unix.go
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func applyBuildkitdPlatformFlags(args []string) []string {
|
||||
return append(args, "--oci-worker=false")
|
||||
}
|
||||
|
||||
func requireRoot() error {
|
||||
if os.Getuid() != 0 {
|
||||
return errors.Wrap(integration.ErrRequirements, "requires root")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{
|
||||
Setsid: true, // stretch sudo needs this for sigterm
|
||||
}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "otel-grpc.sock")
|
||||
}
|
||||
|
||||
func getContainerdSock(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "containerd.sock")
|
||||
}
|
||||
|
||||
func getContainerdDebugSock(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "debug.sock")
|
||||
}
|
||||
|
||||
func mountInfo(tmpdir string) error {
|
||||
f, err := os.Open("/proc/self/mountinfo")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open mountinfo")
|
||||
}
|
||||
defer f.Close()
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if strings.Contains(s.Text(), tmpdir) {
|
||||
return errors.Errorf("leaked mountpoint for %s", tmpdir)
|
||||
}
|
||||
}
|
||||
return s.Err()
|
||||
}
|
||||
|
||||
// moved here since os.Chown is not supported on Windows.
|
||||
// see no-op counterpart in util_windows.go
|
||||
func chown(name string, uid, gid int) error {
|
||||
return os.Chown(name, uid, gid)
|
||||
}
|
||||
|
||||
func normalizeAddress(address string) string {
|
||||
// for parity with windows, no effect for unix
|
||||
return address
|
||||
}
|
53
vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go
generated
vendored
Normal file
53
vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
package workers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func applyBuildkitdPlatformFlags(args []string) []string {
|
||||
return args
|
||||
}
|
||||
|
||||
func requireRoot() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "npipe:////./pipe/buildkitd-" + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return `\\.\pipe\buildkit-otel-grpc-` + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getContainerdSock(tmpdir string) string {
|
||||
return `\\.\pipe\containerd-` + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getContainerdDebugSock(tmpdir string) string {
|
||||
return `\\.\pipe\containerd-` + filepath.Base(tmpdir) + `debug`
|
||||
}
|
||||
|
||||
// no-op for parity with unix
|
||||
func mountInfo(tmpdir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func chown(name string, uid, gid int) error {
|
||||
// Chown not supported on Windows
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeAddress(address string) string {
|
||||
address = filepath.ToSlash(address)
|
||||
if !strings.HasPrefix(address, "npipe://") {
|
||||
address = "npipe://" + address
|
||||
}
|
||||
return address
|
||||
}
|
5
vendor/github.com/moby/buildkit/util/tracing/detect/delegated/delegated.go
generated
vendored
5
vendor/github.com/moby/buildkit/util/tracing/detect/delegated/delegated.go
generated
vendored
@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/moby/buildkit/util/tracing/detect"
|
||||
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
@ -13,8 +14,8 @@ const maxBuffer = 256
|
||||
var exp = &Exporter{}
|
||||
|
||||
func init() {
|
||||
detect.Register("delegated", func() (sdktrace.SpanExporter, error) {
|
||||
return exp, nil
|
||||
detect.Register("delegated", func() (sdktrace.SpanExporter, sdkmetric.Exporter, error) {
|
||||
return exp, nil, nil
|
||||
}, 100)
|
||||
}
|
||||
|
||||
|
160
vendor/github.com/moby/buildkit/util/tracing/detect/detect.go
generated
vendored
160
vendor/github.com/moby/buildkit/util/tracing/detect/detect.go
generated
vendored
@ -10,13 +10,16 @@ import (
|
||||
|
||||
"github.com/moby/buildkit/util/bklog"
|
||||
"github.com/pkg/errors"
|
||||
"go.opentelemetry.io/otel/exporters/prometheus"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type ExporterDetector func() (sdktrace.SpanExporter, error)
|
||||
type ExporterDetector func() (sdktrace.SpanExporter, sdkmetric.Exporter, error)
|
||||
|
||||
type detector struct {
|
||||
f ExporterDetector
|
||||
@ -26,10 +29,16 @@ type detector struct {
|
||||
var ServiceName string
|
||||
var Recorder *TraceRecorder
|
||||
|
||||
var Resource *resource.Resource
|
||||
|
||||
var detectors map[string]detector
|
||||
var once sync.Once
|
||||
var tp trace.TracerProvider
|
||||
var exporter sdktrace.SpanExporter
|
||||
var mp metric.MeterProvider
|
||||
var exporter struct {
|
||||
SpanExporter sdktrace.SpanExporter
|
||||
MetricExporter sdkmetric.Exporter
|
||||
}
|
||||
var closers []func(context.Context) error
|
||||
var err error
|
||||
|
||||
@ -43,14 +52,14 @@ func Register(name string, exp ExporterDetector, priority int) {
|
||||
}
|
||||
}
|
||||
|
||||
func detectExporter() (sdktrace.SpanExporter, error) {
|
||||
func detectExporter() (texp sdktrace.SpanExporter, mexp sdkmetric.Exporter, err error) {
|
||||
if n := os.Getenv("OTEL_TRACES_EXPORTER"); n != "" {
|
||||
d, ok := detectors[n]
|
||||
if !ok {
|
||||
if n == "none" {
|
||||
return nil, nil
|
||||
return nil, nil, nil
|
||||
}
|
||||
return nil, errors.Errorf("unsupported opentelemetry tracer %v", n)
|
||||
return nil, nil, errors.Errorf("unsupported opentelemetry tracer %v", n)
|
||||
}
|
||||
return d.f()
|
||||
}
|
||||
@ -61,84 +70,145 @@ func detectExporter() (sdktrace.SpanExporter, error) {
|
||||
sort.Slice(arr, func(i, j int) bool {
|
||||
return arr[i].priority < arr[j].priority
|
||||
})
|
||||
|
||||
for _, d := range arr {
|
||||
exp, err := d.f()
|
||||
t, m, err := d.f()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if exp != nil {
|
||||
return exp, nil
|
||||
if texp == nil {
|
||||
texp = t
|
||||
}
|
||||
if mexp == nil {
|
||||
mexp = m
|
||||
}
|
||||
|
||||
// Found a candidate for both exporters so just return now.
|
||||
if texp != nil && mexp != nil {
|
||||
return texp, mexp, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return texp, mexp, nil
|
||||
}
|
||||
|
||||
func getExporter() (sdktrace.SpanExporter, error) {
|
||||
exp, err := detectExporter()
|
||||
func getExporters() (sdktrace.SpanExporter, sdkmetric.Exporter, error) {
|
||||
texp, mexp, err := detectExporter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if Recorder != nil {
|
||||
Recorder.SpanExporter = exp
|
||||
exp = Recorder
|
||||
Recorder.SpanExporter = texp
|
||||
texp = Recorder
|
||||
}
|
||||
return exp, nil
|
||||
|
||||
return texp, mexp, nil
|
||||
}
|
||||
|
||||
func detect() error {
|
||||
tp = trace.NewNoopTracerProvider()
|
||||
mp = sdkmetric.NewMeterProvider()
|
||||
|
||||
exp, err := getExporter()
|
||||
if err != nil || exp == nil {
|
||||
texp, mexp, err := getExporters()
|
||||
if err != nil || (texp == nil && mexp == nil) {
|
||||
return err
|
||||
}
|
||||
|
||||
if Resource == nil {
|
||||
res, err := resource.Detect(context.Background(), serviceNameDetector{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res, err = resource.Merge(resource.Default(), res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Resource = res
|
||||
}
|
||||
|
||||
// enable log with traceID when valid exporter
|
||||
bklog.EnableLogWithTraceID(true)
|
||||
if texp != nil {
|
||||
bklog.EnableLogWithTraceID(true)
|
||||
|
||||
res, err := resource.Detect(context.Background(), serviceNameDetector{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res, err = resource.Merge(resource.Default(), res)
|
||||
if err != nil {
|
||||
return err
|
||||
sp := sdktrace.NewBatchSpanProcessor(texp)
|
||||
|
||||
if Recorder != nil {
|
||||
Recorder.flush = sp.ForceFlush
|
||||
}
|
||||
|
||||
sdktp := sdktrace.NewTracerProvider(
|
||||
sdktrace.WithSpanProcessor(sp),
|
||||
sdktrace.WithResource(Resource),
|
||||
)
|
||||
closers = append(closers, sdktp.Shutdown)
|
||||
|
||||
exporter.SpanExporter = texp
|
||||
tp = sdktp
|
||||
}
|
||||
|
||||
sp := sdktrace.NewBatchSpanProcessor(exp)
|
||||
|
||||
if Recorder != nil {
|
||||
Recorder.flush = sp.ForceFlush
|
||||
var readers []sdkmetric.Reader
|
||||
if mexp != nil {
|
||||
// Create a new periodic reader using any configured metric exporter.
|
||||
readers = append(readers, sdkmetric.NewPeriodicReader(mexp))
|
||||
}
|
||||
|
||||
sdktp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sp), sdktrace.WithResource(res))
|
||||
closers = append(closers, sdktp.Shutdown)
|
||||
if r, err := prometheus.New(); err != nil {
|
||||
// Log the error but do not fail if we could not configure the prometheus metrics.
|
||||
bklog.G(context.Background()).
|
||||
WithError(err).
|
||||
Error("failed prometheus metrics configuration")
|
||||
} else {
|
||||
// Register the prometheus reader if there was no error.
|
||||
readers = append(readers, r)
|
||||
}
|
||||
|
||||
exporter = exp
|
||||
tp = sdktp
|
||||
if len(readers) > 0 {
|
||||
opts := make([]sdkmetric.Option, 0, len(readers)+1)
|
||||
opts = append(opts, sdkmetric.WithResource(Resource))
|
||||
for _, r := range readers {
|
||||
opts = append(opts, sdkmetric.WithReader(r))
|
||||
}
|
||||
sdkmp := sdkmetric.NewMeterProvider(opts...)
|
||||
closers = append(closers, sdkmp.Shutdown)
|
||||
|
||||
exporter.MetricExporter = mexp
|
||||
mp = sdkmp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TracerProvider() (trace.TracerProvider, error) {
|
||||
once.Do(func() {
|
||||
if err1 := detect(); err1 != nil {
|
||||
err = err1
|
||||
}
|
||||
})
|
||||
b, _ := strconv.ParseBool(os.Getenv("OTEL_IGNORE_ERROR"))
|
||||
if err != nil && !b {
|
||||
if err := detectOnce(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tp, nil
|
||||
}
|
||||
|
||||
func Exporter() (sdktrace.SpanExporter, error) {
|
||||
_, err := TracerProvider()
|
||||
if err != nil {
|
||||
func MeterProvider() (metric.MeterProvider, error) {
|
||||
if err := detectOnce(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return exporter, nil
|
||||
return mp, nil
|
||||
}
|
||||
|
||||
func detectOnce() error {
|
||||
once.Do(func() {
|
||||
if err1 := detect(); err1 != nil {
|
||||
b, _ := strconv.ParseBool(os.Getenv("OTEL_IGNORE_ERROR"))
|
||||
if !b {
|
||||
err = err1
|
||||
}
|
||||
}
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func Exporter() (sdktrace.SpanExporter, sdkmetric.Exporter, error) {
|
||||
_, err := TracerProvider()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return exporter.SpanExporter, exporter.MetricExporter, nil
|
||||
}
|
||||
|
||||
func Shutdown(ctx context.Context) error {
|
||||
|
52
vendor/github.com/moby/buildkit/util/tracing/detect/otlp.go
generated
vendored
52
vendor/github.com/moby/buildkit/util/tracing/detect/otlp.go
generated
vendored
@ -5,9 +5,13 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
||||
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
@ -15,7 +19,20 @@ func init() {
|
||||
Register("otlp", otlpExporter, 10)
|
||||
}
|
||||
|
||||
func otlpExporter() (sdktrace.SpanExporter, error) {
|
||||
func otlpExporter() (sdktrace.SpanExporter, sdkmetric.Exporter, error) {
|
||||
texp, err := otlpSpanExporter()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
mexp, err := otlpMetricExporter()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return texp, mexp, nil
|
||||
}
|
||||
|
||||
func otlpSpanExporter() (sdktrace.SpanExporter, error) {
|
||||
set := os.Getenv("OTEL_TRACES_EXPORTER") == "otlp" || os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != "" || os.Getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") != ""
|
||||
if !set {
|
||||
return nil, nil
|
||||
@ -43,3 +60,36 @@ func otlpExporter() (sdktrace.SpanExporter, error) {
|
||||
|
||||
return otlptrace.New(context.Background(), c)
|
||||
}
|
||||
|
||||
func otlpMetricExporter() (sdkmetric.Exporter, error) {
|
||||
set := os.Getenv("OTEL_METRICS_EXPORTER") == "otlp" || os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != "" || os.Getenv("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT") != ""
|
||||
if !set {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
proto := os.Getenv("OTEL_EXPORTER_OTLP_METRICS_PROTOCOL")
|
||||
if proto == "" {
|
||||
proto = os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL")
|
||||
}
|
||||
if proto == "" {
|
||||
proto = "grpc"
|
||||
}
|
||||
|
||||
switch proto {
|
||||
case "grpc":
|
||||
return otlpmetricgrpc.New(context.Background(),
|
||||
otlpmetricgrpc.WithTemporalitySelector(deltaTemporality),
|
||||
)
|
||||
case "http/protobuf":
|
||||
return otlpmetrichttp.New(context.Background(),
|
||||
otlpmetrichttp.WithTemporalitySelector(deltaTemporality),
|
||||
)
|
||||
// case "http/json": // unsupported by library
|
||||
default:
|
||||
return nil, errors.Errorf("unsupported otlp protocol %v", proto)
|
||||
}
|
||||
}
|
||||
|
||||
func deltaTemporality(_ sdkmetric.InstrumentKind) metricdata.Temporality {
|
||||
return metricdata.DeltaTemporality
|
||||
}
|
||||
|
7
vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/client.go
generated
vendored
7
vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/client.go
generated
vendored
@ -70,9 +70,10 @@ func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
|
||||
}
|
||||
|
||||
ctx, cancel := c.connection.ContextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx, tCancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer tCancel()
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
ctx, tCancel := context.WithCancelCause(ctx)
|
||||
ctx, _ = context.WithTimeoutCause(ctx, 30*time.Second, errors.WithStack(context.DeadlineExceeded))
|
||||
defer tCancel(errors.WithStack(context.Canceled))
|
||||
|
||||
ctx = c.connection.ContextWithMetadata(ctx)
|
||||
err := func() error {
|
||||
|
11
vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/connection.go
generated
vendored
11
vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/connection.go
generated
vendored
@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
@ -185,7 +186,7 @@ func (c *Connection) Shutdown(ctx context.Context) error {
|
||||
select {
|
||||
case <-c.backgroundConnectionDoneCh:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
return context.Cause(ctx)
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
@ -200,17 +201,17 @@ func (c *Connection) Shutdown(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Connection) ContextWithStop(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||
func (c *Connection) ContextWithStop(ctx context.Context) (context.Context, context.CancelCauseFunc) {
|
||||
// Unify the parent context Done signal with the Connection's
|
||||
// stop channel.
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
go func(ctx context.Context, cancel context.CancelFunc) {
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
go func(ctx context.Context, cancel context.CancelCauseFunc) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// Nothing to do, either cancelled or deadline
|
||||
// happened.
|
||||
case <-c.stopCh:
|
||||
cancel()
|
||||
cancel(errors.WithStack(context.Canceled))
|
||||
}
|
||||
}(ctx, cancel)
|
||||
return ctx, cancel
|
||||
|
Reference in New Issue
Block a user