Merge pull request #8626 from jsturtevant/fix-windows-podstats-for-hpc

Fix issue for HPC pod metrics
This commit is contained in:
Kazuyoshi Kato 2023-06-01 19:25:08 -07:00 committed by GitHub
commit 8a6c8a96c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 2 deletions

View File

@ -267,7 +267,9 @@ func (c *criService) listWindowsMetricsForSandbox(ctx context.Context, sandbox s
func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.WindowsContainerStats, error) {
var cs runtime.WindowsContainerStats
if stats != nil {
// the metric should exist but stats or stats.container will be nil for HostProcess sandbox containers
// this can also be the case when the container has not started yet
if stats != nil && stats.Container != nil {
wstats := stats.GetWindows()
if wstats == nil {
return nil, fmt.Errorf("windows stats is empty")

View File

@ -200,6 +200,38 @@ func Test_criService_podSandboxStats(t *testing.T) {
},
expectError: false,
},
{
desc: "pod sandbox with empty stats still works (hostprocess container scenario)",
metrics: map[string]*wstats.Statistics{
"c1": {
Container: windowsStat(currentStatsTimestamp, 400, 20),
},
"s1": {},
},
sandbox: sandboxPod("s1", initialStatsTimestamp, 200),
containers: []containerstore.Container{
{
Metadata: containerstore.Metadata{ID: "c1"},
Stats: &stats.ContainerStats{
Timestamp: initialStatsTimestamp,
UsageCoreNanoSeconds: 200,
},
},
},
expectedPodStats: expectedStats{
UsageCoreNanoSeconds: 400,
UsageNanoCores: 200,
WorkingSetBytes: 20,
},
expectedContainerStats: []expectedStats{
{
UsageCoreNanoSeconds: 400,
UsageNanoCores: 200,
WorkingSetBytes: 20,
},
},
expectError: false,
},
} {
test := test
t.Run(test.desc, func(t *testing.T) {

View File

@ -266,7 +266,9 @@ func (c *criService) listWindowsMetricsForSandbox(ctx context.Context, sandbox s
func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.WindowsContainerStats, error) {
var cs runtime.WindowsContainerStats
if stats != nil {
// the metric should exist but stats or stats.container will be nil for HostProcess sandbox containers
// this can also be the case when the container has not started yet
if stats != nil && stats.Container != nil {
wstats := stats.GetWindows()
if wstats == nil {
return nil, fmt.Errorf("windows stats is empty")

View File

@ -200,6 +200,38 @@ func Test_criService_podSandboxStats(t *testing.T) {
},
expectError: false,
},
{
desc: "pod sandbox with empty stats still works (hostprocess container scenario)",
metrics: map[string]*wstats.Statistics{
"c1": {
Container: windowsStat(currentStatsTimestamp, 400, 20),
},
"s1": {},
},
sandbox: sandboxPod("s1", initialStatsTimestamp, 200),
containers: []containerstore.Container{
{
Metadata: containerstore.Metadata{ID: "c1"},
Stats: &stats.ContainerStats{
Timestamp: initialStatsTimestamp,
UsageCoreNanoSeconds: 200,
},
},
},
expectedPodStats: expectedStats{
UsageCoreNanoSeconds: 400,
UsageNanoCores: 200,
WorkingSetBytes: 20,
},
expectedContainerStats: []expectedStats{
{
UsageCoreNanoSeconds: 400,
UsageNanoCores: 200,
WorkingSetBytes: 20,
},
},
expectError: false,
},
} {
test := test
t.Run(test.desc, func(t *testing.T) {