Skip to content

Commit

Permalink
buildkitd: otel config and otel-socket-path flag
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Aug 3, 2023
1 parent 659fba6 commit 29964d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cmd/buildkitd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Config struct {
// GRPC configuration settings
GRPC GRPCConfig `toml:"grpc"`

OTEL OTELConfig `toml:"otel"`

Workers struct {
OCI OCIConfig `toml:"oci"`
Containerd ContainerdConfig `toml:"containerd"`
Expand Down Expand Up @@ -46,6 +48,10 @@ type TLSConfig struct {
CA string `toml:"ca"`
}

type OTELConfig struct {
SocketPath string `toml:"socket-path"`
}

type GCConfig struct {
GC *bool `toml:"gc"`
GCKeepStorage DiskSpace `toml:"gckeepstorage"`
Expand Down
6 changes: 5 additions & 1 deletion cmd/buildkitd/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ insecure-entitlements = ["security.insecure"]
[gc]
enabled=true
[grpc]
address=["buildkit.sock"]
debugAddress="debug.sock"
gid=1234
[grpc.tls]
cert="mycert.pem"
[otel]
socket-path="/tmp/otel-grpc.sock"
[worker.oci]
enabled=true
snapshotter="overlay"
Expand Down Expand Up @@ -83,6 +85,8 @@ searchDomains=["example.com"]
require.Equal(t, 1234, *cfg.GRPC.GID)
require.Equal(t, "mycert.pem", cfg.GRPC.TLS.Cert)

require.Equal(t, "/tmp/otel-grpc.sock", cfg.OTEL.SocketPath)

require.NotNil(t, cfg.Workers.OCI.Enabled)
require.Equal(t, int64(123456789), cfg.Workers.OCI.GCKeepStorage.Bytes)
require.Equal(t, true, *cfg.Workers.OCI.Enabled)
Expand Down
19 changes: 14 additions & 5 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func main() {
Name: "allow-insecure-entitlement",
Usage: "allows insecure entitlements e.g. network.host, security.insecure",
},
cli.StringFlag{
Name: "otel-socket-path",
Usage: "OTEL collector trace socket path",
},
)
app.Flags = append(app.Flags, appFlags...)
app.Flags = append(app.Flags, serviceFlags()...)
Expand Down Expand Up @@ -458,6 +462,10 @@ func setDefaultConfig(cfg *config.Config) {
appdefaults.EnsureUserAddressDir()
}
}

if cfg.OTEL.SocketPath == "" {
cfg.OTEL.SocketPath = appdefaults.TraceSocketPath(userns.RunningInUserNS())
}
}

func applyMainFlags(c *cli.Context, cfg *config.Config) error {
Expand Down Expand Up @@ -511,6 +519,11 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
if tlsca := c.String("tlscacert"); tlsca != "" {
cfg.GRPC.TLS.CA = tlsca
}

if c.IsSet("trace-socket") {
cfg.OTEL.SocketPath = c.String("trace-socket")
}

applyPlatformFlags(c)

return nil
Expand Down Expand Up @@ -661,11 +674,7 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err

var traceSocket string
if tc != nil {
if v, ok := os.LookupEnv("BUILDKIT_TRACE_SOCKET"); ok {
traceSocket = v
} else {
traceSocket = appdefaults.TraceSocketPath(userns.RunningInUserNS())
}
traceSocket = cfg.OTEL.SocketPath
if err := runTraceController(traceSocket, tc); err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions docs/buildkitd.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
key = "/etc/buildkit/tls.key"
ca = "/etc/buildkit/tlsca.crt"

[otel]
# OTEL collector trace socket path
socket-path = "/run/buildkit/otel-grpc.sock"

# config for build history API that stores information about completed build commands
[history]
# maxAge is the maximum age of history entries to keep, in seconds.
Expand Down

0 comments on commit 29964d4

Please sign in to comment.