Skip to content

Commit b133b13

Browse files
Add platform tracing socket paths and mounts
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 7d6bee2 commit b133b13

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

executor/oci/spec.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"path"
66
"path/filepath"
7-
"runtime"
87
"strings"
98
"sync"
109

@@ -36,6 +35,12 @@ const (
3635
NoProcessSandbox
3736
)
3837

38+
var tracingEnvVars = []string{
39+
"OTEL_TRACES_EXPORTER=otlp",
40+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=" + getTracingSocket(),
41+
"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc",
42+
}
43+
3944
func (pm ProcessMode) String() string {
4045
switch pm {
4146
case ProcessSandbox:
@@ -184,20 +189,7 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
184189
}
185190

186191
if tracingSocket != "" {
187-
if runtime.GOOS == "windows" {
188-
s.Mounts = append(s.Mounts, specs.Mount{
189-
Destination: `\\.\pipe\otel-grpc`,
190-
Source: tracingSocket,
191-
Options: []string{"ro"},
192-
})
193-
} else {
194-
s.Mounts = append(s.Mounts, specs.Mount{
195-
Destination: "/dev/otel-grpc.sock",
196-
Type: "bind",
197-
Source: tracingSocket,
198-
Options: []string{"ro", "rbind"},
199-
})
200-
}
192+
s.Mounts = append(s.Mounts, getTracingSocketMount(tracingSocket))
201193
}
202194

203195
s.Mounts = dedupMounts(s.Mounts)

executor/oci/spec_unix.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import (
2121
"github.com/pkg/errors"
2222
)
2323

24-
var tracingEnvVars = []string{
25-
"OTEL_TRACES_EXPORTER=otlp",
26-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=unix:///dev/otel-grpc.sock",
27-
"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc",
28-
}
24+
const (
25+
tracingSocketPath = "/dev/otel-grpc.sock"
26+
)
2927

3028
func generateMountOpts(resolvConf, hostsFile string) ([]oci.SpecOpts, error) {
3129
return []oci.SpecOpts{
@@ -128,3 +126,16 @@ func withDefaultProfile() oci.SpecOpts {
128126
return err
129127
}
130128
}
129+
130+
func getTracingSocketMount(socket string) specs.Mount {
131+
return specs.Mount{
132+
Destination: tracingSocketPath,
133+
Type: "bind",
134+
Source: socket,
135+
Options: []string{"ro", "rbind"},
136+
}
137+
}
138+
139+
func getTracingSocket() string {
140+
return fmt.Sprintf("unix://%s", tracingSocketPath)
141+
}

executor/oci/spec_windows.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
package oci
55

66
import (
7+
"fmt"
8+
"path/filepath"
9+
710
"github.com/containerd/containerd/oci"
811
"github.com/docker/docker/pkg/idtools"
912
"github.com/moby/buildkit/solver/pb"
13+
specs "github.com/opencontainers/runtime-spec/specs-go"
1014
"github.com/pkg/errors"
1115
)
1216

13-
var tracingEnvVars = []string{
14-
"OTEL_TRACES_EXPORTER=otlp",
15-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=npipe:////./pipe/otel-grpc",
16-
"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc",
17-
}
17+
const (
18+
tracingSocketPath = "//./pipe/otel-grpc"
19+
)
1820

1921
func generateMountOpts(resolvConf, hostsFile string) ([]oci.SpecOpts, error) {
2022
return nil, nil
@@ -49,3 +51,15 @@ func generateRlimitOpts(ulimits []*pb.Ulimit) ([]oci.SpecOpts, error) {
4951
}
5052
return nil, errors.New("no support for POSIXRlimit on Windows")
5153
}
54+
55+
func getTracingSocketMount(socket string) specs.Mount {
56+
return specs.Mount{
57+
Destination: filepath.FromSlash(tracingSocketPath),
58+
Source: socket,
59+
Options: []string{"ro"},
60+
}
61+
}
62+
63+
func getTracingSocket() string {
64+
return fmt.Sprintf("npipe://%s", filepath.ToSlash(tracingSocketPath))
65+
}

0 commit comments

Comments
 (0)