diff --git a/monasca_transform/component/usage/fetch_quantity_util.py b/monasca_transform/component/usage/fetch_quantity_util.py index 55c0569..624eb9d 100644 --- a/monasca_transform/component/usage/fetch_quantity_util.py +++ b/monasca_transform/component/usage/fetch_quantity_util.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from pyspark.sql.functions import ceil from pyspark.sql.functions import col from pyspark.sql.functions import when from pyspark.sql import SQLContext @@ -157,7 +156,7 @@ class FetchQuantityUtil(UsageComponent): To calculate the utilized quantity this component uses following formula: - utilized quantity = ceil((100 - idle_perc) * total_quantity / 100) + utilized quantity = (100 - idle_perc) * total_quantity / 100 """ @@ -252,9 +251,9 @@ class FetchQuantityUtil(UsageComponent): quant_idle_perc_calc_df = quant_idle_perc_df.select( col("quantity_df_alias.*"), when(col("idle_perc_df_alias.quantity") != 0.0, - ceil(((100.0 - col( - "idle_perc_df_alias.quantity"))) * col( - "quantity_df_alias.quantity") / 100.0)) + (100.0 - col( + "idle_perc_df_alias.quantity")) * col( + "quantity_df_alias.quantity") / 100.0) .otherwise(col("quantity_df_alias.quantity")) .alias("utilized_quantity"), diff --git a/tests/unit/driver/first_attempt_at_spark_test.py b/tests/unit/driver/first_attempt_at_spark_test.py index a865455..9a59673 100644 --- a/tests/unit/driver/first_attempt_at_spark_test.py +++ b/tests/unit/driver/first_attempt_at_spark_test.py @@ -747,7 +747,7 @@ class SparkTest(SparkContextTest): self.assertTrue(cpu_util_cores_agg_metric is not None) - self.assertEqual(2.0, + self.assertEqual(0.5303809523809525, cpu_util_cores_agg_metric .get('metric').get('value')) self.assertEqual('useast', @@ -789,7 +789,7 @@ class SparkTest(SparkContextTest): self.assertTrue(cpu_util_cores_agg_metric is not None) - self.assertEqual(1.0, + self.assertEqual(0.3866666666666669, cpu_util_cores_agg_metric .get('metric').get('value')) self.assertEqual('useast', @@ -831,7 +831,7 @@ class SparkTest(SparkContextTest): self.assertTrue(cpu_util_cores_agg_metric is not None) - self.assertEqual(1.0, + self.assertEqual(0.14371428571428566, cpu_util_cores_agg_metric .get('metric').get('value')) self.assertEqual('useast', diff --git a/tests/unit/usage/test_fetch_quantity_util_agg.py b/tests/unit/usage/test_fetch_quantity_util_agg.py index a79277f..26d182c 100644 --- a/tests/unit/usage/test_fetch_quantity_util_agg.py +++ b/tests/unit/usage/test_fetch_quantity_util_agg.py @@ -181,7 +181,7 @@ class TestFetchQuantityUtilAgg(SparkContextTest): if value.get('metric').get( 'name') == 'cpu.utilized_logical_cores_agg'][0] - self.assertEqual(9.0, + self.assertEqual(7.7700000000000005, utilized_cpu_logical_agg_metric.get( 'metric').get('value')) self.assertEqual('useast', @@ -284,7 +284,7 @@ class TestFetchQuantityUtilAgg(SparkContextTest): if value.get('metric').get( 'name') == 'cpu.utilized_logical_cores_agg'][0] - self.assertEqual(11.0, + self.assertEqual(9.52, utilized_cpu_logical_agg_metric.get( 'metric').get('value')) self.assertEqual('useast', @@ -387,7 +387,7 @@ class TestFetchQuantityUtilAgg(SparkContextTest): if value.get('metric').get( 'name') == 'cpu.utilized_logical_cores_agg'][0] - self.assertEqual(8.0, + self.assertEqual(7.134214285714285, utilized_cpu_logical_agg_metric.get( 'metric').get('value')) self.assertEqual('useast', diff --git a/tests/unit/usage/test_host_cpu_usage_component.py b/tests/unit/usage/test_host_cpu_usage_component.py index b555240..d704130 100644 --- a/tests/unit/usage/test_host_cpu_usage_component.py +++ b/tests/unit/usage/test_host_cpu_usage_component.py @@ -217,7 +217,7 @@ class SparkTest(SparkContextTest): value.get('metric').get('dimensions').get('host') == 'all'][0] - self.assertEqual(8.0, + self.assertEqual(7.134214285714285, utilized_cpu_logical_agg_metric.get( 'metric').get('value')) self.assertEqual('useast', @@ -258,7 +258,7 @@ class SparkTest(SparkContextTest): value.get('metric').get('dimensions').get('host') == 'test-cp1-comp0333-mgmt'][0] - self.assertEqual(5.0, + self.assertEqual(4.9665, utilized_cpu_logical_agg_metric.get( 'metric').get('value')) self.assertEqual('useast', @@ -299,7 +299,7 @@ class SparkTest(SparkContextTest): value.get('metric').get('dimensions').get('host') == 'test-cp1-comp0027-mgmt'][0] - self.assertEqual(3.0, + self.assertEqual(2.1677142857142853, utilized_cpu_logical_agg_metric.get( 'metric').get('value')) self.assertEqual('useast',