diff --git a/lib/utils/common.py b/lib/utils/common.py index 460d7e4a..3e1a5ced 100644 --- a/lib/utils/common.py +++ b/lib/utils/common.py @@ -380,6 +380,10 @@ def _compute_license_data_size(namespace_stats, cluster_dict): ns_repl_factor = 1 for host_id, host_stats in ns_stats.items(): + host_memory_bytes = 0.0 + host_device_bytes = 0.0 + host_pmem_bytes = 0.0 + if not host_stats or isinstance(host_stats, Exception): continue @@ -392,7 +396,7 @@ def _compute_license_data_size(namespace_stats, cluster_dict): ns_repl_factor = util.get_value_from_dict( host_stats, - "effective_replication_factor", + ("effective_replication_factor", "replication-factor"), default_value=1, return_type=int, ) @@ -411,49 +415,40 @@ def _compute_license_data_size(namespace_stats, cluster_dict): return_type=float, ) - # For data-in-memory, data is in both memory & device. In this case it was - # asked that we only count the data stored in memory. - - metrics = [ - "index_pmem_used_bytes", - "index_flash_used_bytes", - "memory_used_bytes", - ] - - for metric in metrics: - bytes = util.get_value_from_dict( - host_stats, - metric, - default_value=0, - return_type=int, - ) + host_device_bytes = util.get_value_from_dict( + host_stats, + "device_used_bytes", + default_value=0.0, + return_type=float, + ) - ns_unique_data += bytes + host_device_bytes /= host_device_compression_ratio - ns_data_in_memory = util.get_value_from_dict( + host_pmem_bytes = util.get_value_from_dict( host_stats, - "storage-engine.data-in-memory", - default_value=False, - return_type=bool, + "pmem_used_bytes", + default_value=0.0, + return_type=float, ) - if not ns_data_in_memory: - bytes = util.get_value_from_dict( + host_pmem_bytes /= host_pmem_compression_ratio + + if host_pmem_bytes == 0.0 and host_device_bytes == 0.0: + host_memory_bytes += util.get_value_from_dict( host_stats, - "device_used_bytes", - default_value=0, - return_type=int, + "memory_used_index_bytes", + default_value=0.0, + return_type=float, ) - ns_unique_data += bytes / host_device_compression_ratio - bytes = util.get_value_from_dict( - host_stats, - "pmem_used_bytes", - default_value=0, - return_type=int, - ) + host_memory_bytes += util.get_value_from_dict( + host_stats, + "memory_used_data_bytes", + default_value=0.0, + return_type=float, + ) - ns_unique_data += bytes / host_pmem_compression_ratio + ns_unique_data += host_memory_bytes + host_pmem_bytes + host_device_bytes ns_unique_data = _license_data_usage_adjustment( ns_repl_factor, ns_master_objects, ns_unique_data diff --git a/test/unit/utils/test_common.py b/test/unit/utils/test_common.py index e5c2a4f3..897d3dc1 100644 --- a/test/unit/utils/test_common.py +++ b/test/unit/utils/test_common.py @@ -39,12 +39,11 @@ def test_success(self): "1.1.1.1": { "master_objects": 100, "effective_replication_factor": 2, - "pmem_used_bytes": 99000, - "device_used_bytes": 3200, + "device_used_bytes": 7200, } } }, - "exp_cluster_dict": {"license_data": 47600}, + "exp_cluster_dict": {"license_data": 100}, }, { "ns_stats": { @@ -52,8 +51,7 @@ def test_success(self): "1.1.1.1": { "master_objects": 100, "effective_replication_factor": 2, - "pmem_used_bytes": 99000, - "device_used_bytes": 3200, + "pmem_used_bytes": 8000, "memory_used_bytes": 800, } }, @@ -61,13 +59,12 @@ def test_success(self): "1.1.1.1": { "master_objects": 50, "effective_replication_factor": 3, - "pmem_used_bytes": 50000, - "device_used_bytes": 3800, + "device_used_bytes": 6000, "memory_used_bytes": 3300, } }, }, - "exp_cluster_dict": {"license_data": 65283}, + "exp_cluster_dict": {"license_data": 500 + 250}, }, { "ns_stats": { @@ -75,13 +72,13 @@ def test_success(self): "1.1.1.1": { "master_objects": 100, "effective_replication_factor": 2, - "pmem_used_bytes": 99000, - "device_used_bytes": 3200, + "device_used_bytes": 7200, "memory_used_bytes": 800, }, "2.2.2.2": { "master_objects": 10, "effective_replication_factor": 2, + "device_used_bytes": 3200, "memory_used_bytes": 10000, }, }, @@ -90,17 +87,17 @@ def test_success(self): "master_objects": 50, "effective_replication_factor": 3, "pmem_used_bytes": 50000, - "device_used_bytes": 3800, - "memory_used_bytes": 3300, }, "2.2.2.2": { "master_objects": 10, "effective_replication_factor": 3, - "memory_used_bytes": 10000, + "pmem_used_bytes": 10000, }, }, }, - "exp_cluster_dict": {"license_data": 72917}, + "exp_cluster_dict": { + "license_data": ((7200 + 3200) / 2) - (110 * 35) + 20000 - (35 * 60) + }, }, ]