-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
def datadog_log_cost_calculator(size): # TODO: Cost estimator is a placeholder | ||
""" | ||
Calculates the datadog log cost | ||
:param size: Log file size in GB | ||
:type size: Float | ||
:return: Log cost in dollars | ||
:rtype: Float | ||
""" | ||
|
||
return size * 0.1 | ||
|
||
|
||
def grafana_log_cost_calculator(size): # TODO: Cost estimator is a placeholder | ||
""" | ||
Calculates the grafana log cost | ||
:param size: Log file size in GB | ||
:type size: Float | ||
:return: Log cost in dollars | ||
:rtype: Float | ||
""" | ||
|
||
return size * 0.01 | ||
|
||
|
||
def format_bytes(file_size): | ||
""" | ||
Converts file size from Bytes to GB | ||
:param file_size: file size in bytes | ||
:type file_size: Float | ||
:return: File size in GB | ||
:rtype: Float | ||
""" | ||
k = 1024 | ||
file_size_in_gb = file_size / k**3 # Directly convert to GB (1024^3) | ||
return file_size_in_gb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import unittest | ||
from cortisol.cortisollib.estimators import ( | ||
datadog_log_cost_calculator, | ||
grafana_log_cost_calculator, | ||
format_bytes, | ||
) | ||
|
||
|
||
class TestLogCostCalculators(unittest.TestCase): | ||
def test_datadog_log_cost_calculator(self): | ||
size_gb = 5.0 | ||
expected_cost = size_gb * 0.1 | ||
self.assertEqual(datadog_log_cost_calculator(size_gb), expected_cost) | ||
|
||
def test_grafana_log_cost_calculator(self): | ||
size_gb = 10.0 | ||
expected_cost = size_gb * 0.01 | ||
self.assertEqual(grafana_log_cost_calculator(size_gb), expected_cost) | ||
|
||
def test_format_bytes(self): | ||
file_size_bytes = 2147483648 # 2 GB in bytes | ||
expected_size_gb = 2.0 | ||
result = format_bytes(file_size_bytes) | ||
self.assertEqual(expected_size_gb, result) | ||
|
||
# Additional tests for edge cases | ||
|
||
def test_datadog_log_cost_calculator_zero_size(self): | ||
size_gb = 0.0 | ||
expected_cost = 0.0 | ||
self.assertEqual(datadog_log_cost_calculator(size_gb), expected_cost) | ||
|
||
def test_grafana_log_cost_calculator_negative_size(self): | ||
size_gb = -5.0 | ||
expected_cost = size_gb * 0.01 | ||
self.assertEqual(grafana_log_cost_calculator(size_gb), expected_cost) | ||
|
||
def test_format_bytes_large_size(self): | ||
file_size_bytes = 128 * 1024**5 # 128 TB in bytes | ||
expected_size_gb = 128 * 1024**2 | ||
result = format_bytes(file_size_bytes) | ||
print(result) | ||
print(expected_size_gb) | ||
self.assertEqual(expected_size_gb, result) |