diff --git a/pkg/kubelet/stats/cadvisor_stats_provider.go b/pkg/kubelet/stats/cadvisor_stats_provider.go index 6e4655fdcde..738f240c2d3 100644 --- a/pkg/kubelet/stats/cadvisor_stats_provider.go +++ b/pkg/kubelet/stats/cadvisor_stats_provider.go @@ -125,7 +125,17 @@ func (p *cadvisorStatsProvider) ListPodStats() ([]statsapi.PodStats, error) { // the user and has network stats. podStats.Network = cadvisorInfoToNetworkStats(&cinfo) } else { - podStats.Containers = append(podStats.Containers, *cadvisorInfoToContainerStats(containerName, &cinfo, &rootFsInfo, &imageFsInfo)) + containerStat := cadvisorInfoToContainerStats(containerName, &cinfo, &rootFsInfo, &imageFsInfo) + // NOTE: This doesn't support the old pod log path, `/var/log/pods/UID`. For containers + // using old log path, they will be populated by cadvisorInfoToContainerStats. + podUID := types.UID(podStats.PodRef.UID) + logs, err := p.hostStatsProvider.getPodContainerLogStats(podStats.PodRef.Namespace, podStats.PodRef.Name, podUID, containerName, &rootFsInfo) + if err != nil { + klog.ErrorS(err, "Unable to fetch container log stats", "containerName", containerName) + } else { + containerStat.Logs = logs + } + podStats.Containers = append(podStats.Containers, *containerStat) } } diff --git a/pkg/kubelet/stats/helper.go b/pkg/kubelet/stats/helper.go index 6af80ce3d97..da32fb11eed 100644 --- a/pkg/kubelet/stats/helper.go +++ b/pkg/kubelet/stats/helper.go @@ -94,6 +94,9 @@ func cadvisorInfoToContainerStats(name string, info *cadvisorapiv2.ContainerInfo result.CPU = cpu result.Memory = memory + // NOTE: if they can be found, log stats will be overwritten + // by the caller, as it knows more information about the pod, + // which is needed to determine log size. if rootFs != nil { // The container logs live on the node rootfs device result.Logs = buildLogsStats(cstat, rootFs)