runtime: make dialing timeout configurable

allow to set dialing timeout in configuration.toml
default is 30s

Fixes: #1789
Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
This commit is contained in:
Snir Sheriber 2021-05-02 14:33:29 +03:00
parent 12a04cb0ba
commit 01b56d6cbf
7 changed files with 35 additions and 4 deletions

View File

@ -150,6 +150,10 @@ block_device_driver = "@DEFBLOCKSTORAGEDRIVER_ACRN@"
#debug_console_enabled = true
# Agent connection dialing timeout value in seconds
# (default: 30)
#dial_timeout = 30
[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional

View File

@ -165,6 +165,10 @@ block_device_driver = "virtio-blk"
#debug_console_enabled = true
# Agent connection dialing timeout value in seconds
# (default: 30)
#dial_timeout = 30
[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional

View File

@ -287,6 +287,10 @@ kernel_modules=[]
#debug_console_enabled = true
# Agent connection dialing timeout value in seconds
# (default: 30)
#dial_timeout = 30
[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional

View File

@ -437,6 +437,10 @@ kernel_modules=[]
#debug_console_enabled = true
# Agent connection dialing timeout value in seconds
# (default: 30)
#dial_timeout = 30
[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional

View File

@ -154,6 +154,7 @@ type agent struct {
Debug bool `toml:"enable_debug"`
Tracing bool `toml:"enable_tracing"`
DebugConsoleEnabled bool `toml:"debug_console_enabled"`
DialTimeout uint32 `toml:"dial_timeout"`
}
type netmon struct {
@ -471,6 +472,10 @@ func (a agent) debugConsoleEnabled() bool {
return a.DebugConsoleEnabled
}
func (a agent) dialTimout() uint32 {
return a.DialTimeout
}
func (a agent) debug() bool {
return a.Debug
}
@ -920,6 +925,7 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc
TraceType: agent.traceType(),
KernelModules: agent.kernelModules(),
EnableDebugConsole: agent.debugConsoleEnabled(),
DialTimeout: agent.dialTimout(),
}
}

View File

@ -217,6 +217,7 @@ type KataAgentConfig struct {
ContainerPipeSize uint32
TraceMode string
TraceType string
DialTimeout uint32
KernelModules []string
}
@ -236,6 +237,7 @@ type kataAgent struct {
keepConn bool
dynamicTracing bool
dead bool
dialTimout uint32
kmodules []string
vmSocket interface{}
@ -344,6 +346,7 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config KataAgent
disableVMShutdown = k.handleTraceSettings(config)
k.keepConn = config.LongLiveConn
k.kmodules = config.KernelModules
k.dialTimout = config.DialTimeout
return disableVMShutdown, nil
}
@ -1794,7 +1797,7 @@ func (k *kataAgent) connect(ctx context.Context) error {
}
k.Logger().WithField("url", k.state.URL).Info("New client")
client, err := kataclient.NewAgentClient(k.ctx, k.state.URL)
client, err := kataclient.NewAgentClient(k.ctx, k.state.URL, k.dialTimout)
if err != nil {
k.dead = true
return err

View File

@ -62,15 +62,21 @@ type dialer func(string, time.Duration) (net.Conn, error)
// model, and mediates communication between AF_UNIX sockets (on the host end)
// and AF_VSOCK sockets (on the guest end).
// - mock://<path>. just for test use.
func NewAgentClient(ctx context.Context, sock string) (*AgentClient, error) {
func NewAgentClient(ctx context.Context, sock string, timeout uint32) (*AgentClient, error) {
grpcAddr, parsedAddr, err := parse(sock)
if err != nil {
return nil, err
}
dialTimeout := defaultDialTimeout
if timeout > 0 {
dialTimeout = time.Duration(timeout) * time.Second
agentClientLog.WithField("timeout", timeout).Debug("custom dialing timeout has been set")
}
var conn net.Conn
var d = agentDialer(parsedAddr)
conn, err = d(grpcAddr, defaultDialTimeout)
conn, err = d(grpcAddr, dialTimeout)
if err != nil {
return nil, err
}
@ -92,7 +98,7 @@ func NewAgentClient(ctx context.Context, sock string) (*AgentClient, error) {
grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(tracer)))
}
ctx, cancel := context.WithTimeout(ctx, defaultDialTimeout)
ctx, cancel := context.WithTimeout(ctx, dialTimeout)
defer cancel()
conn, err := grpc.DialContext(ctx, grpcAddr, dialOpts...)
if err != nil {