Skip to content

Commit

Permalink
Merge pull request #121 from citrusleaf/Fix-license-calculation
Browse files Browse the repository at this point in the history
Fix license calculation
  • Loading branch information
Jesse S authored Aug 27, 2021
2 parents 26605e9 + 1144efd commit 80f0128
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 49 deletions.
65 changes: 30 additions & 35 deletions lib/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
)
Expand All @@ -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
Expand Down
25 changes: 11 additions & 14 deletions test/unit/utils/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,46 @@ 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": {
"foo": {
"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,
}
},
"bar": {
"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": {
"foo": {
"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,
},
},
Expand All @@ -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)
},
},
]

Expand Down

0 comments on commit 80f0128

Please sign in to comment.