Skip to content

Commit aecddc9

Browse files
committed
kubelet: add remote_runtime tracing at log level 10
1 parent 52243de commit aecddc9

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

pkg/kubelet/remote/remote_runtime.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
7171

7272
// Version returns the runtime name, runtime version and runtime API version.
7373
func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
74+
klog.V(10).Infof("[RemoteRuntimeService] Version (apiVersion=%v, timeout=%v)", apiVersion, r.timeout)
75+
7476
ctx, cancel := getContextWithTimeout(r.timeout)
7577
defer cancel()
7678

@@ -82,6 +84,8 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
8284
return nil, err
8385
}
8486

87+
klog.V(10).Infof("[RemoteRuntimeService] Version Response (typedVersion=%v)", typedVersion)
88+
8589
if typedVersion.Version == "" || typedVersion.RuntimeName == "" || typedVersion.RuntimeApiVersion == "" || typedVersion.RuntimeVersion == "" {
8690
return nil, fmt.Errorf("not all fields are set in VersionResponse (%q)", *typedVersion)
8791
}
@@ -94,7 +98,11 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
9498
func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
9599
// Use 2 times longer timeout for sandbox operation (4 mins by default)
96100
// TODO: Make the pod sandbox timeout configurable.
97-
ctx, cancel := getContextWithTimeout(r.timeout * 2)
101+
timeout := r.timeout * 2
102+
103+
klog.V(10).Infof("[RemoteRuntimeService] RunPodSandbox (config=%v, runtimeHandler=%v, timeout=%v)", config, runtimeHandler, timeout)
104+
105+
ctx, cancel := getContextWithTimeout(timeout)
98106
defer cancel()
99107

100108
resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
@@ -112,12 +120,16 @@ func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
112120
return "", errors.New(errorMessage)
113121
}
114122

123+
klog.V(10).Infof("[RemoteRuntimeService] RunPodSandbox Response (PodSandboxId=%v)", resp.PodSandboxId)
124+
115125
return resp.PodSandboxId, nil
116126
}
117127

118128
// StopPodSandbox stops the sandbox. If there are any running containers in the
119129
// sandbox, they should be forced to termination.
120130
func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
131+
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
132+
121133
ctx, cancel := getContextWithTimeout(r.timeout)
122134
defer cancel()
123135

@@ -129,12 +141,15 @@ func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
129141
return err
130142
}
131143

144+
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox Response (podSandboxID=%v)", podSandBoxID)
145+
132146
return nil
133147
}
134148

135149
// RemovePodSandbox removes the sandbox. If there are any containers in the
136150
// sandbox, they should be forcibly removed.
137151
func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
152+
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
138153
ctx, cancel := getContextWithTimeout(r.timeout)
139154
defer cancel()
140155

@@ -146,11 +161,14 @@ func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
146161
return err
147162
}
148163

164+
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox Response (podSandboxID=%v)", podSandBoxID)
165+
149166
return nil
150167
}
151168

152169
// PodSandboxStatus returns the status of the PodSandbox.
153170
func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
171+
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
154172
ctx, cancel := getContextWithTimeout(r.timeout)
155173
defer cancel()
156174

@@ -161,6 +179,8 @@ func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
161179
return nil, err
162180
}
163181

182+
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus Response (podSandboxID=%v, status=%v)", podSandBoxID, resp.Status)
183+
164184
if resp.Status != nil {
165185
if err := verifySandboxStatus(resp.Status); err != nil {
166186
return nil, err
@@ -172,6 +192,7 @@ func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
172192

173193
// ListPodSandbox returns a list of PodSandboxes.
174194
func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
195+
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox (filter=%v, timeout=%v)", filter, r.timeout)
175196
ctx, cancel := getContextWithTimeout(r.timeout)
176197
defer cancel()
177198

@@ -183,11 +204,14 @@ func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilte
183204
return nil, err
184205
}
185206

207+
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox Response (filter=%v, items=%v)", filter, resp.Items)
208+
186209
return resp.Items, nil
187210
}
188211

189212
// CreateContainer creates a new container in the specified PodSandbox.
190213
func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
214+
klog.V(10).Infof("[RemoteRuntimeService] CreateContainer (podSandBoxID=%v, timeout=%v)", podSandBoxID, r.timeout)
191215
ctx, cancel := getContextWithTimeout(r.timeout)
192216
defer cancel()
193217

@@ -201,6 +225,7 @@ func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
201225
return "", err
202226
}
203227

228+
klog.V(10).Infof("[RemoteRuntimeService] CreateContainer (podSandBoxID=%v, ContainerId=%v)", podSandBoxID, resp.ContainerId)
204229
if resp.ContainerId == "" {
205230
errorMessage := fmt.Sprintf("ContainerId is not set for container %q", config.GetMetadata())
206231
klog.Errorf("CreateContainer failed: %s", errorMessage)
@@ -212,6 +237,7 @@ func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
212237

213238
// StartContainer starts the container.
214239
func (r *RemoteRuntimeService) StartContainer(containerID string) error {
240+
klog.V(10).Infof("[RemoteRuntimeService] StartContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
215241
ctx, cancel := getContextWithTimeout(r.timeout)
216242
defer cancel()
217243

@@ -222,12 +248,14 @@ func (r *RemoteRuntimeService) StartContainer(containerID string) error {
222248
klog.Errorf("StartContainer %q from runtime service failed: %v", containerID, err)
223249
return err
224250
}
251+
klog.V(10).Infof("[RemoteRuntimeService] StartContainer Response (containerID=%v)", containerID)
225252

226253
return nil
227254
}
228255

229256
// StopContainer stops a running container with a grace period (i.e., timeout).
230257
func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64) error {
258+
klog.V(10).Infof("[RemoteRuntimeService] StopContainer (containerID=%v, timeout=%v)", containerID, timeout)
231259
// Use timeout + default timeout (2 minutes) as timeout to leave extra time
232260
// for SIGKILL container and request latency.
233261
t := r.timeout + time.Duration(timeout)*time.Second
@@ -243,13 +271,15 @@ func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64)
243271
klog.Errorf("StopContainer %q from runtime service failed: %v", containerID, err)
244272
return err
245273
}
274+
klog.V(10).Infof("[RemoteRuntimeService] StopContainer Response (containerID=%v)", containerID)
246275

247276
return nil
248277
}
249278

250279
// RemoveContainer removes the container. If the container is running, the container
251280
// should be forced to removal.
252281
func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
282+
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
253283
ctx, cancel := getContextWithTimeout(r.timeout)
254284
defer cancel()
255285

@@ -261,12 +291,14 @@ func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
261291
klog.Errorf("RemoveContainer %q from runtime service failed: %v", containerID, err)
262292
return err
263293
}
294+
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer Response (containerID=%v)", containerID)
264295

265296
return nil
266297
}
267298

268299
// ListContainers lists containers by filters.
269300
func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
301+
klog.V(10).Infof("[RemoteRuntimeService] ListContainers (filter=%v, timeout=%v)", filter, r.timeout)
270302
ctx, cancel := getContextWithTimeout(r.timeout)
271303
defer cancel()
272304

@@ -277,12 +309,14 @@ func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter
277309
klog.Errorf("ListContainers with filter %+v from runtime service failed: %v", filter, err)
278310
return nil, err
279311
}
312+
klog.V(10).Infof("[RemoteRuntimeService] ListContainers Response (filter=%v, containers=%v)", filter, resp.Containers)
280313

281314
return resp.Containers, nil
282315
}
283316

284317
// ContainerStatus returns the container status.
285318
func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
319+
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus (containerID=%v, timeout=%v)", containerID, r.timeout)
286320
ctx, cancel := getContextWithTimeout(r.timeout)
287321
defer cancel()
288322

@@ -297,6 +331,7 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
297331
return nil, err
298332
}
299333
r.logReduction.ClearID(containerID)
334+
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus Response (containerID=%v, status=%v)", containerID, resp.Status)
300335

301336
if resp.Status != nil {
302337
if err := verifyContainerStatus(resp.Status); err != nil {
@@ -310,6 +345,7 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
310345

311346
// UpdateContainerResources updates a containers resource config
312347
func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
348+
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources (containerID=%v, timeout=%v)", containerID, r.timeout)
313349
ctx, cancel := getContextWithTimeout(r.timeout)
314350
defer cancel()
315351

@@ -321,13 +357,15 @@ func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, reso
321357
klog.Errorf("UpdateContainerResources %q from runtime service failed: %v", containerID, err)
322358
return err
323359
}
360+
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources Response (containerID=%v)", containerID)
324361

325362
return nil
326363
}
327364

328365
// ExecSync executes a command in the container, and returns the stdout output.
329366
// If command exits with a non-zero exit code, an error is returned.
330367
func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
368+
klog.V(10).Infof("[RemoteRuntimeService] ExecSync (containerID=%v, timeout=%v)", containerID, timeout)
331369
// Do not set timeout when timeout is 0.
332370
var ctx context.Context
333371
var cancel context.CancelFunc
@@ -352,6 +390,7 @@ func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
352390
return nil, nil, err
353391
}
354392

393+
klog.V(10).Infof("[RemoteRuntimeService] ExecSync Response (containerID=%v, ExitCode=%v)", containerID, resp.ExitCode)
355394
err = nil
356395
if resp.ExitCode != 0 {
357396
err = utilexec.CodeExitError{
@@ -365,6 +404,7 @@ func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
365404

366405
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
367406
func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
407+
klog.V(10).Infof("[RemoteRuntimeService] Exec (timeout=%v)", r.timeout)
368408
ctx, cancel := getContextWithTimeout(r.timeout)
369409
defer cancel()
370410

@@ -373,6 +413,7 @@ func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
373413
klog.Errorf("Exec %s '%s' from runtime service failed: %v", req.ContainerId, strings.Join(req.Cmd, " "), err)
374414
return nil, err
375415
}
416+
klog.V(10).Info("[RemoteRuntimeService] Exec Response")
376417

377418
if resp.Url == "" {
378419
errorMessage := "URL is not set"
@@ -385,6 +426,7 @@ func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
385426

386427
// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
387428
func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
429+
klog.V(10).Infof("[RemoteRuntimeService] Attach (containerId=%v, timeout=%v)", req.ContainerId, r.timeout)
388430
ctx, cancel := getContextWithTimeout(r.timeout)
389431
defer cancel()
390432

@@ -393,6 +435,7 @@ func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
393435
klog.Errorf("Attach %s from runtime service failed: %v", req.ContainerId, err)
394436
return nil, err
395437
}
438+
klog.V(10).Infof("[RemoteRuntimeService] Attach Response (containerId=%v)", req.ContainerId)
396439

397440
if resp.Url == "" {
398441
errorMessage := "URL is not set"
@@ -404,6 +447,7 @@ func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
404447

405448
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
406449
func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
450+
klog.V(10).Infof("[RemoteRuntimeService] PortForward (podSandboxID=%v, port=%v, timeout=%v)", req.PodSandboxId, req.Port, r.timeout)
407451
ctx, cancel := getContextWithTimeout(r.timeout)
408452
defer cancel()
409453

@@ -412,6 +456,7 @@ func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
412456
klog.Errorf("PortForward %s from runtime service failed: %v", req.PodSandboxId, err)
413457
return nil, err
414458
}
459+
klog.V(10).Infof("[RemoteRuntimeService] PortForward Response (podSandboxID=%v)", req.PodSandboxId)
415460

416461
if resp.Url == "" {
417462
errorMessage := "URL is not set"
@@ -426,6 +471,7 @@ func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
426471
// update payload currently supported is the pod CIDR assigned to a node,
427472
// and the runtime service just proxies it down to the network plugin.
428473
func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error {
474+
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig (runtimeConfig=%v, timeout=%v)", runtimeConfig, r.timeout)
429475
ctx, cancel := getContextWithTimeout(r.timeout)
430476
defer cancel()
431477

@@ -439,12 +485,14 @@ func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.Run
439485
if err != nil {
440486
return err
441487
}
488+
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig Response (runtimeConfig=%v)", runtimeConfig)
442489

443490
return nil
444491
}
445492

446493
// Status returns the status of the runtime.
447494
func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
495+
klog.V(10).Infof("[RemoteRuntimeService] Status (timeout=%v)", r.timeout)
448496
ctx, cancel := getContextWithTimeout(r.timeout)
449497
defer cancel()
450498

@@ -454,6 +502,8 @@ func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
454502
return nil, err
455503
}
456504

505+
klog.V(10).Infof("[RemoteRuntimeService] Status Response (status=%v)", resp.Status)
506+
457507
if resp.Status == nil || len(resp.Status.Conditions) < 2 {
458508
errorMessage := "RuntimeReady or NetworkReady condition are not set"
459509
klog.Errorf("Status failed: %s", errorMessage)
@@ -465,6 +515,7 @@ func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
465515

466516
// ContainerStats returns the stats of the container.
467517
func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
518+
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)
468519
ctx, cancel := getContextWithTimeout(r.timeout)
469520
defer cancel()
470521

@@ -478,11 +529,13 @@ func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
478529
return nil, err
479530
}
480531
r.logReduction.ClearID(containerID)
532+
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats Response (containerID=%v, stats=%v)", containerID, resp.GetStats())
481533

482534
return resp.GetStats(), nil
483535
}
484536

485537
func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
538+
klog.V(10).Infof("[RemoteRuntimeService] ListContainerStats (filter=%v)", filter)
486539
// Do not set timeout, because writable layer stats collection takes time.
487540
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
488541
ctx, cancel := getContextWithCancel()
@@ -495,11 +548,13 @@ func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt
495548
klog.Errorf("ListContainerStats with filter %+v from runtime service failed: %v", filter, err)
496549
return nil, err
497550
}
551+
klog.V(10).Infof("[RemoteRuntimeService] ListContainerStats Response (filter=%v, stats=%v)", filter, resp.GetStats())
498552

499553
return resp.GetStats(), nil
500554
}
501555

502556
func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error {
557+
klog.V(10).Infof("[RemoteRuntimeService] ReopenContainerLog (containerID=%v, timeout=%v)", containerID, r.timeout)
503558
ctx, cancel := getContextWithTimeout(r.timeout)
504559
defer cancel()
505560

@@ -508,5 +563,7 @@ func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error {
508563
klog.Errorf("ReopenContainerLog %q from runtime service failed: %v", containerID, err)
509564
return err
510565
}
566+
567+
klog.V(10).Infof("[RemoteRuntimeService] ReopenContainerLog Response (containerID=%v)", containerID)
511568
return nil
512569
}

0 commit comments

Comments
 (0)