Skip to content

Tests for filesystem and disk allocated size metrics #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4d70ae5
Tests for filesystem and disk allocated size metrics
OhadRevah May 5, 2025
659fba9
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 6, 2025
ffbdd06
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 6, 2025
dab735a
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 6, 2025
c96d9a5
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 6, 2025
f8dcd05
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 7, 2025
c4cac96
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 7, 2025
3df9fa3
gMerge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 18, 2025
0d56b5b
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 18, 2025
e1badcb
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 19, 2025
8520cf4
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 19, 2025
65d4e83
Added tier3 marker to windows vms tests
OhadRevah May 20, 2025
818f2ea
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 20, 2025
b6dcf7c
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 21, 2025
30e739e
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 21, 2025
6f18dfa
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 22, 2025
8b3e8d8
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 22, 2025
e0babe4
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 22, 2025
0b3014a
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 26, 2025
b858d7d
Added check for gusetinfo --filesystem
OhadRevah May 26, 2025
226e080
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 27, 2025
3300704
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 27, 2025
78fe5bb
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 29, 2025
a7ac20e
Update tests/observability/metrics/utils.py
OhadRevah May 29, 2025
1ff9b11
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 29, 2025
e33204a
Updated code according to tox
OhadRevah May 29, 2025
0c2eb16
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah May 29, 2025
fd7ecb7
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 3, 2025
f475475
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 3, 2025
a7f79ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2025
6bad781
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 3, 2025
b32b08d
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 4, 2025
0e5fbef
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 4, 2025
254c587
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2025
9078fb8
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 5, 2025
c9cd642
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 5, 2025
ffd3c6f
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 10, 2025
e141dc5
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 10, 2025
208a2f3
Merge branch 'main' into kubevirt_vmi_filesystem_used_bytes
OhadRevah Jun 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 9 additions & 81 deletions tests/observability/metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
from ocp_resources.deployment import Deployment
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
from ocp_resources.pod import Pod
from ocp_resources.pod_metrics import PodMetrics
from ocp_resources.resource import Resource, ResourceEditor, get_client
from ocp_resources.storage_class import StorageClass
from ocp_resources.virtual_machine import VirtualMachine
from ocp_resources.virtual_machine_instance_migration import VirtualMachineInstanceMigration
from ocp_resources.virtual_machine_restore import VirtualMachineRestore
from pyhelper_utils.shell import run_command, run_ssh_commands
from pyhelper_utils.shell import run_ssh_commands
from pytest_testconfig import py_config
from timeout_sampler import TimeoutExpiredError, TimeoutSampler

Expand All @@ -33,7 +32,6 @@
KUBEVIRT_VMI_PHASE_COUNT_STR,
KUBEVIRT_VMI_STATUS_ADDRESSES,
KUBEVIRT_VNC_ACTIVE_CONNECTIONS_BY_VMI,
RSS_MEMORY_COMMAND,
)
from tests.observability.metrics.utils import (
SINGLE_VM,
Expand Down Expand Up @@ -83,12 +81,10 @@
SOURCE_POD,
SSP_OPERATOR,
TCP_TIMEOUT_30SEC,
TIMEOUT_1MIN,
TIMEOUT_2MIN,
TIMEOUT_3MIN,
TIMEOUT_4MIN,
TIMEOUT_5MIN,
TIMEOUT_5SEC,
TIMEOUT_10MIN,
TIMEOUT_15SEC,
TIMEOUT_30MIN,
Expand Down Expand Up @@ -798,12 +794,17 @@ def vm_for_test_snapshot(vm_for_test):


@pytest.fixture()
def dfs_info(vm_for_test):
def disk_file_system_info_linux(vm_for_test):
return disk_file_system_info(vm=vm_for_test)


@pytest.fixture()
def file_system_metric_mountpoints_existence(request, prometheus, vm_for_test, dfs_info):
def disk_file_system_info_windows(windows_vm_for_test):
return disk_file_system_info(vm=windows_vm_for_test)


@pytest.fixture()
def file_system_metric_mountpoints_existence(request, prometheus, vm_for_test, disk_file_system_info_linux):
capacity_or_used = request.param
samples = TimeoutSampler(
wait_timeout=TIMEOUT_2MIN,
Expand All @@ -817,7 +818,7 @@ def file_system_metric_mountpoints_existence(request, prometheus, vm_for_test, d
try:
for sample in samples:
if sample:
if [mount_point for mount_point in dfs_info if not sample.get(mount_point)]:
if [mount_point for mount_point in disk_file_system_info_linux if not sample.get(mount_point)]:
continue
mount_points_with_value_zero = {
mount_point: float(sample[mount_point]) for mount_point in sample if int(sample[mount_point]) == 0
Expand All @@ -843,65 +844,6 @@ def vm_for_test_with_resource_limits(namespace):
yield vm


@pytest.fixture()
def vm_memory_working_set_bytes(vm_for_test, virt_launcher_pod_metrics_resource_exists):
samples = TimeoutSampler(
wait_timeout=TIMEOUT_2MIN,
sleep=TIMEOUT_5SEC,
func=run_command,
command=shlex.split(
f"oc adm top pod {vm_for_test.vmi.virt_launcher_pod.name} -n {vm_for_test.namespace} --no-headers"
),
check=False,
)
try:
for sample in samples:
if sample and (out := sample[1]):
return int(
bitmath.parse_string_unsafe(
re.search(
r"\b(\d+Mi)\b",
out,
).group(1)
).bytes
)
except TimeoutExpiredError:
LOGGER.error(f"working_set bytes is not available for VM {vm_for_test.name} after {TIMEOUT_2MIN} seconds")
raise


@pytest.fixture()
def virt_launcher_pod_metrics_resource_exists(vm_for_test):
vl_name = vm_for_test.vmi.virt_launcher_pod.name
samples = TimeoutSampler(
wait_timeout=TIMEOUT_1MIN,
sleep=TIMEOUT_15SEC,
func=lambda: PodMetrics(name=vl_name, namespace=vm_for_test.namespace).exists,
)
try:
for sample in samples:
if sample:
LOGGER.info(f"PodMetric resource for {vl_name} exists.")
return
except TimeoutExpiredError:
LOGGER.error(f"Resource PodMetrics for pod {vl_name} not found")
raise


@pytest.fixture()
def vm_memory_rss_bytes(vm_for_test):
return int(vm_for_test.privileged_vmi.virt_launcher_pod.execute(command=RSS_MEMORY_COMMAND))


@pytest.fixture(scope="class")
def vm_virt_launcher_pod_requested_memory(vm_for_test):
return int(
bitmath.parse_string_unsafe(
vm_for_test.vmi.virt_launcher_pod.instance.spec.containers[0].resources.requests.memory
).bytes
)


@pytest.fixture()
def virt_handler_pods_count(hco_namespace):
return str(
Expand Down Expand Up @@ -1045,20 +987,6 @@ def vm_for_vm_disk_allocation_size_test(namespace, unprivileged_client, golden_i
yield vm


@pytest.fixture()
def pvc_size_bytes(vm_for_vm_disk_allocation_size_test):
return str(
int(
bitmath.parse_string_unsafe(
PersistentVolumeClaim(
name=vm_for_vm_disk_allocation_size_test.instance.spec.dataVolumeTemplates[0].metadata.name,
namespace=vm_for_vm_disk_allocation_size_test.namespace,
).instance.spec.resources.requests.storage
).Byte.bytes
)
)


@pytest.fixture()
def vnic_info_from_vm_or_vmi(request, running_metric_vm):
vm_instance = (
Expand Down
1 change: 1 addition & 0 deletions tests/observability/metrics/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
KUBEVIRT_VMSNAPSHOT_PERSISTENTVOLUMECLAIM_LABELS = (
"kubevirt_vmsnapshot_persistentvolumeclaim_labels{{vm_name='{vm_name}'}}"
)
KUBEVIRT_VM_DISK_ALLOCATED_SIZE_BYTES = "kubevirt_vm_disk_allocated_size_bytes{{name='{vm_name}'}}"
KUBEVIRT_VMI_NETWORK_RECEIVE_PACKETS_TOTAL = "kubevirt_vmi_network_receive_packets_total"
KUBEVIRT_VMI_NETWORK_TRANSMIT_PACKETS_TOTAL = "kubevirt_vmi_network_transmit_packets_total"
KUBEVIRT_VMI_MIGRATIONS_IN_SCHEDULING_PHASE = "kubevirt_vmi_migrations_in_scheduling_phase"
Expand Down
86 changes: 70 additions & 16 deletions tests/observability/metrics/test_vms_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from tests.observability.metrics.constants import (
KUBEVIRT_CONSOLE_ACTIVE_CONNECTIONS_BY_VMI,
KUBEVIRT_VM_DISK_ALLOCATED_SIZE_BYTES,
KUBEVIRT_VMI_MEMORY_AVAILABLE_BYTES,
KUBEVIRT_VMSNAPSHOT_PERSISTENTVOLUMECLAIM_LABELS,
KUBEVIRT_VNC_ACTIVE_CONNECTIONS_BY_VMI,
Expand All @@ -23,8 +24,10 @@
compare_metric_file_system_values_with_vm_file_system_values,
expected_metric_labels_and_values,
get_metric_labels_non_empty_value,
get_pvc_size_bytes,
timestamp_to_seconds,
validate_metric_value_within_range,
validate_metric_vm_container_free_memory_bytes_based_on_working_set_rss_bytes,
validate_vnic_info,
)
from tests.observability.utils import validate_metrics_value
Expand Down Expand Up @@ -301,7 +304,7 @@ def test_kubevirt_vmi_memory_cached_bytes(


@pytest.mark.parametrize("vm_for_test", [pytest.param("file-system-metrics")], indirect=True)
class TestVmiFileSystemMetrics:
class TestVmiFileSystemMetricsLinux:
@pytest.mark.parametrize(
"file_system_metric_mountpoints_existence, capacity_or_used",
[
Expand All @@ -320,13 +323,50 @@ class TestVmiFileSystemMetrics:
],
indirect=["file_system_metric_mountpoints_existence"],
)
def test_metric_kubevirt_vmi_filesystem_capacity_used_bytes(
self, prometheus, vm_for_test, file_system_metric_mountpoints_existence, dfs_info, capacity_or_used
def test_metric_kubevirt_vmi_filesystem_capacity_used_bytes_linux(
self,
prometheus,
vm_for_test,
file_system_metric_mountpoints_existence,
disk_file_system_info_linux,
capacity_or_used,
):
compare_metric_file_system_values_with_vm_file_system_values(
prometheus=prometheus,
vm_for_test=vm_for_test,
mount_point=list(dfs_info.keys())[0],
mount_point=[*disk_file_system_info_linux][0],
capacity_or_used=capacity_or_used,
)


@pytest.mark.tier3
class TestVmiFileSystemMetricsWindows:
@pytest.mark.parametrize(
"capacity_or_used",
[
pytest.param(
CAPACITY,
marks=pytest.mark.polarion("CNV-11917"),
id="test_metric_kubevirt_vmi_filesystem_capacity_bytes",
),
pytest.param(
USED,
marks=pytest.mark.polarion("CNV-11918"),
id="test_metric_kubevirt_vmi_filesystem_used_bytes",
),
],
)
def test_metric_kubevirt_vmi_filesystem_capacity_used_bytes_windows(
self,
prometheus,
windows_vm_for_test,
disk_file_system_info_windows,
capacity_or_used,
):
compare_metric_file_system_values_with_vm_file_system_values(
prometheus=prometheus,
vm_for_test=windows_vm_for_test,
mount_point=[*disk_file_system_info_windows][0],
capacity_or_used=capacity_or_used,
)

Expand Down Expand Up @@ -418,25 +458,26 @@ def test_metric_kubevirt_vm_resource_limits(
@pytest.mark.parametrize("vm_for_test", [pytest.param("memory-working-set-vm")], indirect=True)
class TestVmFreeMemoryBytes:
@pytest.mark.polarion("CNV-11692")
def test_metric_kubevirt_vm_container_free_memory_bytes_based_on_working_set_bytes(
self, prometheus, vm_for_test, vm_virt_launcher_pod_requested_memory, vm_memory_working_set_bytes
):
validate_metric_value_within_range(
def test_metric_kubevirt_vm_container_free_memory_bytes_based_on_working_set_bytes(self, prometheus, vm_for_test):
validate_metric_vm_container_free_memory_bytes_based_on_working_set_rss_bytes(
prometheus=prometheus,
metric_name=f"kubevirt_vm_container_free_memory_bytes_based_on_working_set_bytes"
f"{{pod='{vm_for_test.vmi.virt_launcher_pod.name}'}}",
expected_value=vm_virt_launcher_pod_requested_memory - vm_memory_working_set_bytes,
vm=vm_for_test,
working_set=True,
)

@pytest.mark.polarion("CNV-11693")
def test_metric_kubevirt_vm_container_free_memory_bytes_based_on_rss(
self, prometheus, vm_for_test, vm_virt_launcher_pod_requested_memory, vm_memory_rss_bytes
self,
prometheus,
vm_for_test,
):
validate_metric_value_within_range(
validate_metric_vm_container_free_memory_bytes_based_on_working_set_rss_bytes(
prometheus=prometheus,
metric_name=f"kubevirt_vm_container_free_memory_bytes_based_on_rss"
f"{{pod='{vm_for_test.privileged_vmi.virt_launcher_pod.name}'}}",
expected_value=vm_virt_launcher_pod_requested_memory - vm_memory_rss_bytes,
vm=vm_for_test,
)


Expand Down Expand Up @@ -497,15 +538,28 @@ def test_metric_kubevirt_vmsnapshot_persistentvolumeclaim_labels(
)


class TestVmDiskAllocatedSize:
class TestVmDiskAllocatedSizeLinux:
@pytest.mark.polarion("CNV-11817")
def test_metric_kubevirt_vm_disk_allocated_size_bytes(
self, prometheus, vm_for_vm_disk_allocation_size_test, pvc_size_bytes
self,
prometheus,
vm_for_vm_disk_allocation_size_test,
):
validate_metrics_value(
prometheus=prometheus,
metric_name=f"kubevirt_vm_disk_allocated_size_bytes{{name='{vm_for_vm_disk_allocation_size_test.name}'}}",
expected_value=pvc_size_bytes,
metric_name=KUBEVIRT_VM_DISK_ALLOCATED_SIZE_BYTES.format(vm_name=vm_for_vm_disk_allocation_size_test.name),
expected_value=get_pvc_size_bytes(vm=vm_for_vm_disk_allocation_size_test),
)


@pytest.mark.tier3
class TestVmDiskAllocatedSizeWindows:
@pytest.mark.polarion("CNV-11916")
def test_metric_kubevirt_vm_disk_allocated_size_bytes_windows(self, prometheus, windows_vm_for_test):
validate_metrics_value(
prometheus=prometheus,
metric_name=KUBEVIRT_VM_DISK_ALLOCATED_SIZE_BYTES.format(vm_name=windows_vm_for_test.name),
expected_value=get_pvc_size_bytes(vm=windows_vm_for_test),
)


Expand Down
Loading