Skip to content

Commit

Permalink
agent: Support Kata agent tracing
Browse files Browse the repository at this point in the history
Add configuration options to support the various Kata agent tracing
modes and types. See the comments in the configuration files for
details:

- `cli/config/configuration-fc.toml`
- `cli/config/configuration-qemu.toml`

Fixes kata-containers#1369.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Mar 28, 2019
1 parent 952afd8 commit 8573c8d
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 40 deletions.
21 changes: 21 additions & 0 deletions cli/config/configuration-fc.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ path = "@SHIMPATH@"
# (default: disabled)
#enable_debug = true

# Enable agent tracing.
#
# If enabled, the default trace mode is "dynamic" and the
# default trace type is "isolated". The trace mode and type are set
# explicity with the `trace_type=` and `trace_mode=` options.
#
# Notes:
#
# - Tracing is ONLY enabled when `enable_tracing` is set: explicitly
# setting `trace_mode=` and/or `trace_type=` without setting `enable_tracing`
# will NOT activate agent tracing.
#
# - See https://github.com/kata-containers/agent/blob/master/TRACING.md for
# full details.
#
# (default: disabled)
#enable_tracing = true
#
#trace_mode = "dynamic"
#trace_type = "isolated"

[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional
Expand Down
21 changes: 21 additions & 0 deletions cli/config/configuration-qemu.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ path = "@SHIMPATH@"
# (default: disabled)
#enable_debug = true

# Enable agent tracing.
#
# If enabled, the default trace mode is "dynamic" and the
# default trace type is "isolated". The trace mode and type are set
# explicity with the `trace_type=` and `trace_mode=` options.
#
# Notes:
#
# - Tracing is ONLY enabled when `enable_tracing` is set: explicitly
# setting `trace_mode=` and/or `trace_type=` without setting `enable_tracing`
# will NOT activate agent tracing.
#
# - See https://github.com/kata-containers/agent/blob/master/TRACING.md for
# full details.
#
# (default: disabled)
#enable_tracing = true
#
#trace_mode = "dynamic"
#trace_type = "isolated"

[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional
Expand Down
12 changes: 9 additions & 3 deletions cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.22"
const formatVersion = "1.0.23"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand Down Expand Up @@ -112,8 +112,11 @@ type ShimInfo struct {

// AgentInfo stores agent details
type AgentInfo struct {
Type string
Debug bool
Type string
Debug bool
Trace bool
TraceMode string
TraceType string
}

// DistroInfo stores host operating system distribution details.
Expand Down Expand Up @@ -321,6 +324,9 @@ func getAgentInfo(config oci.RuntimeConfig) (AgentInfo, error) {
return AgentInfo{}, errors.New("cannot determine Kata agent config")
}
agent.Debug = agentConfig.Debug
agent.Trace = agentConfig.Trace
agent.TraceMode = agentConfig.TraceMode
agent.TraceType = agentConfig.TraceType
default:
// Nothing useful to report for the other agent types
}
Expand Down
18 changes: 18 additions & 0 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
shimDebug = false
netmonDebug = false
agentDebug = false
agentTrace = false
)

// makeVersionBinary creates a shell script with the specified file
Expand Down Expand Up @@ -155,6 +156,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
ShimDebug: shimDebug,
NetmonDebug: netmonDebug,
AgentDebug: agentDebug,
AgentTrace: agentTrace,
}

runtimeConfig := katatestutils.MakeRuntimeConfigFileData(configFileOptions)
Expand Down Expand Up @@ -217,6 +219,11 @@ func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
return AgentInfo{
Type: string(config.AgentType),
Debug: agentConfig.Debug,
Trace: agentConfig.Trace,

// No trace mode/type set by default
TraceMode: "",
TraceType: "",
}, nil
}

Expand Down Expand Up @@ -496,6 +503,7 @@ func TestEnvGetEnvInfo(t *testing.T) {
runtimeTrace = toggle
shimDebug = toggle
agentDebug = toggle
agentTrace = toggle

configFile, config, err := makeRuntimeConfig(tmpdir)
assert.NoError(t, err)
Expand Down Expand Up @@ -823,6 +831,16 @@ func TestEnvGetAgentInfo(t *testing.T) {
assert.NoError(t, err)
assert.True(t, agent.Debug)

agentConfig.Trace = true
agentConfig.TraceMode = "traceMode"
agentConfig.TraceType = "traceType"
config.AgentConfig = agentConfig
agent, err = getAgentInfo(config)
assert.NoError(t, err)
assert.True(t, agent.Trace)
assert.Equal(t, agent.TraceMode, "traceMode")
assert.Equal(t, agent.TraceType, "traceType")

config.AgentConfig = "I am the wrong type"
_, err = getAgentInfo(config)
assert.Error(t, err)
Expand Down
29 changes: 26 additions & 3 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ type shim struct {
}

type agent struct {
Debug bool `toml:"enable_debug"`
Debug bool `toml:"enable_debug"`
Tracing bool `toml:"enable_tracing"`
TraceMode string `toml:"trace_mode"`
TraceType string `toml:"trace_type"`
}

type netmon struct {
Expand Down Expand Up @@ -395,6 +398,18 @@ func (a agent) debug() bool {
return a.Debug
}

func (a agent) trace() bool {
return a.Tracing
}

func (a agent) traceMode() string {
return a.TraceMode
}

func (a agent) traceType() string {
return a.TraceType
}

func (n netmon) enable() bool {
return n.Enable
}
Expand Down Expand Up @@ -655,8 +670,11 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc
case kataAgentTableType:
config.AgentType = vc.KataContainersAgent
config.AgentConfig = vc.KataAgentConfig{
UseVSock: config.HypervisorConfig.UseVSock,
Debug: agent.debug(),
UseVSock: config.HypervisorConfig.UseVSock,
Debug: agent.debug(),
Trace: agent.trace(),
TraceMode: agent.traceMode(),
TraceType: agent.traceType(),
}
}
}
Expand Down Expand Up @@ -717,6 +735,11 @@ func SetKernelParams(runtimeConfig *oci.RuntimeConfig) error {

// next, check for agent specific kernel params
if agentConfig, ok := runtimeConfig.AgentConfig.(vc.KataAgentConfig); ok {
err := vc.KataAgentSetDefaultTraceConfigOptions(&agentConfig)
if err != nil {
return err
}

params := vc.KataAgentKernelParams(agentConfig)

for _, p := range params {
Expand Down
10 changes: 10 additions & 0 deletions pkg/katautils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
shimDebug = false
netmonDebug = false
agentDebug = false
agentTrace = false
)

type testRuntimeConfig struct {
Expand Down Expand Up @@ -111,6 +112,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
ShimDebug: shimDebug,
NetmonDebug: netmonDebug,
AgentDebug: agentDebug,
AgentTrace: agentTrace,
}

runtimeConfigFileData := katatestutils.MakeRuntimeConfigFileData(configFileOptions)
Expand Down Expand Up @@ -1206,6 +1208,14 @@ func TestAgentDefaults(t *testing.T) {

a.Debug = true
assert.Equal(a.debug(), a.Debug)

assert.Equal(a.trace(), a.Tracing)

a.Tracing = true
assert.Equal(a.trace(), a.Tracing)

assert.Equal(a.traceMode(), a.TraceMode)
assert.Equal(a.traceType(), a.TraceType)
}

func TestGetDefaultConfigFilePaths(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type agent interface {
// init().
// After init() is called, agent implementations should be initialized and ready
// to handle all other Agent interface methods.
init(ctx context.Context, sandbox *Sandbox, config interface{}) error
init(ctx context.Context, sandbox *Sandbox, config interface{}) (disableVMShutdown bool, err error)

// capabilities should return a structure that specifies the capabilities
// supported by the agent.
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func fsMapFromDevices(c *Container) ([]*hyperstart.FsmapDescriptor, error) {
}

// init is the agent initialization implementation for hyperstart.
func (h *hyper) init(ctx context.Context, sandbox *Sandbox, config interface{}) (err error) {
func (h *hyper) init(ctx context.Context, sandbox *Sandbox, config interface{}) (disableVMShutdown bool, err error) {
// save
h.ctx = ctx

Expand All @@ -276,25 +276,25 @@ func (h *hyper) init(ctx context.Context, sandbox *Sandbox, config interface{})

h.sandbox = sandbox
default:
return errInvalidConfigType
return false, errInvalidConfigType
}

h.proxy, err = newProxy(sandbox.config.ProxyType)
if err != nil {
return err
return false, err
}

h.shim, err = newShim(sandbox.config.ShimType)
if err != nil {
return err
return false, err
}

// Fetch agent runtime info.
if err := sandbox.store.Load(store.Agent, &h.state); err != nil {
h.Logger().Debug("Could not retrieve anything from storage")
}

return nil
return false, nil
}

func (h *hyper) getVMPath(id string) string {
Expand Down
Loading

0 comments on commit 8573c8d

Please sign in to comment.