mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
kubelet stats: wire up podAndContainerStatsFromCRI feature gate
though it is currently unused Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
parent
cd85d4b3fb
commit
7866287ba1
@ -723,7 +723,8 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
|
||||
kubeDeps.RemoteRuntimeService,
|
||||
kubeDeps.RemoteImageService,
|
||||
hostStatsProvider,
|
||||
utilfeature.DefaultFeatureGate.Enabled(features.DisableAcceleratorUsageMetrics))
|
||||
utilfeature.DefaultFeatureGate.Enabled(features.DisableAcceleratorUsageMetrics),
|
||||
utilfeature.DefaultFeatureGate.Enabled(features.PodAndContainerStatsFromCRI))
|
||||
}
|
||||
|
||||
klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache, clock.RealClock{})
|
||||
|
@ -70,6 +70,7 @@ type criStatsProvider struct {
|
||||
cpuUsageCache map[string]*cpuUsageRecord
|
||||
mutex sync.RWMutex
|
||||
disableAcceleratorUsageMetrics bool
|
||||
podAndContainerStatsFromCRI bool
|
||||
}
|
||||
|
||||
// newCRIStatsProvider returns a containerStatsProvider implementation that
|
||||
@ -80,7 +81,8 @@ func newCRIStatsProvider(
|
||||
runtimeService internalapi.RuntimeService,
|
||||
imageService internalapi.ImageManagerService,
|
||||
hostStatsProvider HostStatsProvider,
|
||||
disableAcceleratorUsageMetrics bool,
|
||||
disableAcceleratorUsageMetrics,
|
||||
podAndContainerStatsFromCRI bool,
|
||||
) containerStatsProvider {
|
||||
return &criStatsProvider{
|
||||
cadvisor: cadvisor,
|
||||
@ -90,6 +92,7 @@ func newCRIStatsProvider(
|
||||
hostStatsProvider: hostStatsProvider,
|
||||
cpuUsageCache: make(map[string]*cpuUsageRecord),
|
||||
disableAcceleratorUsageMetrics: disableAcceleratorUsageMetrics,
|
||||
podAndContainerStatsFromCRI: podAndContainerStatsFromCRI,
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +140,10 @@ func (p *criStatsProvider) listPodStats(updateCPUNanoCoreUsage bool) ([]statsapi
|
||||
for _, s := range podSandboxes {
|
||||
podSandboxMap[s.Id] = s
|
||||
}
|
||||
|
||||
if p.podAndContainerStatsFromCRI {
|
||||
return p.listPodStatsStrictlyFromCRI(updateCPUNanoCoreUsage, containers, podSandboxes)
|
||||
}
|
||||
// fsIDtoInfo is a map from filesystem id to its stats. This will be used
|
||||
// as a cache to avoid querying cAdvisor for the filesystem stats with the
|
||||
// same filesystem id many times.
|
||||
@ -156,7 +163,6 @@ func (p *criStatsProvider) listPodStats(updateCPUNanoCoreUsage bool) ([]statsapi
|
||||
for _, c := range containers {
|
||||
containerMap[c.Id] = c
|
||||
}
|
||||
|
||||
allInfos, err := getCadvisorContainerInfo(p.cadvisor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch cadvisor stats: %v", err)
|
||||
@ -218,6 +224,10 @@ func (p *criStatsProvider) listPodStats(updateCPUNanoCoreUsage bool) ([]statsapi
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *criStatsProvider) listPodStatsStrictlyFromCRI(updateCPUNanoCoreUsage bool, containers []*runtimeapi.Container, podSandboxes []*runtimeapi.PodSandbox) ([]statsapi.PodStats, error) {
|
||||
return []statsapi.PodStats{}, nil
|
||||
}
|
||||
|
||||
// ListPodCPUAndMemoryStats returns the CPU and Memory stats of all the pod-managed containers.
|
||||
func (p *criStatsProvider) ListPodCPUAndMemoryStats() ([]statsapi.PodStats, error) {
|
||||
containers, err := p.runtimeService.ListContainers(&runtimeapi.ContainerFilter{})
|
||||
|
@ -236,6 +236,7 @@ func TestCRIListPodStats(t *testing.T) {
|
||||
fakeImageService,
|
||||
NewFakeHostStatsProviderWithData(fakeStats, fakeOS),
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
||||
stats, err := provider.ListPodStats()
|
||||
@ -396,6 +397,7 @@ func TestAcceleratorUsageStatsCanBeDisabled(t *testing.T) {
|
||||
fakeImageService,
|
||||
NewFakeHostStatsProvider(),
|
||||
true, // this is what the test is actually testing
|
||||
false,
|
||||
)
|
||||
|
||||
stats, err := provider.ListPodStats()
|
||||
@ -541,6 +543,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
|
||||
nil,
|
||||
NewFakeHostStatsProvider(),
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
||||
stats, err := provider.ListPodCPUAndMemoryStats()
|
||||
@ -671,6 +674,7 @@ func TestCRIImagesFsStats(t *testing.T) {
|
||||
fakeImageService,
|
||||
NewFakeHostStatsProvider(),
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
||||
stats, err := provider.ImageFsStats()
|
||||
|
@ -42,10 +42,10 @@ func NewCRIStatsProvider(
|
||||
runtimeService internalapi.RuntimeService,
|
||||
imageService internalapi.ImageManagerService,
|
||||
hostStatsProvider HostStatsProvider,
|
||||
disableAcceleratorUsageMetrics bool,
|
||||
disableAcceleratorUsageMetrics, podAndContainerStatsFromCRI bool,
|
||||
) *Provider {
|
||||
return newStatsProvider(cadvisor, podManager, runtimeCache, newCRIStatsProvider(cadvisor, resourceAnalyzer,
|
||||
runtimeService, imageService, hostStatsProvider, disableAcceleratorUsageMetrics))
|
||||
runtimeService, imageService, hostStatsProvider, disableAcceleratorUsageMetrics, podAndContainerStatsFromCRI))
|
||||
}
|
||||
|
||||
// NewCadvisorStatsProvider returns a containerStatsProvider that provides both
|
||||
|
Loading…
Reference in New Issue
Block a user