Skip to content

Commit 79cb4b0

Browse files
committed
[sbserver] handle missing cpu stats
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 464a497 commit 79cb4b0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/cri/sbserver/container_stats_list.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ func (c *criService) toCRIContainerStats(
6464
return nil, fmt.Errorf("failed to decode container metrics for %q: %w", cntr.ID, err)
6565
}
6666

67-
// this is a calculated value and should be computed for all OSes
68-
nanoUsage, err := c.getUsageNanoCores(cntr.Metadata.ID, false, cs.Cpu.UsageCoreNanoSeconds.Value, time.Unix(0, cs.Cpu.Timestamp))
69-
if err != nil {
70-
return nil, fmt.Errorf("failed to get usage nano cores, containerID: %s: %w", cntr.Metadata.ID, err)
67+
if cs.Cpu != nil && cs.Cpu.UsageCoreNanoSeconds != nil {
68+
// this is a calculated value and should be computed for all OSes
69+
nanoUsage, err := c.getUsageNanoCores(cntr.Metadata.ID, false, cs.Cpu.UsageCoreNanoSeconds.Value, time.Unix(0, cs.Cpu.Timestamp))
70+
if err != nil {
71+
return nil, fmt.Errorf("failed to get usage nano cores, containerID: %s: %w", cntr.Metadata.ID, err)
72+
}
73+
cs.Cpu.UsageNanoCores = &runtime.UInt64Value{Value: nanoUsage}
7174
}
72-
cs.Cpu.UsageNanoCores = &runtime.UInt64Value{Value: nanoUsage}
7375

7476
containerStats.Stats = append(containerStats.Stats, cs)
7577
}

0 commit comments

Comments
 (0)