Skip to content

Commit

Permalink
fix: flaky test_volume_metircs
Browse files Browse the repository at this point in the history
ref: 8268

Signed-off-by: Chris <[email protected]>
  • Loading branch information
chriscchien authored and khushboo-rancher committed Apr 3, 2024
1 parent f4d6c4a commit a159de3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions manager/integration/tests/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from common import RETRY_COUNTS
from common import RETRY_INTERVAL
from common import DEFAULT_DISK_PATH
from common import Gi

# The dictionaries use float type of value because the value obtained from
# prometheus_client is in float type.
Expand Down Expand Up @@ -194,9 +195,11 @@ def filter_metric_by_labels(metrics, labels):
assert total_metrics["value"] >= 0.0


def wait_for_metric_volume_actual_size(core_api, metric_name, metric_labels, actual_size): # NOQA
def wait_for_metric_volume_actual_size(client, core_api, metric_name, metric_labels, volume_name): # NOQA
for _ in range(RETRY_COUNTS):
time.sleep(RETRY_INTERVAL)
volume = client.by_id_volume(volume_name)
actual_size = int(volume.controllers[0].actualSize)

try:
check_metric(core_api, metric_name,
Expand Down Expand Up @@ -273,7 +276,7 @@ def test_volume_metrics(client, core_api, volume_name, pvc_namespace): # NOQA
lht_hostId = get_self_host_id()
pv_name = volume_name + "-pv"
pvc_name = volume_name + "-pvc"
volume_size = str(500 * Mi)
volume_size = str(1 * Gi)
volume = create_and_check_volume(client,
volume_name,
num_of_replicas=3,
Expand All @@ -286,7 +289,7 @@ def test_volume_metrics(client, core_api, volume_name, pvc_namespace): # NOQA
volume = client.by_id_volume(volume_name)
volume.attach(hostId=lht_hostId)
volume = wait_for_volume_healthy(client, volume_name)
data_size = 1 * Mi
data_size = 100 * Mi
data = {'pos': 0,
'len': data_size,
'content': generate_random_data(data_size)}
Expand All @@ -302,9 +305,9 @@ def test_volume_metrics(client, core_api, volume_name, pvc_namespace): # NOQA
}

# check volume metric basic
wait_for_metric_volume_actual_size(core_api,
wait_for_metric_volume_actual_size(client, core_api,
"longhorn_volume_actual_size_bytes",
metric_labels, data_size)
metric_labels, volume_name)
check_metric(core_api, "longhorn_volume_capacity_bytes",
metric_labels, capacity_size)
check_metric(core_api, "longhorn_volume_read_throughput",
Expand Down

0 comments on commit a159de3

Please sign in to comment.