Skip to content

Commit

Permalink
agent: Display trace details
Browse files Browse the repository at this point in the history
Log the trace mode and type when tracing is enabled. The change makes it
clearer that static tracing is enabled when the agent parsers the kernel
command line (`config.go`) and dynamic tracing is enabled by gRPC (`grpc.go`).

Specifics of change:

- Rename variables to match the terms defined in `TRACING.md`.
- Pass trace mode and trace type arguments to `enableTracing()`.
- Change the tense of the message displayed by `enableTracing()` so that
  the message indicates that tracing *is* enabled, not *about to be*.

Fixes kata-containers#504.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Apr 16, 2019
1 parent 7720b93 commit 2ada1d1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
40 changes: 23 additions & 17 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import (
)

const (
optionPrefix = "agent."
logLevelFlag = optionPrefix + "log"
devModeFlag = optionPrefix + "devmode"
traceModeFlag = optionPrefix + "trace"
useVsockFlag = optionPrefix + "use_vsock"
kernelCmdlineFile = "/proc/cmdline"
traceValueIsolated = "isolated"
traceValueCollated = "collated"
optionPrefix = "agent."
logLevelFlag = optionPrefix + "log"
devModeFlag = optionPrefix + "devmode"
traceModeFlag = optionPrefix + "trace"
useVsockFlag = optionPrefix + "use_vsock"
kernelCmdlineFile = "/proc/cmdline"
traceModeStatic = "static"
traceModeDynamic = "dynamic"
traceTypeIsolated = "isolated"
traceTypeCollated = "collated"
defaultTraceType = traceTypeIsolated
)

type agentConfig struct {
Expand Down Expand Up @@ -77,7 +80,7 @@ func (c *agentConfig) parseCmdlineOption(option string) error {
}

if option == traceModeFlag {
enableTracing(false)
enableTracing(traceModeStatic, defaultTraceType)
return nil
}

Expand All @@ -99,10 +102,10 @@ func (c *agentConfig) parseCmdlineOption(option string) error {
}
case traceModeFlag:
switch split[valuePosition] {
case traceValueIsolated:
enableTracing(false)
case traceValueCollated:
enableTracing(true)
case traceTypeIsolated:
enableTracing(traceModeStatic, traceTypeIsolated)
case traceTypeCollated:
enableTracing(traceModeStatic, traceTypeCollated)
}
case useVsockFlag:
flag, err := strconv.ParseBool(split[valuePosition])
Expand All @@ -126,13 +129,16 @@ func (c *agentConfig) parseCmdlineOption(option string) error {

}

func enableTracing(enableCollatedTrace bool) {
agentLog.Info("enabling tracing")

func enableTracing(traceMode, traceType string) {
tracing = true

// Enable in case this generates more trace spans
debug = true

collatedTrace = enableCollatedTrace
collatedTrace = traceType == traceTypeCollated

agentLog.WithFields(logrus.Fields{
"trace-mode": traceMode,
"trace-type": traceType,
}).Info("enabled tracing")
}
23 changes: 14 additions & 9 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ func TestParseCmdlineOptionTracing(t *testing.T) {
{traceModeFlag + "=", false, false},

{traceModeFlag, true, false},
{traceModeFlag + "=" + traceValueIsolated, true, false},
{traceModeFlag + "=" + traceValueCollated, true, true},
{traceModeFlag + "=" + traceTypeIsolated, true, false},
{traceModeFlag + "=" + traceTypeCollated, true, true},

{traceModeFlag + "=" + traceValueIsolated + "x", false, false},
{traceModeFlag + "=" + traceValueCollated + "x", false, false},
{traceModeFlag + "=" + traceTypeIsolated + "x", false, false},
{traceModeFlag + "=" + traceTypeCollated + "x", false, false},
}

for i, d := range data {
Expand Down Expand Up @@ -259,12 +259,17 @@ func TestEnableTracing(t *testing.T) {
assert := assert.New(t)

type testData struct {
collatedTrace bool
traceMode string
traceType string
expectCollatedTrace bool
}

data := []testData{
{false},
{true},
{traceModeStatic, traceTypeIsolated, false},
{traceModeStatic, traceTypeCollated, true},

{traceModeDynamic, traceTypeIsolated, false},
{traceModeDynamic, traceTypeCollated, true},
}

for i, d := range data {
Expand All @@ -273,12 +278,12 @@ func TestEnableTracing(t *testing.T) {
collatedTrace = false
debug = false

enableTracing(d.collatedTrace)
enableTracing(d.traceMode, d.traceType)

assert.True(debug, "test %d (%+v)", i, d)
assert.True(tracing, "test %d (%+v)", i, d)

if d.collatedTrace {
if d.expectCollatedTrace {
assert.True(collatedTrace, "test %d (%+v)", i, d)
} else {
assert.False(collatedTrace, "test %d (%+v)", i, d)
Expand Down
3 changes: 2 additions & 1 deletion grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,8 @@ func (a *agentGRPC) StartTracing(ctx context.Context, req *pb.StartTracingReques
return nil, grpcStatus.Error(codes.FailedPrecondition, "tracing already enabled")
}

enableTracing(false)
// The only trace type support for dynamic tracing is isolated.
enableTracing(traceModeDynamic, traceTypeIsolated)
startTracingCalled = true

var err error
Expand Down

0 comments on commit 2ada1d1

Please sign in to comment.