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:
Peter Hunt 2021-06-10 15:28:06 -04:00
parent cd85d4b3fb
commit 7866287ba1
4 changed files with 20 additions and 5 deletions

View File

@ -723,7 +723,8 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
kubeDeps.RemoteRuntimeService, kubeDeps.RemoteRuntimeService,
kubeDeps.RemoteImageService, kubeDeps.RemoteImageService,
hostStatsProvider, 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{}) klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache, clock.RealClock{})

View File

@ -70,6 +70,7 @@ type criStatsProvider struct {
cpuUsageCache map[string]*cpuUsageRecord cpuUsageCache map[string]*cpuUsageRecord
mutex sync.RWMutex mutex sync.RWMutex
disableAcceleratorUsageMetrics bool disableAcceleratorUsageMetrics bool
podAndContainerStatsFromCRI bool
} }
// newCRIStatsProvider returns a containerStatsProvider implementation that // newCRIStatsProvider returns a containerStatsProvider implementation that
@ -80,7 +81,8 @@ func newCRIStatsProvider(
runtimeService internalapi.RuntimeService, runtimeService internalapi.RuntimeService,
imageService internalapi.ImageManagerService, imageService internalapi.ImageManagerService,
hostStatsProvider HostStatsProvider, hostStatsProvider HostStatsProvider,
disableAcceleratorUsageMetrics bool, disableAcceleratorUsageMetrics,
podAndContainerStatsFromCRI bool,
) containerStatsProvider { ) containerStatsProvider {
return &criStatsProvider{ return &criStatsProvider{
cadvisor: cadvisor, cadvisor: cadvisor,
@ -90,6 +92,7 @@ func newCRIStatsProvider(
hostStatsProvider: hostStatsProvider, hostStatsProvider: hostStatsProvider,
cpuUsageCache: make(map[string]*cpuUsageRecord), cpuUsageCache: make(map[string]*cpuUsageRecord),
disableAcceleratorUsageMetrics: disableAcceleratorUsageMetrics, disableAcceleratorUsageMetrics: disableAcceleratorUsageMetrics,
podAndContainerStatsFromCRI: podAndContainerStatsFromCRI,
} }
} }
@ -137,6 +140,10 @@ func (p *criStatsProvider) listPodStats(updateCPUNanoCoreUsage bool) ([]statsapi
for _, s := range podSandboxes { for _, s := range podSandboxes {
podSandboxMap[s.Id] = s 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 // 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 // as a cache to avoid querying cAdvisor for the filesystem stats with the
// same filesystem id many times. // same filesystem id many times.
@ -156,7 +163,6 @@ func (p *criStatsProvider) listPodStats(updateCPUNanoCoreUsage bool) ([]statsapi
for _, c := range containers { for _, c := range containers {
containerMap[c.Id] = c containerMap[c.Id] = c
} }
allInfos, err := getCadvisorContainerInfo(p.cadvisor) allInfos, err := getCadvisorContainerInfo(p.cadvisor)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to fetch cadvisor stats: %v", err) 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 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. // ListPodCPUAndMemoryStats returns the CPU and Memory stats of all the pod-managed containers.
func (p *criStatsProvider) ListPodCPUAndMemoryStats() ([]statsapi.PodStats, error) { func (p *criStatsProvider) ListPodCPUAndMemoryStats() ([]statsapi.PodStats, error) {
containers, err := p.runtimeService.ListContainers(&runtimeapi.ContainerFilter{}) containers, err := p.runtimeService.ListContainers(&runtimeapi.ContainerFilter{})

View File

@ -236,6 +236,7 @@ func TestCRIListPodStats(t *testing.T) {
fakeImageService, fakeImageService,
NewFakeHostStatsProviderWithData(fakeStats, fakeOS), NewFakeHostStatsProviderWithData(fakeStats, fakeOS),
false, false,
false,
) )
stats, err := provider.ListPodStats() stats, err := provider.ListPodStats()
@ -396,6 +397,7 @@ func TestAcceleratorUsageStatsCanBeDisabled(t *testing.T) {
fakeImageService, fakeImageService,
NewFakeHostStatsProvider(), NewFakeHostStatsProvider(),
true, // this is what the test is actually testing true, // this is what the test is actually testing
false,
) )
stats, err := provider.ListPodStats() stats, err := provider.ListPodStats()
@ -541,6 +543,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
nil, nil,
NewFakeHostStatsProvider(), NewFakeHostStatsProvider(),
false, false,
false,
) )
stats, err := provider.ListPodCPUAndMemoryStats() stats, err := provider.ListPodCPUAndMemoryStats()
@ -671,6 +674,7 @@ func TestCRIImagesFsStats(t *testing.T) {
fakeImageService, fakeImageService,
NewFakeHostStatsProvider(), NewFakeHostStatsProvider(),
false, false,
false,
) )
stats, err := provider.ImageFsStats() stats, err := provider.ImageFsStats()

View File

@ -42,10 +42,10 @@ func NewCRIStatsProvider(
runtimeService internalapi.RuntimeService, runtimeService internalapi.RuntimeService,
imageService internalapi.ImageManagerService, imageService internalapi.ImageManagerService,
hostStatsProvider HostStatsProvider, hostStatsProvider HostStatsProvider,
disableAcceleratorUsageMetrics bool, disableAcceleratorUsageMetrics, podAndContainerStatsFromCRI bool,
) *Provider { ) *Provider {
return newStatsProvider(cadvisor, podManager, runtimeCache, newCRIStatsProvider(cadvisor, resourceAnalyzer, return newStatsProvider(cadvisor, podManager, runtimeCache, newCRIStatsProvider(cadvisor, resourceAnalyzer,
runtimeService, imageService, hostStatsProvider, disableAcceleratorUsageMetrics)) runtimeService, imageService, hostStatsProvider, disableAcceleratorUsageMetrics, podAndContainerStatsFromCRI))
} }
// NewCadvisorStatsProvider returns a containerStatsProvider that provides both // NewCadvisorStatsProvider returns a containerStatsProvider that provides both