diff --git a/integration/test_metric.html b/integration/test_metric.html index df95b6323e..27ba776cca 100644 --- a/integration/test_metric.html +++ b/integration/test_metric.html @@ -28,16 +28,26 @@

Module tests.test_metric

import pytest
 import requests
+
 from prometheus_client.parser import text_string_to_metric_families
+
+from backupstore import set_random_backupstore  # NOQA
 from common import client, core_api, volume_name  # NOQA
+
+from common import crash_replica_processes
+from common import create_pv_for_volume
+from common import create_pvc_for_volume
+from common import create_and_check_volume
 from common import get_self_host_id
-from common import create_pv_for_volume, create_pvc_for_volume
-from common import create_and_check_volume, wait_for_volume_healthy
-from common import write_volume_random_data
-from common import wait_for_volume_detached, wait_for_volume_degraded
-from common import wait_for_volume_faulted, crash_replica_processes
+from common import wait_for_volume_degraded
+from common import wait_for_volume_detached
 from common import wait_for_volume_detached_unknown
-from common import Mi, LONGHORN_NAMESPACE
+from common import wait_for_volume_faulted
+from common import wait_for_volume_healthy
+from common import write_volume_random_data
+
+from common import Mi
+from common import LONGHORN_NAMESPACE
 
 # The dictionaries use float type of value because the value obtained from
 # prometheus_client is in float type.
@@ -75,7 +85,7 @@ 

Module tests.test_metric

return result -def check_volume_metric(core_api, metric_name, metric_labels, expect_value=None): # NOQA +def check_metric(core_api, metric_name, metric_labels, expected_value=None): # NOQA metric_data = get_metrics(core_api) for family in metric_data: for sample in family.samples: @@ -84,13 +94,14 @@

Module tests.test_metric

break assert item is not None - assert item.labels["node"] == metric_labels["node"] - assert item.labels["pvc"] == metric_labels["pvc"] - assert item.labels["volume"] == metric_labels["volume"] - assert item.labels["pvc_namespace"] == metric_labels["pvc_namespace"] + + for key, value in metric_labels.items(): + assert item.labels[key] == value + assert type(item.value) is float - if expect_value is not None: - assert item.value == expect_value + + if expected_value is not None: + assert item.value == expected_value else: assert item.value >= 0.0 @@ -124,7 +135,7 @@

Module tests.test_metric

write_volume_random_data(volume) volume = client.by_id_volume(volume_name) actual_size = float(volume.controllers[0].actualSize) - capacity_szie = float(volume.size) + capacity_size = float(volume.size) metric_labels = { "node": lht_hostId, @@ -134,57 +145,57 @@

Module tests.test_metric

} # check volume metric basic - check_volume_metric(core_api, "longhorn_volume_actual_size_bytes", - metric_labels, actual_size) - check_volume_metric(core_api, "longhorn_volume_capacity_bytes", - metric_labels, capacity_szie) - check_volume_metric(core_api, "longhorn_volume_read_throughput", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_write_throughput", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_read_iops", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_write_iops", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_read_latency", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_write_latency", - metric_labels) + check_metric(core_api, "longhorn_volume_actual_size_bytes", + metric_labels, actual_size) + check_metric(core_api, "longhorn_volume_capacity_bytes", + metric_labels, capacity_size) + check_metric(core_api, "longhorn_volume_read_throughput", + metric_labels) + check_metric(core_api, "longhorn_volume_write_throughput", + metric_labels) + check_metric(core_api, "longhorn_volume_read_iops", + metric_labels) + check_metric(core_api, "longhorn_volume_write_iops", + metric_labels) + check_metric(core_api, "longhorn_volume_read_latency", + metric_labels) + check_metric(core_api, "longhorn_volume_write_latency", + metric_labels) # verify longhorn_volume_robustness when volume is healthy, # degraded, faulted or unknown volume.detach() volume = wait_for_volume_detached_unknown(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", - metric_labels, longhorn_volume_robustness["unknown"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["unknown"]) volume.attach(hostId=lht_hostId) volume = wait_for_volume_healthy(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", metric_labels, - longhorn_volume_robustness["healthy"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["healthy"]) volume.updateReplicaCount(replicaCount=4) volume = wait_for_volume_degraded(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", - metric_labels, longhorn_volume_robustness["degraded"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["degraded"]) volume.updateReplicaCount(replicaCount=3) volume = wait_for_volume_healthy(client, volume_name) crash_replica_processes(client, core_api, volume_name) volume = wait_for_volume_faulted(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", - metric_labels, longhorn_volume_robustness["faulted"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["faulted"]) # verify longhorn_volume_state when volume is attached or detached volume = wait_for_volume_healthy(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_state", metric_labels, - longhorn_volume_state["attached"]) + check_metric(core_api, "longhorn_volume_state", + metric_labels, longhorn_volume_state["attached"]) volume.detach() volume = wait_for_volume_detached(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_state", - metric_labels, longhorn_volume_state["detached"])
+ check_metric(core_api, "longhorn_volume_state", + metric_labels, longhorn_volume_state["detached"])
@@ -194,8 +205,8 @@

Module tests.test_metric

Functions

-
-def check_volume_metric(core_api, metric_name, metric_labels, expect_value=None) +
+def check_metric(core_api, metric_name, metric_labels, expected_value=None)
@@ -203,7 +214,7 @@

Functions

Expand source code -
def check_volume_metric(core_api, metric_name, metric_labels, expect_value=None): # NOQA
+
def check_metric(core_api, metric_name, metric_labels, expected_value=None): # NOQA
     metric_data = get_metrics(core_api)
     for family in metric_data:
         for sample in family.samples:
@@ -212,13 +223,14 @@ 

Functions

break assert item is not None - assert item.labels["node"] == metric_labels["node"] - assert item.labels["pvc"] == metric_labels["pvc"] - assert item.labels["volume"] == metric_labels["volume"] - assert item.labels["pvc_namespace"] == metric_labels["pvc_namespace"] + + for key, value in metric_labels.items(): + assert item.labels[key] == value + assert type(item.value) is float - if expect_value is not None: - assert item.value == expect_value + + if expected_value is not None: + assert item.value == expected_value else: assert item.value >= 0.0
@@ -290,7 +302,7 @@

Functions

write_volume_random_data(volume) volume = client.by_id_volume(volume_name) actual_size = float(volume.controllers[0].actualSize) - capacity_szie = float(volume.size) + capacity_size = float(volume.size) metric_labels = { "node": lht_hostId, @@ -300,57 +312,57 @@

Functions

} # check volume metric basic - check_volume_metric(core_api, "longhorn_volume_actual_size_bytes", - metric_labels, actual_size) - check_volume_metric(core_api, "longhorn_volume_capacity_bytes", - metric_labels, capacity_szie) - check_volume_metric(core_api, "longhorn_volume_read_throughput", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_write_throughput", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_read_iops", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_write_iops", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_read_latency", - metric_labels) - check_volume_metric(core_api, "longhorn_volume_write_latency", - metric_labels) + check_metric(core_api, "longhorn_volume_actual_size_bytes", + metric_labels, actual_size) + check_metric(core_api, "longhorn_volume_capacity_bytes", + metric_labels, capacity_size) + check_metric(core_api, "longhorn_volume_read_throughput", + metric_labels) + check_metric(core_api, "longhorn_volume_write_throughput", + metric_labels) + check_metric(core_api, "longhorn_volume_read_iops", + metric_labels) + check_metric(core_api, "longhorn_volume_write_iops", + metric_labels) + check_metric(core_api, "longhorn_volume_read_latency", + metric_labels) + check_metric(core_api, "longhorn_volume_write_latency", + metric_labels) # verify longhorn_volume_robustness when volume is healthy, # degraded, faulted or unknown volume.detach() volume = wait_for_volume_detached_unknown(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", - metric_labels, longhorn_volume_robustness["unknown"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["unknown"]) volume.attach(hostId=lht_hostId) volume = wait_for_volume_healthy(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", metric_labels, - longhorn_volume_robustness["healthy"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["healthy"]) volume.updateReplicaCount(replicaCount=4) volume = wait_for_volume_degraded(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", - metric_labels, longhorn_volume_robustness["degraded"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["degraded"]) volume.updateReplicaCount(replicaCount=3) volume = wait_for_volume_healthy(client, volume_name) crash_replica_processes(client, core_api, volume_name) volume = wait_for_volume_faulted(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_robustness", - metric_labels, longhorn_volume_robustness["faulted"]) + check_metric(core_api, "longhorn_volume_robustness", + metric_labels, longhorn_volume_robustness["faulted"]) # verify longhorn_volume_state when volume is attached or detached volume = wait_for_volume_healthy(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_state", metric_labels, - longhorn_volume_state["attached"]) + check_metric(core_api, "longhorn_volume_state", + metric_labels, longhorn_volume_state["attached"]) volume.detach() volume = wait_for_volume_detached(client, volume_name) - check_volume_metric(core_api, "longhorn_volume_state", - metric_labels, longhorn_volume_state["detached"])
+ check_metric(core_api, "longhorn_volume_state", + metric_labels, longhorn_volume_state["detached"])
@@ -371,7 +383,7 @@

Index

  • Functions