Skip to content

Commit

Permalink
added placeholder cost estimators
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarelas committed Aug 1, 2023
1 parent 77506ae commit dc70323
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cortisol/cortisollib/estimators.py
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
44 changes: 44 additions & 0 deletions tests/cortisollib/test_estimators.py
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)

0 comments on commit dc70323

Please sign in to comment.