Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
shim: Add trace config option
Browse files Browse the repository at this point in the history
Add a new `enable_tracing` option to `configuration.toml` to enable
shim tracing.

Fixes #934.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Dec 5, 2018
1 parent 0a7a437 commit ea74b98
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -459,6 +464,7 @@ func newShimConfig(s shim) (vc.ShimConfig, error) {
return vc.ShimConfig{
Path: path,
Debug: s.debug(),
Trace: s.trace(),
}, nil
}

Expand Down Expand Up @@ -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
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/katautils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
4 changes: 4 additions & 0 deletions virtcontainers/kata_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions virtcontainers/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ea74b98

Please sign in to comment.