From 1dc803cb8d3e297d25f4ba147a59c59dc1c51113 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Thu, 9 Feb 2023 10:54:10 -0800 Subject: [PATCH] Add platform tracing socket paths and mounts Signed-off-by: Gabriel Adrian Samfira --- executor/oci/spec.go | 22 +++++++--------------- executor/oci/spec_unix.go | 13 +++++++++++++ executor/oci/spec_windows.go | 19 ++++++++++++++----- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/executor/oci/spec.go b/executor/oci/spec.go index d313c3f70634c..dfa2f29293f82 100644 --- a/executor/oci/spec.go +++ b/executor/oci/spec.go @@ -4,7 +4,6 @@ import ( "context" "path" "path/filepath" - "runtime" "strings" "sync" @@ -36,6 +35,12 @@ const ( NoProcessSandbox ) +var tracingEnvVars = []string{ + "OTEL_TRACES_EXPORTER=otlp", + "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=unix://" + filepath.ToSlash(tracingSocketPath), + "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc", +} + func (pm ProcessMode) String() string { switch pm { case ProcessSandbox: @@ -184,20 +189,7 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou } if tracingSocket != "" { - if runtime.GOOS == "windows" { - s.Mounts = append(s.Mounts, specs.Mount{ - Destination: `\\.\pipe\otel-grpc`, - Source: tracingSocket, - Options: []string{"ro"}, - }) - } else { - s.Mounts = append(s.Mounts, specs.Mount{ - Destination: "/dev/otel-grpc.sock", - Type: "bind", - Source: tracingSocket, - Options: []string{"ro", "rbind"}, - }) - } + s.Mounts = append(s.Mounts, getTracingSocketMount(tracingSocket)) } s.Mounts = dedupMounts(s.Mounts) diff --git a/executor/oci/spec_unix.go b/executor/oci/spec_unix.go index 3933764c8502e..592d44e7608d6 100644 --- a/executor/oci/spec_unix.go +++ b/executor/oci/spec_unix.go @@ -21,6 +21,10 @@ import ( "github.com/pkg/errors" ) +const ( + tracingSocketPath = "/dev/otel-grpc.sock" +) + var tracingEnvVars = []string{ "OTEL_TRACES_EXPORTER=otlp", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=unix:///dev/otel-grpc.sock", @@ -128,3 +132,12 @@ func withDefaultProfile() oci.SpecOpts { return err } } + +func getTracingSocketMount(socket string) specs.Mount { + return specs.Mount{ + Destination: tracingSocketPath, + Type: "bind", + Source: socket, + Options: []string{"ro", "rbind"}, + } +} \ No newline at end of file diff --git a/executor/oci/spec_windows.go b/executor/oci/spec_windows.go index 69827931cf474..8696ec8aeec17 100644 --- a/executor/oci/spec_windows.go +++ b/executor/oci/spec_windows.go @@ -4,17 +4,18 @@ package oci import ( + "path/filepath" + "github.com/containerd/containerd/oci" "github.com/docker/docker/pkg/idtools" "github.com/moby/buildkit/solver/pb" + specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" ) -var tracingEnvVars = []string{ - "OTEL_TRACES_EXPORTER=otlp", - "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=npipe:////./pipe/otel-grpc", - "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc", -} +const ( + tracingSocketPath = "//./pipe/otel-grpc" +) func generateMountOpts(resolvConf, hostsFile string) ([]oci.SpecOpts, error) { return nil, nil @@ -49,3 +50,11 @@ func generateRlimitOpts(ulimits []*pb.Ulimit) ([]oci.SpecOpts, error) { } return nil, errors.New("no support for POSIXRlimit on Windows") } + +func getTracingSocketMount(socket string) specs.Mount { + return specs.Mount{ + Destination: filepath.FromSlash(tracingSocketPath), + Source: socket, + Options: []string{"ro"}, + } +}