mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
kubelet stats: use UsageNanoCores if available
Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
parent
ffdb4b9c4a
commit
85e8a4bf73
@ -678,12 +678,18 @@ func (p *criStatsProvider) makeContainerCPUAndMemoryStats(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// getContainerUsageNanoCores gets the cached usageNanoCores.
|
// getContainerUsageNanoCores first attempts to get the usage nano cores from the stats reported
|
||||||
|
// by the CRI. If it is unable to, it gets the information from the cache instead.
|
||||||
func (p *criStatsProvider) getContainerUsageNanoCores(stats *runtimeapi.ContainerStats) *uint64 {
|
func (p *criStatsProvider) getContainerUsageNanoCores(stats *runtimeapi.ContainerStats) *uint64 {
|
||||||
if stats == nil || stats.Attributes == nil {
|
if stats == nil || stats.Attributes == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bypass the cache if the CRI implementation specified the UsageNanoCores.
|
||||||
|
if stats.Cpu.UsageNanoCores != nil {
|
||||||
|
return &stats.Cpu.UsageNanoCores.Value
|
||||||
|
}
|
||||||
|
|
||||||
p.mutex.RLock()
|
p.mutex.RLock()
|
||||||
defer p.mutex.RUnlock()
|
defer p.mutex.RUnlock()
|
||||||
|
|
||||||
@ -696,11 +702,19 @@ func (p *criStatsProvider) getContainerUsageNanoCores(stats *runtimeapi.Containe
|
|||||||
return &latestUsage
|
return &latestUsage
|
||||||
}
|
}
|
||||||
|
|
||||||
// getContainerUsageNanoCores computes usageNanoCores based on the given and
|
// getAndUpdateContainerUsageNanoCores first attempts to get the usage nano cores from the stats reported
|
||||||
// the cached usageCoreNanoSeconds, updates the cache with the computed
|
// by the CRI. If it is unable to, it computes usageNanoCores based on the given and the cached usageCoreNanoSeconds,
|
||||||
// usageNanoCores, and returns the usageNanoCores.
|
// updates the cache with the computed usageNanoCores, and returns the usageNanoCores.
|
||||||
func (p *criStatsProvider) getAndUpdateContainerUsageNanoCores(stats *runtimeapi.ContainerStats) *uint64 {
|
func (p *criStatsProvider) getAndUpdateContainerUsageNanoCores(stats *runtimeapi.ContainerStats) *uint64 {
|
||||||
if stats == nil || stats.Attributes == nil || stats.Cpu == nil || stats.Cpu.UsageCoreNanoSeconds == nil {
|
if stats == nil || stats.Attributes == nil || stats.Cpu == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Bypass the cache if the CRI implementation specified the UsageNanoCores.
|
||||||
|
if stats.Cpu.UsageNanoCores != nil {
|
||||||
|
return &stats.Cpu.UsageNanoCores.Value
|
||||||
|
}
|
||||||
|
// If there is no UsageNanoCores, nor UsageCoreNanoSeconds, there is no information to use
|
||||||
|
if stats.Cpu.UsageCoreNanoSeconds == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
id := stats.Attributes.Id
|
id := stats.Attributes.Id
|
||||||
|
Loading…
Reference in New Issue
Block a user