tracing: Remove trace mode and trace type

Remove the `trace_mode` and `trace_type` agent tracing options as
decided in the Architecture Committee meeting.

See:

- https://github.com/kata-containers/kata-containers/pull/2062

Fixes: #2352.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2021-07-29 14:14:57 +01:00
parent 119edcc443
commit 321be0f794
18 changed files with 145 additions and 438 deletions

View File

@ -34,8 +34,6 @@ There are several kinds of Kata configurations and they are listed below.
| `io.katacontainers.config.agent.enable_tracing` | `boolean` | enable tracing for the agent | | `io.katacontainers.config.agent.enable_tracing` | `boolean` | enable tracing for the agent |
| `io.katacontainers.config.agent.container_pipe_size` | uint32 | specify the size of the std(in/out) pipes created for containers | | `io.katacontainers.config.agent.container_pipe_size` | uint32 | specify the size of the std(in/out) pipes created for containers |
| `io.katacontainers.config.agent.kernel_modules` | string | the list of kernel modules and their parameters that will be loaded in the guest kernel. Semicolon separated list of kernel modules and their parameters. These modules will be loaded in the guest kernel using `modprobe`(8). E.g., `e1000e InterruptThrottleRate=3000,3000,3000 EEE=1; i915 enable_ppgtt=0` | | `io.katacontainers.config.agent.kernel_modules` | string | the list of kernel modules and their parameters that will be loaded in the guest kernel. Semicolon separated list of kernel modules and their parameters. These modules will be loaded in the guest kernel using `modprobe`(8). E.g., `e1000e InterruptThrottleRate=3000,3000,3000 EEE=1; i915 enable_ppgtt=0` |
| `io.katacontainers.config.agent.trace_mode` | string | the trace mode for the agent |
| `io.katacontainers.config.agent.trace_type` | string | the trace type for the agent |
## Hypervisor Options ## Hypervisor Options
| Key | Value Type | Comments | | Key | Value Type | Comments |

View File

@ -2,7 +2,6 @@
// //
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use crate::tracer;
use anyhow::{bail, ensure, Context, Result}; use anyhow::{bail, ensure, Context, Result};
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashSet; use std::collections::HashSet;
@ -33,7 +32,7 @@ const VSOCK_PORT: u16 = 1024;
// Environment variables used for development and testing // Environment variables used for development and testing
const SERVER_ADDR_ENV_VAR: &str = "KATA_AGENT_SERVER_ADDR"; const SERVER_ADDR_ENV_VAR: &str = "KATA_AGENT_SERVER_ADDR";
const LOG_LEVEL_ENV_VAR: &str = "KATA_AGENT_LOG_LEVEL"; const LOG_LEVEL_ENV_VAR: &str = "KATA_AGENT_LOG_LEVEL";
const TRACE_TYPE_ENV_VAR: &str = "KATA_AGENT_TRACE_TYPE"; const TRACING_ENV_VAR: &str = "KATA_AGENT_TRACING";
const ERR_INVALID_LOG_LEVEL: &str = "invalid log level"; const ERR_INVALID_LOG_LEVEL: &str = "invalid log level";
const ERR_INVALID_LOG_LEVEL_PARAM: &str = "invalid log level parameter"; const ERR_INVALID_LOG_LEVEL_PARAM: &str = "invalid log level parameter";
@ -73,7 +72,7 @@ pub struct AgentConfig {
pub container_pipe_size: i32, pub container_pipe_size: i32,
pub server_addr: String, pub server_addr: String,
pub unified_cgroup_hierarchy: bool, pub unified_cgroup_hierarchy: bool,
pub tracing: tracer::TraceType, pub tracing: bool,
pub endpoints: AgentEndpoints, pub endpoints: AgentEndpoints,
} }
@ -88,7 +87,7 @@ pub struct AgentConfigBuilder {
pub container_pipe_size: Option<i32>, pub container_pipe_size: Option<i32>,
pub server_addr: Option<String>, pub server_addr: Option<String>,
pub unified_cgroup_hierarchy: Option<bool>, pub unified_cgroup_hierarchy: Option<bool>,
pub tracing: Option<tracer::TraceType>, pub tracing: Option<bool>,
pub endpoints: Option<EndpointsConfig>, pub endpoints: Option<EndpointsConfig>,
} }
@ -148,7 +147,7 @@ impl Default for AgentConfig {
container_pipe_size: DEFAULT_CONTAINER_PIPE_SIZE, container_pipe_size: DEFAULT_CONTAINER_PIPE_SIZE,
server_addr: format!("{}:{}", VSOCK_ADDR, VSOCK_PORT), server_addr: format!("{}:{}", VSOCK_ADDR, VSOCK_PORT),
unified_cgroup_hierarchy: false, unified_cgroup_hierarchy: false,
tracing: tracer::TraceType::Disabled, tracing: false,
endpoints: Default::default(), endpoints: Default::default(),
} }
} }
@ -213,11 +212,11 @@ impl AgentConfig {
// Support "bare" tracing option for backwards compatibility with // Support "bare" tracing option for backwards compatibility with
// Kata 1.x. // Kata 1.x.
if param == &TRACE_MODE_OPTION { if param == &TRACE_MODE_OPTION {
config.tracing = tracer::TraceType::Isolated; config.tracing = true;
continue; continue;
} }
parse_cmdline_param!(param, TRACE_MODE_OPTION, config.tracing, get_trace_type); parse_cmdline_param!(param, TRACE_MODE_OPTION, config.tracing, get_bool_value);
// parse cmdline options // parse cmdline options
parse_cmdline_param!(param, LOG_LEVEL_OPTION, config.log_level, get_log_level); parse_cmdline_param!(param, LOG_LEVEL_OPTION, config.log_level, get_log_level);
@ -277,10 +276,10 @@ impl AgentConfig {
} }
} }
if let Ok(value) = env::var(TRACE_TYPE_ENV_VAR) { if let Ok(value) = env::var(TRACING_ENV_VAR) {
if let Ok(result) = value.parse::<tracer::TraceType>() { let name_value = format!("{}={}", TRACING_ENV_VAR, value);
config.tracing = result;
} config.tracing = get_bool_value(&name_value)?;
} }
// We did not get a configuration file: allow all endpoints. // We did not get a configuration file: allow all endpoints.
@ -343,25 +342,6 @@ fn get_log_level(param: &str) -> Result<slog::Level> {
logrus_to_slog_level(fields[1]) logrus_to_slog_level(fields[1])
} }
#[instrument]
fn get_trace_type(param: &str) -> Result<tracer::TraceType> {
ensure!(!param.is_empty(), "invalid trace type parameter");
let fields: Vec<&str> = param.split('=').collect();
ensure!(
fields[0] == TRACE_MODE_OPTION,
"invalid trace type key name"
);
if fields.len() == 1 {
return Ok(tracer::TraceType::Isolated);
}
let result = fields[1].parse::<tracer::TraceType>()?;
Ok(result)
}
#[instrument] #[instrument]
fn get_hotplug_timeout(param: &str) -> Result<time::Duration> { fn get_hotplug_timeout(param: &str) -> Result<time::Duration> {
let fields: Vec<&str> = param.split('=').collect(); let fields: Vec<&str> = param.split('=').collect();
@ -446,10 +426,6 @@ mod tests {
use std::time; use std::time;
use tempfile::tempdir; use tempfile::tempdir;
const ERR_INVALID_TRACE_TYPE_PARAM: &str = "invalid trace type parameter";
const ERR_INVALID_TRACE_TYPE: &str = "invalid trace type";
const ERR_INVALID_TRACE_TYPE_KEY: &str = "invalid trace type key name";
// Parameters: // Parameters:
// //
// 1: expected Result // 1: expected Result
@ -500,7 +476,7 @@ mod tests {
container_pipe_size: i32, container_pipe_size: i32,
server_addr: &'a str, server_addr: &'a str,
unified_cgroup_hierarchy: bool, unified_cgroup_hierarchy: bool,
tracing: tracer::TraceType, tracing: bool,
} }
impl Default for TestData<'_> { impl Default for TestData<'_> {
@ -515,7 +491,7 @@ mod tests {
container_pipe_size: DEFAULT_CONTAINER_PIPE_SIZE, container_pipe_size: DEFAULT_CONTAINER_PIPE_SIZE,
server_addr: TEST_SERVER_ADDR, server_addr: TEST_SERVER_ADDR,
unified_cgroup_hierarchy: false, unified_cgroup_hierarchy: false,
tracing: tracer::TraceType::Disabled, tracing: false,
} }
} }
} }
@ -774,49 +750,115 @@ mod tests {
}, },
TestData { TestData {
contents: "trace", contents: "trace",
tracing: tracer::TraceType::Disabled, tracing: false,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: ".trace", contents: ".trace",
tracing: tracer::TraceType::Disabled, tracing: false,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "agent.tracer", contents: "agent.tracer",
tracing: tracer::TraceType::Disabled, tracing: false,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "agent.trac", contents: "agent.trac",
tracing: tracer::TraceType::Disabled, tracing: false,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "agent.trace", contents: "agent.trace",
tracing: tracer::TraceType::Isolated, tracing: true,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "agent.trace=isolated", contents: "agent.trace=true",
tracing: tracer::TraceType::Isolated, tracing: true,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "agent.trace=disabled", contents: "agent.trace=false",
tracing: tracer::TraceType::Disabled, tracing: false,
..Default::default()
},
TestData {
contents: "agent.trace=0",
tracing: false,
..Default::default()
},
TestData {
contents: "agent.trace=1",
tracing: true,
..Default::default()
},
TestData {
contents: "agent.trace=a",
tracing: false,
..Default::default()
},
TestData {
contents: "agent.trace=foo",
tracing: false,
..Default::default()
},
TestData {
contents: "agent.trace=.",
tracing: false,
..Default::default()
},
TestData {
contents: "agent.trace=,",
tracing: false,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "", contents: "",
env_vars: vec!["KATA_AGENT_TRACE_TYPE=isolated"], env_vars: vec!["KATA_AGENT_TRACING="],
tracing: tracer::TraceType::Isolated, tracing: false,
..Default::default() ..Default::default()
}, },
TestData { TestData {
contents: "", contents: "",
env_vars: vec!["KATA_AGENT_TRACE_TYPE=disabled"], env_vars: vec!["KATA_AGENT_TRACING=''"],
tracing: tracer::TraceType::Disabled, tracing: false,
..Default::default()
},
TestData {
contents: "",
env_vars: vec!["KATA_AGENT_TRACING=0"],
tracing: false,
..Default::default()
},
TestData {
contents: "",
env_vars: vec!["KATA_AGENT_TRACING=."],
tracing: false,
..Default::default()
},
TestData {
contents: "",
env_vars: vec!["KATA_AGENT_TRACING=,"],
tracing: false,
..Default::default()
},
TestData {
contents: "",
env_vars: vec!["KATA_AGENT_TRACING=foo"],
tracing: false,
..Default::default()
},
TestData {
contents: "",
env_vars: vec!["KATA_AGENT_TRACING=1"],
tracing: true,
..Default::default()
},
TestData {
contents: "",
env_vars: vec!["KATA_AGENT_TRACING=true"],
tracing: true,
..Default::default() ..Default::default()
}, },
]; ];
@ -1302,64 +1344,6 @@ Caused by:
} }
} }
#[test]
fn test_get_trace_type() {
#[derive(Debug)]
struct TestData<'a> {
param: &'a str,
result: Result<tracer::TraceType>,
}
let tests = &[
TestData {
param: "",
result: Err(anyhow!(ERR_INVALID_TRACE_TYPE_PARAM)),
},
TestData {
param: "agent.tracer",
result: Err(anyhow!(ERR_INVALID_TRACE_TYPE_KEY)),
},
TestData {
param: "agent.trac",
result: Err(anyhow!(ERR_INVALID_TRACE_TYPE_KEY)),
},
TestData {
param: "agent.trace=",
result: Err(anyhow!(ERR_INVALID_TRACE_TYPE)),
},
TestData {
param: "agent.trace==",
result: Err(anyhow!(ERR_INVALID_TRACE_TYPE)),
},
TestData {
param: "agent.trace=foo",
result: Err(anyhow!(ERR_INVALID_TRACE_TYPE)),
},
TestData {
param: "agent.trace",
result: Ok(tracer::TraceType::Isolated),
},
TestData {
param: "agent.trace=isolated",
result: Ok(tracer::TraceType::Isolated),
},
TestData {
param: "agent.trace=disabled",
result: Ok(tracer::TraceType::Disabled),
},
];
for (i, d) in tests.iter().enumerate() {
let msg = format!("test[{}]: {:?}", i, d);
let result = get_trace_type(d.param);
let msg = format!("{}: result: {:?}", msg, result);
assert_result!(d.result, result, msg);
}
}
#[test] #[test]
fn test_config_builder_from_string() { fn test_config_builder_from_string() {
let config = AgentConfig::from_str( let config = AgentConfig::from_str(

View File

@ -196,8 +196,8 @@ async fn real_main() -> std::result::Result<(), Box<dyn std::error::Error>> {
ttrpc_log_guard = Ok(slog_stdlog::init().map_err(|e| e)?); ttrpc_log_guard = Ok(slog_stdlog::init().map_err(|e| e)?);
} }
if config.tracing != tracer::TraceType::Disabled { if config.tracing {
let _ = tracer::setup_tracing(NAME, &logger, &config)?; tracer::setup_tracing(NAME, &logger)?;
} }
let root_span = span!(tracing::Level::TRACE, "root-span"); let root_span = span!(tracing::Level::TRACE, "root-span");
@ -239,7 +239,7 @@ async fn real_main() -> std::result::Result<(), Box<dyn std::error::Error>> {
drop(span_guard); drop(span_guard);
drop(root_span); drop(root_span);
if config.tracing != tracer::TraceType::Disabled { if config.tracing {
tracer::end_tracing(); tracer::end_tracing();
} }

View File

@ -3,61 +3,17 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use crate::config::AgentConfig;
use anyhow::Result; use anyhow::Result;
use opentelemetry::sdk::propagation::TraceContextPropagator; use opentelemetry::sdk::propagation::TraceContextPropagator;
use opentelemetry::{global, sdk::trace::Config, trace::TracerProvider}; use opentelemetry::{global, sdk::trace::Config, trace::TracerProvider};
use serde::Deserialize;
use slog::{info, o, Logger}; use slog::{info, o, Logger};
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error;
use std::fmt;
use std::str::FromStr;
use tracing_opentelemetry::OpenTelemetryLayer; use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry; use tracing_subscriber::Registry;
use ttrpc::r#async::TtrpcContext; use ttrpc::r#async::TtrpcContext;
#[derive(Debug, Deserialize, PartialEq)] pub fn setup_tracing(name: &'static str, logger: &Logger) -> Result<()> {
pub enum TraceType {
Disabled,
Isolated,
}
#[derive(Debug)]
pub struct TraceTypeError {
details: String,
}
impl TraceTypeError {
fn new(msg: &str) -> TraceTypeError {
TraceTypeError {
details: msg.into(),
}
}
}
impl Error for TraceTypeError {}
impl fmt::Display for TraceTypeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.details)
}
}
impl FromStr for TraceType {
type Err = TraceTypeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"isolated" => Ok(TraceType::Isolated),
"disabled" => Ok(TraceType::Disabled),
_ => Err(TraceTypeError::new("invalid trace type")),
}
}
}
pub fn setup_tracing(name: &'static str, logger: &Logger, _agent_cfg: &AgentConfig) -> Result<()> {
let logger = logger.new(o!("subsystem" => "vsock-tracer")); let logger = logger.new(o!("subsystem" => "vsock-tracer"));
let exporter = vsock_exporter::Exporter::builder() let exporter = vsock_exporter::Exporter::builder()

View File

@ -117,8 +117,6 @@ type HypervisorInfo struct {
// AgentInfo stores agent details // AgentInfo stores agent details
type AgentInfo struct { type AgentInfo struct {
TraceMode string
TraceType string
Debug bool Debug bool
Trace bool Trace bool
} }
@ -157,11 +155,11 @@ type EnvInfo struct {
Meta MetaInfo Meta MetaInfo
Image ImageInfo Image ImageInfo
Initrd InitrdInfo Initrd InitrdInfo
Agent AgentInfo
Hypervisor HypervisorInfo Hypervisor HypervisorInfo
Netmon NetmonInfo
Runtime RuntimeInfo Runtime RuntimeInfo
Netmon NetmonInfo
Host HostInfo Host HostInfo
Agent AgentInfo
} }
func getMetaInfo() MetaInfo { func getMetaInfo() MetaInfo {
@ -303,8 +301,6 @@ func getAgentInfo(config oci.RuntimeConfig) (AgentInfo, error) {
agentConfig := config.AgentConfig agentConfig := config.AgentConfig
agent.Debug = agentConfig.Debug agent.Debug = agentConfig.Debug
agent.Trace = agentConfig.Trace agent.Trace = agentConfig.Trace
agent.TraceMode = agentConfig.TraceMode
agent.TraceType = agentConfig.TraceType
return agent, nil return agent, nil
} }

View File

@ -184,10 +184,6 @@ func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
return AgentInfo{ return AgentInfo{
Debug: agentConfig.Debug, Debug: agentConfig.Debug,
Trace: agentConfig.Trace, Trace: agentConfig.Trace,
// No trace mode/type set by default
TraceMode: "",
TraceType: "",
}, nil }, nil
} }
@ -677,14 +673,10 @@ func TestEnvGetAgentInfo(t *testing.T) {
assert.True(t, agent.Debug) assert.True(t, agent.Debug)
agentConfig.Trace = true agentConfig.Trace = true
agentConfig.TraceMode = "traceMode"
agentConfig.TraceType = "traceType"
config.AgentConfig = agentConfig config.AgentConfig = agentConfig
agent, err = getAgentInfo(config) agent, err = getAgentInfo(config)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, agent.Trace) assert.True(t, agent.Trace)
assert.Equal(t, agent.TraceMode, "traceMode")
assert.Equal(t, agent.TraceType, "traceType")
} }
func testEnvShowTOMLSettings(t *testing.T, tmpdir string, tmpfile *os.File) error { func testEnvShowTOMLSettings(t *testing.T, tmpdir string, tmpfile *os.File) error {

View File

@ -124,24 +124,17 @@ block_device_driver = "@DEFBLOCKSTORAGEDRIVER_ACRN@"
# Enable agent tracing. # Enable agent tracing.
# #
# If enabled, the default trace mode is "dynamic" and the # If enabled, the agent will generate OpenTelemetry trace spans.
# default trace type is "isolated". The trace mode and type are set
# explicity with the `trace_type=` and `trace_mode=` options.
# #
# Notes: # Notes:
# #
# - Tracing is ONLY enabled when `enable_tracing` is set: explicitly # - If the runtime also has tracing enabled, the agent spans will be
# setting `trace_mode=` and/or `trace_type=` without setting `enable_tracing` # associated with the appropriate runtime parent span.
# will NOT activate agent tracing. # - If enabled, the runtime will wait for the container to shutdown,
# # increasing the container shutdown time slightly.
# - See https://github.com/kata-containers/agent/blob/master/TRACING.md for
# full details.
# #
# (default: disabled) # (default: disabled)
#enable_tracing = true #enable_tracing = true
#
#trace_mode = "dynamic"
#trace_type = "isolated"
# Enable debug console. # Enable debug console.

View File

@ -144,24 +144,17 @@ block_device_driver = "virtio-blk"
# Enable agent tracing. # Enable agent tracing.
# #
# If enabled, the default trace mode is "dynamic" and the # If enabled, the agent will generate OpenTelemetry trace spans.
# default trace type is "isolated". The trace mode and type are set
# explicity with the `trace_type=` and `trace_mode=` options.
# #
# Notes: # Notes:
# #
# - Tracing is ONLY enabled when `enable_tracing` is set: explicitly # - If the runtime also has tracing enabled, the agent spans will be
# setting `trace_mode=` and/or `trace_type=` without setting `enable_tracing` # associated with the appropriate runtime parent span.
# will NOT activate agent tracing. # - If enabled, the runtime will wait for the container to shutdown,
# # increasing the container shutdown time slightly.
# - See https://github.com/kata-containers/agent/blob/master/TRACING.md for
# full details.
# #
# (default: disabled) # (default: disabled)
#enable_tracing = true #enable_tracing = true
#
#trace_mode = "dynamic"
#trace_type = "isolated"
# Enable debug console. # Enable debug console.

View File

@ -246,24 +246,17 @@ valid_entropy_sources = @DEFVALIDENTROPYSOURCES@
# Enable agent tracing. # Enable agent tracing.
# #
# If enabled, the default trace mode is "dynamic" and the # If enabled, the agent will generate OpenTelemetry trace spans.
# default trace type is "isolated". The trace mode and type are set
# explicity with the `trace_type=` and `trace_mode=` options.
# #
# Notes: # Notes:
# #
# - Tracing is ONLY enabled when `enable_tracing` is set: explicitly # - If the runtime also has tracing enabled, the agent spans will be
# setting `trace_mode=` and/or `trace_type=` without setting `enable_tracing` # associated with the appropriate runtime parent span.
# will NOT activate agent tracing. # - If enabled, the runtime will wait for the container to shutdown,
# # increasing the container shutdown time slightly.
# - See https://github.com/kata-containers/agent/blob/master/TRACING.md for
# full details.
# #
# (default: disabled) # (default: disabled)
#enable_tracing = true #enable_tracing = true
#
#trace_mode = "dynamic"
#trace_type = "isolated"
# Comma separated list of kernel modules and their parameters. # Comma separated list of kernel modules and their parameters.
# These modules will be loaded in the guest kernel using modprobe(8). # These modules will be loaded in the guest kernel using modprobe(8).

View File

@ -422,24 +422,17 @@ valid_entropy_sources = @DEFVALIDENTROPYSOURCES@
# Enable agent tracing. # Enable agent tracing.
# #
# If enabled, the default trace mode is "dynamic" and the # If enabled, the agent will generate OpenTelemetry trace spans.
# default trace type is "isolated". The trace mode and type are set
# explicity with the `trace_type=` and `trace_mode=` options.
# #
# Notes: # Notes:
# #
# - Tracing is ONLY enabled when `enable_tracing` is set: explicitly # - If the runtime also has tracing enabled, the agent spans will be
# setting `trace_mode=` and/or `trace_type=` without setting `enable_tracing` # associated with the appropriate runtime parent span.
# will NOT activate agent tracing. # - If enabled, the runtime will wait for the container to shutdown,
# # increasing the container shutdown time slightly.
# - See https://github.com/kata-containers/agent/blob/master/TRACING.md for
# full details.
# #
# (default: disabled) # (default: disabled)
#enable_tracing = true #enable_tracing = true
#
#trace_mode = "dynamic"
#trace_type = "isolated"
# Comma separated list of kernel modules and their parameters. # Comma separated list of kernel modules and their parameters.
# These modules will be loaded in the guest kernel using modprobe(8). # These modules will be loaded in the guest kernel using modprobe(8).

View File

@ -23,8 +23,6 @@ type RuntimeConfigOptions struct {
NetmonPath string NetmonPath string
LogPath string LogPath string
BlockDeviceDriver string BlockDeviceDriver string
AgentTraceMode string
AgentTraceType string
SharedFS string SharedFS string
VirtioFSDaemon string VirtioFSDaemon string
JaegerEndpoint string JaegerEndpoint string
@ -137,8 +135,6 @@ func MakeRuntimeConfigFileData(config RuntimeConfigOptions) string {
[agent.kata] [agent.kata]
enable_debug = ` + strconv.FormatBool(config.AgentDebug) + ` enable_debug = ` + strconv.FormatBool(config.AgentDebug) + `
enable_tracing = ` + strconv.FormatBool(config.AgentTrace) + ` enable_tracing = ` + strconv.FormatBool(config.AgentTrace) + `
trace_mode = "` + config.AgentTraceMode + `"` + `
trace_type = "` + config.AgentTraceType + `"` + `
[netmon] [netmon]
path = "` + config.NetmonPath + `" path = "` + config.NetmonPath + `"

View File

@ -153,8 +153,6 @@ type runtime struct {
} }
type agent struct { type agent struct {
TraceMode string `toml:"trace_mode"`
TraceType string `toml:"trace_type"`
KernelModules []string `toml:"kernel_modules"` KernelModules []string `toml:"kernel_modules"`
Debug bool `toml:"enable_debug"` Debug bool `toml:"enable_debug"`
Tracing bool `toml:"enable_tracing"` Tracing bool `toml:"enable_tracing"`
@ -489,14 +487,6 @@ func (a agent) trace() bool {
return a.Tracing return a.Tracing
} }
func (a agent) traceMode() string {
return a.TraceMode
}
func (a agent) traceType() string {
return a.TraceType
}
func (a agent) kernelModules() []string { func (a agent) kernelModules() []string {
return a.KernelModules return a.KernelModules
} }
@ -929,8 +919,6 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc
LongLiveConn: true, LongLiveConn: true,
Debug: agent.debug(), Debug: agent.debug(),
Trace: agent.trace(), Trace: agent.trace(),
TraceMode: agent.traceMode(),
TraceType: agent.traceType(),
KernelModules: agent.kernelModules(), KernelModules: agent.kernelModules(),
EnableDebugConsole: agent.debugConsoleEnabled(), EnableDebugConsole: agent.debugConsoleEnabled(),
DialTimeout: agent.dialTimout(), DialTimeout: agent.dialTimout(),
@ -976,10 +964,6 @@ func SetKernelParams(runtimeConfig *oci.RuntimeConfig) error {
} }
// next, check for agent specific kernel params // next, check for agent specific kernel params
err := vc.KataAgentSetDefaultTraceConfigOptions(&runtimeConfig.AgentConfig)
if err != nil {
return err
}
params := vc.KataAgentKernelParams(runtimeConfig.AgentConfig) params := vc.KataAgentKernelParams(runtimeConfig.AgentConfig)

View File

@ -1152,9 +1152,6 @@ func TestAgentDefaults(t *testing.T) {
a.Tracing = true a.Tracing = true
assert.Equal(a.trace(), a.Tracing) assert.Equal(a.trace(), a.Tracing)
assert.Equal(a.traceMode(), a.TraceMode)
assert.Equal(a.traceType(), a.TraceType)
} }
func TestGetDefaultConfigFilePaths(t *testing.T) { func TestGetDefaultConfigFilePaths(t *testing.T) {

View File

@ -105,16 +105,6 @@ var (
GuestDNSFile = "/etc/resolv.conf" GuestDNSFile = "/etc/resolv.conf"
) )
const (
agentTraceModeDynamic = "dynamic"
agentTraceModeStatic = "static"
agentTraceTypeIsolated = "isolated"
agentTraceTypeCollated = "collated"
defaultAgentTraceMode = agentTraceModeDynamic
defaultAgentTraceType = agentTraceTypeIsolated
)
const ( const (
grpcCheckRequest = "grpc.CheckRequest" grpcCheckRequest = "grpc.CheckRequest"
grpcExecProcessRequest = "grpc.ExecProcessRequest" grpcExecProcessRequest = "grpc.ExecProcessRequest"
@ -221,8 +211,6 @@ func ephemeralPath() string {
// KataAgentConfig is a structure storing information needed // KataAgentConfig is a structure storing information needed
// to reach the Kata Containers agent. // to reach the Kata Containers agent.
type KataAgentConfig struct { type KataAgentConfig struct {
TraceMode string
TraceType string
KernelModules []string KernelModules []string
ContainerPipeSize uint32 ContainerPipeSize uint32
DialTimeout uint32 DialTimeout uint32
@ -268,34 +256,6 @@ func (k *kataAgent) longLiveConn() bool {
return k.keepConn return k.keepConn
} }
// KataAgentSetDefaultTraceConfigOptions validates agent trace options and
// sets defaults.
func KataAgentSetDefaultTraceConfigOptions(config *KataAgentConfig) error {
if !config.Trace {
return nil
}
switch config.TraceMode {
case agentTraceModeDynamic:
case agentTraceModeStatic:
case "":
config.TraceMode = defaultAgentTraceMode
default:
return fmt.Errorf("invalid kata agent trace mode: %q (need %q or %q)", config.TraceMode, agentTraceModeDynamic, agentTraceModeStatic)
}
switch config.TraceType {
case agentTraceTypeIsolated:
case agentTraceTypeCollated:
case "":
config.TraceType = defaultAgentTraceType
default:
return fmt.Errorf("invalid kata agent trace type: %q (need %q or %q)", config.TraceType, agentTraceTypeIsolated, agentTraceTypeCollated)
}
return nil
}
// KataAgentKernelParams returns a list of Kata Agent specific kernel // KataAgentKernelParams returns a list of Kata Agent specific kernel
// parameters. // parameters.
func KataAgentKernelParams(config KataAgentConfig) []Param { func KataAgentKernelParams(config KataAgentConfig) []Param {
@ -305,8 +265,8 @@ func KataAgentKernelParams(config KataAgentConfig) []Param {
params = append(params, Param{Key: "agent.log", Value: "debug"}) params = append(params, Param{Key: "agent.log", Value: "debug"})
} }
if config.Trace && config.TraceMode == agentTraceModeStatic { if config.Trace {
params = append(params, Param{Key: "agent.trace", Value: config.TraceType}) params = append(params, Param{Key: "agent.trace", Value: "true"})
} }
if config.ContainerPipeSize > 0 { if config.ContainerPipeSize > 0 {
@ -323,17 +283,14 @@ func KataAgentKernelParams(config KataAgentConfig) []Param {
} }
func (k *kataAgent) handleTraceSettings(config KataAgentConfig) bool { func (k *kataAgent) handleTraceSettings(config KataAgentConfig) bool {
if !config.Trace {
return false
}
disableVMShutdown := false disableVMShutdown := false
switch config.TraceMode { if config.Trace {
case agentTraceModeStatic: // Agent tracing requires that the agent be able to shutdown
// cleanly. This is the only scenario where the agent is
// responsible for stopping the VM: normally this is handled
// by the runtime.
disableVMShutdown = true disableVMShutdown = true
case agentTraceModeDynamic:
k.dynamicTracing = true
} }
return disableVMShutdown return disableVMShutdown

View File

@ -997,75 +997,43 @@ func TestKataAgentKernelParams(t *testing.T) {
debug bool debug bool
trace bool trace bool
containerPipeSize uint32 containerPipeSize uint32
traceMode string
traceType string
expectedParams []Param expectedParams []Param
} }
debugParam := Param{Key: "agent.log", Value: "debug"} debugParam := Param{Key: "agent.log", Value: "debug"}
traceParam := Param{Key: "agent.trace", Value: "true"}
traceIsolatedParam := Param{Key: "agent.trace", Value: "isolated"}
traceCollatedParam := Param{Key: "agent.trace", Value: "collated"}
traceFooParam := Param{Key: "agent.trace", Value: "foo"}
containerPipeSizeParam := Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: "2097152"} containerPipeSizeParam := Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: "2097152"}
data := []testData{ data := []testData{
{false, false, 0, "", "", []Param{}}, {false, false, 0, []Param{}},
{true, false, 0, "", "", []Param{debugParam}},
{false, false, 0, "foo", "", []Param{}}, // Debug
{false, false, 0, "foo", "", []Param{}}, {true, false, 0, []Param{debugParam}},
{false, false, 0, "", "foo", []Param{}},
{false, false, 0, "", "foo", []Param{}},
{false, false, 0, "foo", "foo", []Param{}},
{false, true, 0, "foo", "foo", []Param{}},
{false, false, 0, agentTraceModeDynamic, "", []Param{}}, // Tracing
{false, false, 0, agentTraceModeStatic, "", []Param{}}, {false, true, 0, []Param{traceParam}},
{false, false, 0, "", agentTraceTypeIsolated, []Param{}},
{false, false, 0, "", agentTraceTypeCollated, []Param{}},
{false, false, 0, "foo", agentTraceTypeIsolated, []Param{}},
{false, false, 0, "foo", agentTraceTypeCollated, []Param{}},
{false, false, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}}, // Debug + Tracing
{false, false, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}}, {true, true, 0, []Param{debugParam, traceParam}},
{false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}}, // pipesize
{false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}}, {false, false, 2097152, []Param{containerPipeSizeParam}},
{false, true, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}}, // Debug + pipesize
{false, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}}, {true, false, 2097152, []Param{debugParam, containerPipeSizeParam}},
{true, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{debugParam}},
{false, true, 0, "", agentTraceTypeIsolated, []Param{}}, // Tracing + pipesize
{false, true, 0, "", agentTraceTypeCollated, []Param{}}, {false, true, 2097152, []Param{traceParam, containerPipeSizeParam}},
{true, true, 0, "", agentTraceTypeIsolated, []Param{debugParam}},
{true, true, 0, "", agentTraceTypeCollated, []Param{debugParam}},
{false, true, 0, "foo", agentTraceTypeIsolated, []Param{}},
{false, true, 0, "foo", agentTraceTypeCollated, []Param{}},
{true, true, 0, "foo", agentTraceTypeIsolated, []Param{debugParam}},
{true, true, 0, "foo", agentTraceTypeCollated, []Param{debugParam}},
{false, true, 0, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam}}, // Debug + Tracing + pipesize
{false, true, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam}}, {true, true, 2097152, []Param{debugParam, traceParam, containerPipeSizeParam}},
{true, true, 0, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam, debugParam}},
{true, true, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam, debugParam}},
{false, true, 0, agentTraceModeStatic, "foo", []Param{traceFooParam}},
{true, true, 0, agentTraceModeStatic, "foo", []Param{debugParam, traceFooParam}},
{false, false, 0, "", "", []Param{}},
{false, false, 2097152, "", "", []Param{containerPipeSizeParam}},
} }
for i, d := range data { for i, d := range data {
config := KataAgentConfig{ config := KataAgentConfig{
Debug: d.debug, Debug: d.debug,
Trace: d.trace, Trace: d.trace,
TraceMode: d.traceMode,
TraceType: d.traceType,
ContainerPipeSize: d.containerPipeSize, ContainerPipeSize: d.containerPipeSize,
} }
@ -1090,17 +1058,13 @@ func TestKataAgentHandleTraceSettings(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
type testData struct { type testData struct {
traceMode string
trace bool trace bool
expectDisableVMShutdown bool expectDisableVMShutdown bool
expectDynamicTracing bool
} }
data := []testData{ data := []testData{
{"", false, false, false}, {false, false},
{"", true, false, false}, {true, true},
{agentTraceModeStatic, true, true, false},
{agentTraceModeDynamic, true, false, true},
} }
for i, d := range data { for i, d := range data {
@ -1108,7 +1072,6 @@ func TestKataAgentHandleTraceSettings(t *testing.T) {
config := KataAgentConfig{ config := KataAgentConfig{
Trace: d.trace, Trace: d.trace,
TraceMode: d.traceMode,
} }
disableVMShutdown := k.handleTraceSettings(config) disableVMShutdown := k.handleTraceSettings(config)
@ -1118,78 +1081,6 @@ func TestKataAgentHandleTraceSettings(t *testing.T) {
} else { } else {
assert.Falsef(disableVMShutdown, "test %d (%+v)", i, d) assert.Falsef(disableVMShutdown, "test %d (%+v)", i, d)
} }
if d.expectDynamicTracing {
assert.Truef(k.dynamicTracing, "test %d (%+v)", i, d)
} else {
assert.Falsef(k.dynamicTracing, "test %d (%+v)", i, d)
}
}
}
func TestKataAgentSetDefaultTraceConfigOptions(t *testing.T) {
assert := assert.New(t)
type testData struct {
traceMode string
traceType string
trace bool
expectDefaultTraceMode bool
expectDefaultTraceType bool
expectError bool
}
data := []testData{
{"", "", false, false, false, false},
{agentTraceModeDynamic, agentTraceTypeCollated, false, false, false, false},
{agentTraceModeDynamic, agentTraceTypeIsolated, false, false, false, false},
{agentTraceModeStatic, agentTraceTypeCollated, false, false, false, false},
{agentTraceModeStatic, agentTraceTypeIsolated, false, false, false, false},
{agentTraceModeDynamic, agentTraceTypeCollated, true, false, false, false},
{agentTraceModeDynamic, agentTraceTypeIsolated, true, false, false, false},
{agentTraceModeStatic, agentTraceTypeCollated, true, false, false, false},
{agentTraceModeStatic, agentTraceTypeIsolated, true, false, false, false},
{agentTraceModeDynamic, "", true, false, true, false},
{agentTraceModeDynamic, "invalid", true, false, false, true},
{agentTraceModeStatic, "", true, false, true, false},
{agentTraceModeStatic, "invalid", true, false, false, true},
{"", agentTraceTypeIsolated, true, true, false, false},
{"invalid", agentTraceTypeIsolated, true, false, false, true},
{"", agentTraceTypeCollated, true, true, false, false},
{"invalid", agentTraceTypeCollated, true, false, false, true},
{"", "", true, true, true, false},
{"invalid", "invalid", true, false, false, true},
}
for i, d := range data {
config := &KataAgentConfig{
Trace: d.trace,
TraceMode: d.traceMode,
TraceType: d.traceType,
}
err := KataAgentSetDefaultTraceConfigOptions(config)
if d.expectError {
assert.Error(err, "test %d (%+v)", i, d)
continue
} else {
assert.NoError(err, "test %d (%+v)", i, d)
}
if d.expectDefaultTraceMode {
assert.Equalf(config.TraceMode, defaultAgentTraceMode, "test %d (%+v)", i, d)
}
if d.expectDefaultTraceType {
assert.Equalf(config.TraceType, defaultAgentTraceType, "test %d (%+v)", i, d)
}
} }
} }

View File

@ -272,12 +272,6 @@ const (
// AgentTrace is a sandbox annotation to enable tracing for the agent. // AgentTrace is a sandbox annotation to enable tracing for the agent.
AgentTrace = kataAnnotAgentPrefix + "enable_tracing" AgentTrace = kataAnnotAgentPrefix + "enable_tracing"
// AgentTraceMode is a sandbox annotation to specify the trace mode for the agent.
AgentTraceMode = kataAnnotAgentPrefix + "trace_mode"
// AgentTraceMode is a sandbox annotation to specify the trace type for the agent.
AgentTraceType = kataAnnotAgentPrefix + "trace_type"
// AgentContainerPipeSize is an annotation to specify the size of the pipes created for containers // AgentContainerPipeSize is an annotation to specify the size of the pipes created for containers
AgentContainerPipeSize = kataAnnotAgentPrefix + ContainerPipeSizeOption AgentContainerPipeSize = kataAnnotAgentPrefix + ContainerPipeSizeOption
ContainerPipeSizeOption = "container_pipe_size" ContainerPipeSizeOption = "container_pipe_size"

View File

@ -844,14 +844,6 @@ func addAgentConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig) error
return err return err
} }
if value, ok := ocispec.Annotations[vcAnnotations.AgentTraceMode]; ok {
c.TraceMode = value
}
if value, ok := ocispec.Annotations[vcAnnotations.AgentTraceType]; ok {
c.TraceType = value
}
if err := newAnnotationConfiguration(ocispec, vcAnnotations.AgentContainerPipeSize).setUint(func(containerPipeSize uint64) { if err := newAnnotationConfiguration(ocispec, vcAnnotations.AgentContainerPipeSize).setUint(func(containerPipeSize uint64) {
c.ContainerPipeSize = uint32(containerPipeSize) c.ContainerPipeSize = uint32(containerPipeSize)
}); err != nil { }); err != nil {

View File

@ -122,8 +122,6 @@ func TestVMConfigGrpc(t *testing.T) {
Trace: false, Trace: false,
EnableDebugConsole: false, EnableDebugConsole: false,
ContainerPipeSize: 0, ContainerPipeSize: 0,
TraceMode: "",
TraceType: "",
KernelModules: []string{}}, KernelModules: []string{}},
} }