Skip to content

Commit

Permalink
set tracing socket path to runtime dir
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jul 31, 2023
1 parent 9da03ce commit a7690c5
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 26 deletions.
6 changes: 5 additions & 1 deletion cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,11 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err

var traceSocket string
if tc != nil {
traceSocket = traceSocketPath(cfg.Root)
if v, ok := os.LookupEnv("BUILDKIT_TRACE_SOCKET"); ok {
traceSocket = v
} else {
traceSocket = appdefaults.TraceSocketPath(userns.RunningInUserNS())
}
if err := runTraceController(traceSocket, tc); err != nil {
return nil, err
}
Expand Down
5 changes: 0 additions & 5 deletions cmd/buildkitd/main_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/tls"
"net"
"os"
"path/filepath"
"syscall"

"github.com/containerd/containerd/sys"
Expand Down Expand Up @@ -47,10 +46,6 @@ func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
return nil, errors.New("not supported yet")
}

func traceSocketPath(root string) string {
return filepath.Join(root, "otel-grpc.sock")
}

func getLocalListener(listenerPath string) (net.Listener, error) {
uid := os.Getuid()
l, err := sys.GetLocalListener(listenerPath, uid, uid)
Expand Down
8 changes: 0 additions & 8 deletions cmd/buildkitd/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ import (
"github.com/pkg/errors"
)

const (
defaultTraceSocketPath = `\\.\pipe\buildkit-otel-grpc`
)

func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
return nil, errors.New("listening server on fd not supported on windows")
}

func traceSocketPath(root string) string {
return defaultTraceSocketPath
}

func getLocalListener(listenerPath string) (net.Listener, error) {
pc := &winio.PipeConfig{
// Allow generic read and generic write access to authenticated users
Expand Down
10 changes: 10 additions & 0 deletions util/appdefaults/appdefaults_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ func UserConfigDir() string {
}
return ConfigDir
}

func TraceSocketPath(inUserNS bool) string {
if inUserNS {
if xrd := os.Getenv("XDG_RUNTIME_DIR"); xrd != "" {
dirs := strings.Split(xrd, ":")
return filepath.Join(dirs[0], "buildkit", "otel-grpc.sock")
}
}
return "/run/buildkit/otel-grpc.sock"
}
4 changes: 4 additions & 0 deletions util/appdefaults/appdefaults_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func UserRoot() string {
func UserConfigDir() string {
return ConfigDir
}

func TraceSocketPath(inUserNS bool) string {
return `\\.\pipe\buildkit-otel-grpc`
}
11 changes: 1 addition & 10 deletions util/testutil/integration/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -181,14 +180,6 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
}, cl, nil
}

func getBuildkitdAddr(tmpdir string) string {
address := "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
if runtime.GOOS == "windows" {
address = "//./pipe/buildkitd-" + filepath.Base(tmpdir)
}
return address
}

func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs map[string]*bytes.Buffer, uid, gid int, extraEnv []string) (address string, cl func() error, err error) {
deferF := &multiCloser{}
cl = deferF.F()
Expand Down Expand Up @@ -224,7 +215,7 @@ func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs

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(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "BUILDKIT_TRACE_SOCKET="+getTraceSocketPath(tmpdir), "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(cmd.Env, extraEnv...)
cmd.SysProcAttr = getSysProcAttr()

Expand Down
13 changes: 12 additions & 1 deletion util/testutil/integration/sandbox_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@

package integration

import "syscall"
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")
}
13 changes: 12 additions & 1 deletion util/testutil/integration/sandbox_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

package integration

import "syscall"
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)
}

0 comments on commit a7690c5

Please sign in to comment.