mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +00:00
shim: Add trace config option
Add a new `enable_tracing` option to `configuration.toml` to enable shim tracing. Fixes #934. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
0a7a4379dc
commit
ea74b981d9
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user