diff --git a/cli/config/configuration.toml.in b/cli/config/configuration.toml.in index 89ea3e560..4cba78c11 100644 --- a/cli/config/configuration.toml.in +++ b/cli/config/configuration.toml.in @@ -212,6 +212,17 @@ path = "@SHIMPATH@" # (default: disabled) #enable_debug = true +# If enabled, the shim will create opentracing.io traces and spans. +# (See https://www.jaegertracing.io/docs/getting-started). +# +# Note: By default, the shim runs in a separate network namespace. Therefore, +# to allow it to send trace details to the Jaeger agent running on the host, +# it is necessary to set 'disable_new_netns=true' so that it runs in the host +# network namespace. +# +# (default: disabled) +#enable_tracing = true + [agent.@PROJECT_TYPE@] # There is no field for this section. The goal is only to be able to # specify which type of agent the user wants to use. diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index b1703bbe8..f7b8b8aaf 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -121,8 +121,9 @@ type runtime struct { } type shim struct { - Path string `toml:"path"` - Debug bool `toml:"enable_debug"` + Path string `toml:"path"` + Debug bool `toml:"enable_debug"` + Tracing bool `toml:"enable_tracing"` } type agent struct { @@ -344,6 +345,10 @@ func (s shim) debug() bool { return s.Debug } +func (s shim) trace() bool { + return s.Tracing +} + func (n netmon) enable() bool { return n.Enable } @@ -459,6 +464,7 @@ func newShimConfig(s shim) (vc.ShimConfig, error) { return vc.ShimConfig{ Path: path, Debug: s.debug(), + Trace: s.trace(), }, nil } @@ -710,7 +716,13 @@ func checkNetNsConfig(config oci.RuntimeConfig) error { if config.InterNetworkModel != vc.NetXConnectNoneModel { return fmt.Errorf("config disable_new_netns only works with 'none' internetworking_model") } + } else if config.ShimConfig.(vc.ShimConfig).Trace { + // Normally, the shim runs in a separate network namespace. + // But when tracing, the shim process needs to be able to talk + // to the Jaeger agent running in the host network namespace. + return errors.New("Shim tracing requires disable_new_netns for Jaeger agent communication") } + return nil } diff --git a/pkg/katautils/config_test.go b/pkg/katautils/config_test.go index 2192509e9..a54dbb220 100644 --- a/pkg/katautils/config_test.go +++ b/pkg/katautils/config_test.go @@ -1148,6 +1148,10 @@ func TestShimDefaults(t *testing.T) { assert.False(s.debug()) s.Debug = true assert.True(s.debug()) + + assert.False(s.trace()) + s.Tracing = true + assert.True(s.trace()) } func TestGetDefaultConfigFilePaths(t *testing.T) { @@ -1538,3 +1542,41 @@ func TestCheckFactoryConfig(t *testing.T) { } } } + +func TestCheckNetNsConfigShimTrace(t *testing.T) { + assert := assert.New(t) + + type testData struct { + disableNetNs bool + networkModel vc.NetInterworkingModel + shimTrace bool + expectError bool + } + + data := []testData{ + {false, vc.NetXConnectMacVtapModel, false, false}, + {false, vc.NetXConnectMacVtapModel, true, true}, + {true, vc.NetXConnectMacVtapModel, true, true}, + {true, vc.NetXConnectMacVtapModel, false, true}, + {true, vc.NetXConnectNoneModel, false, false}, + {true, vc.NetXConnectNoneModel, true, false}, + } + + for i, d := range data { + config := oci.RuntimeConfig{ + DisableNewNetNs: d.disableNetNs, + InterNetworkModel: d.networkModel, + ShimConfig: vc.ShimConfig{ + Trace: d.shimTrace, + }, + } + + err := checkNetNsConfig(config) + + if d.expectError { + assert.Error(err, "test %d (%+v)", i, d) + } else { + assert.NoError(err, "test %d (%+v)", i, d) + } + } +} diff --git a/virtcontainers/kata_shim.go b/virtcontainers/kata_shim.go index 077327161..cb1cd8e2d 100644 --- a/virtcontainers/kata_shim.go +++ b/virtcontainers/kata_shim.go @@ -57,5 +57,9 @@ func (s *kataShim) start(sandbox *Sandbox, params ShimParams) (int, error) { args = append(args, "-log", "debug") } + if config.Trace { + args = append(args, "-trace") + } + return startShim(args, params) } diff --git a/virtcontainers/shim.go b/virtcontainers/shim.go index b82357f64..8d74c7f62 100644 --- a/virtcontainers/shim.go +++ b/virtcontainers/shim.go @@ -56,6 +56,7 @@ type ShimParams struct { type ShimConfig struct { Path string Debug bool + Trace bool } // Set sets a shim type based on the input string.