Skip to content

Commit 57d93d6

Browse files
committed
pkg/validate/pod.go: update expected descriptors
Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
1 parent a64d665 commit 57d93d6

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

.github/workflows/crio.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
run: |
6262
sudo mkdir -p /etc/crio/crio.conf.d
6363
printf '[crio.runtime]\nlog_level = "debug"\n[crio.image]\nshort_name_mode = "disabled"\n' | sudo tee -a /etc/crio/crio.conf.d/01-base.conf
64-
printf '[crio.stats]\nincluded_pod_metrics = [\n"disk",\n"diskIO",\n"network",\n"cpu",\n"hugetlb",\n"memory",\n"oom",\n"process",\n"spec",\n]\n' | sudo tee -a /etc/crio/crio.conf.d/01-base.conf
64+
printf '[crio.stats]\nincluded_pod_metrics = [\n"disk",\n"diskIO",\n"network",\n"cpu",\n"hugetlb",\n"memory",\n"oom",\n"process",\n"spec",\n"pressure",\n]\n' | sudo tee -a /etc/crio/crio.conf.d/01-base.conf
6565
- name: Configure CRI-O to use conmon-rs intead of the default conmon
6666
if: ${{matrix.monitor == 'conmon-rs'}}
6767
run: |

pkg/validate/pod.go

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"os"
2222
"path/filepath"
23+
"slices"
2324
"strings"
2425
"time"
2526

@@ -36,22 +37,31 @@ import (
3637

3738
// expectedMetricDescriptorNames contains all expected metric descriptor names
3839
// based on metrics returned by kubelet with CRI-O and cadvisor on the legacy cadvisor stats provider
39-
// on kubernetes 1.35.
40+
// on kubernetes 1.37.
4041
var expectedMetricDescriptorNames = []string{
4142
"container_blkio_device_usage_total",
43+
"container_cpu_cfs_periods_total",
44+
"container_cpu_cfs_throttled_periods_total",
45+
"container_cpu_cfs_throttled_seconds_total",
4246
"container_cpu_system_seconds_total",
4347
"container_cpu_usage_seconds_total",
4448
"container_cpu_user_seconds_total",
4549
"container_file_descriptors",
50+
"container_fs_inodes_free",
51+
"container_fs_inodes_total",
52+
"container_fs_limit_bytes",
4653
"container_fs_reads_bytes_total",
4754
"container_fs_reads_total",
4855
"container_fs_usage_bytes",
4956
"container_fs_writes_bytes_total",
5057
"container_fs_writes_total",
58+
"container_hugetlb_max_usage_bytes",
59+
"container_hugetlb_usage_bytes",
5160
"container_last_seen",
5261
"container_memory_cache",
5362
"container_memory_failcnt",
5463
"container_memory_failures_total",
64+
"container_memory_kernel_usage",
5565
"container_memory_mapped_file",
5666
"container_memory_max_usage_bytes",
5767
"container_memory_rss",
@@ -67,9 +77,16 @@ var expectedMetricDescriptorNames = []string{
6777
"container_network_transmit_packets_dropped_total",
6878
"container_network_transmit_packets_total",
6979
"container_oom_events_total",
80+
"container_pressure_cpu_stalled_seconds_total",
81+
"container_pressure_cpu_waiting_seconds_total",
82+
"container_pressure_io_stalled_seconds_total",
83+
"container_pressure_io_waiting_seconds_total",
84+
"container_pressure_memory_stalled_seconds_total",
85+
"container_pressure_memory_waiting_seconds_total",
7086
"container_processes",
7187
"container_sockets",
7288
"container_spec_cpu_period",
89+
"container_spec_cpu_quota",
7390
"container_spec_cpu_shares",
7491
"container_spec_memory_limit_bytes",
7592
"container_spec_memory_reservation_limit_bytes",
@@ -80,6 +97,19 @@ var expectedMetricDescriptorNames = []string{
8097
"container_ulimits_soft",
8198
}
8299

100+
// optionalValuesForMetricDescriptors contains the metric descriptors that have
101+
// optional values due to test environment limitations.
102+
var optionalValuesForMetricDescriptors = []string{
103+
// All of these depend on blkio cgroup accounting, which doesn't work on
104+
// GitHub actions runners because the overlay filesystem is typically backed
105+
// by a virtual disk that doesn't report per-device I/O stats.
106+
"container_blkio_device_usage_total",
107+
"container_fs_reads_bytes_total",
108+
"container_fs_reads_total",
109+
"container_fs_writes_bytes_total",
110+
"container_fs_writes_total",
111+
}
112+
83113
var _ = framework.KubeDescribe("PodSandbox", func() {
84114
f := framework.NewDefaultCRIFramework()
85115

@@ -178,7 +208,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
178208
By("create container in pod")
179209

180210
ic := f.CRIClient.CRIImageClient
181-
containerID := framework.CreateDefaultContainer(context.TODO(), rc, ic, podID, podConfig, "container-for-metrics-")
211+
containerID := createContainerForMetrics(context.TODO(), rc, ic, podID, podConfig)
182212

183213
By("start container")
184214
startContainer(context.TODO(), rc, containerID)
@@ -397,6 +427,9 @@ func testPodSandboxMetrics(allMetrics []*runtimeapi.PodSandboxMetrics, descs []*
397427

398428
for _, expectedName := range expectedMetricDescriptorNames {
399429
if len(metricNamesFound[expectedName]) == 0 {
430+
if slices.Contains(optionalValuesForMetricDescriptors, expectedName) {
431+
continue // skip optional values
432+
}
400433
missingMetrics = append(missingMetrics, expectedName)
401434
}
402435
}
@@ -407,9 +440,30 @@ func testPodSandboxMetrics(allMetrics []*runtimeapi.PodSandboxMetrics, descs []*
407440

408441
for _, desc := range descs {
409442
if len(metricNamesFound[desc.GetName()]) != len(desc.GetLabelKeys()) {
443+
if slices.Contains(optionalValuesForMetricDescriptors, desc.GetName()) {
444+
continue // skip optional values
445+
}
410446
mismatchedLabels = append(mismatchedLabels, desc.GetName())
411447
}
412448
}
413449

414450
Expect(mismatchedLabels).To(BeEmpty(), "Expected %s metrics to have same set of labels in ListMetricDescriptors and ListPodSandboxMetrics", strings.Join(mismatchedLabels, ","))
415451
}
452+
453+
// createContainerForMetrics creates a container for metrics.
454+
func createContainerForMetrics(ctx context.Context, rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig) string {
455+
containerName := "container-for-metrics-" + framework.NewUUID()
456+
containerConfig := &runtimeapi.ContainerConfig{
457+
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
458+
Image: &runtimeapi.ImageSpec{Image: framework.TestContext.TestImageList.DefaultTestContainerImage},
459+
Command: framework.DefaultContainerCommand,
460+
Linux: &runtimeapi.LinuxContainerConfig{
461+
Resources: &runtimeapi.LinuxContainerResources{
462+
// Set CPUQuota to have values for container_spec_cpu_quota
463+
CpuQuota: 20000,
464+
},
465+
},
466+
}
467+
468+
return framework.CreateContainer(ctx, rc, ic, containerConfig, podID, podConfig)
469+
}

0 commit comments

Comments
 (0)