From 5d90856d364a391ef6e3fe92f04b1e4d23aff0d0 Mon Sep 17 00:00:00 2001 From: Jackie Goldstein Date: Fri, 3 Feb 2023 15:51:51 -0500 Subject: [PATCH 1/3] [batch] Mitigate too many resources with same prices --- batch/batch/driver/billing_manager.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/batch/batch/driver/billing_manager.py b/batch/batch/driver/billing_manager.py index bfe57930cdc..0ff0901d974 100644 --- a/batch/batch/driver/billing_manager.py +++ b/batch/batch/driver/billing_manager.py @@ -67,6 +67,7 @@ async def _refresh_resources_from_retail_prices(self, prices: List[Price]): if current_resource_rate is None: resource_updates.append((resource_name, latest_resource_rate)) + # we compare to a precision of 1e-20 as there is some loss in precision when going back and forth between MySQL and Python elif abs(current_resource_rate - latest_resource_rate) > 1e-20: log.error( f'resource {resource_name} does not have the latest rate in the database for ' @@ -75,6 +76,15 @@ async def _refresh_resources_from_retail_prices(self, prices: List[Price]): ) continue + # this prevents having too many resources in the database with redundant information + if current_product_version and current_product_version != latest_product_version: + # we compare to a precision of 1e-20 as there is some loss in precision when going back and forth between MySQL and Python + if current_resource_rate is not None and abs(current_resource_rate - latest_resource_rate) < 1e-20: + log.info( + f'ignoring price update for product {product} -- the latest rate is equal to the previous rate' + ) + continue + if price.is_current_price() and ( current_product_version is None or current_product_version != latest_product_version ): From fa72b317b4a3d0ecd260b4147975390c311ed058 Mon Sep 17 00:00:00 2001 From: Jackie Goldstein Date: Mon, 6 Feb 2023 10:07:03 -0500 Subject: [PATCH 2/3] add equality chcks --- batch/batch/driver/billing_manager.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/batch/batch/driver/billing_manager.py b/batch/batch/driver/billing_manager.py index 0ff0901d974..0554d5ff4f1 100644 --- a/batch/batch/driver/billing_manager.py +++ b/batch/batch/driver/billing_manager.py @@ -67,8 +67,7 @@ async def _refresh_resources_from_retail_prices(self, prices: List[Price]): if current_resource_rate is None: resource_updates.append((resource_name, latest_resource_rate)) - # we compare to a precision of 1e-20 as there is some loss in precision when going back and forth between MySQL and Python - elif abs(current_resource_rate - latest_resource_rate) > 1e-20: + elif current_resource_rate != latest_resource_rate: log.error( f'resource {resource_name} does not have the latest rate in the database for ' f'version {current_product_version}: {current_resource_rate} vs {latest_resource_rate}; ' @@ -76,10 +75,9 @@ async def _refresh_resources_from_retail_prices(self, prices: List[Price]): ) continue - # this prevents having too many resources in the database with redundant information if current_product_version and current_product_version != latest_product_version: - # we compare to a precision of 1e-20 as there is some loss in precision when going back and forth between MySQL and Python - if current_resource_rate is not None and abs(current_resource_rate - latest_resource_rate) < 1e-20: + # this prevents having too many resources in the database with redundant information + if current_resource_rate is not None and current_resource_rate == latest_resource_rate: log.info( f'ignoring price update for product {product} -- the latest rate is equal to the previous rate' ) From fb8395321cedd2266440acf88b956ece0bd16c4c Mon Sep 17 00:00:00 2001 From: Jackie Goldstein Date: Mon, 6 Feb 2023 12:12:37 -0500 Subject: [PATCH 3/3] fix --- batch/batch/driver/billing_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/batch/batch/driver/billing_manager.py b/batch/batch/driver/billing_manager.py index 0554d5ff4f1..3423f228dd7 100644 --- a/batch/batch/driver/billing_manager.py +++ b/batch/batch/driver/billing_manager.py @@ -67,7 +67,7 @@ async def _refresh_resources_from_retail_prices(self, prices: List[Price]): if current_resource_rate is None: resource_updates.append((resource_name, latest_resource_rate)) - elif current_resource_rate != latest_resource_rate: + elif current_product_version == latest_product_version and current_resource_rate != latest_resource_rate: log.error( f'resource {resource_name} does not have the latest rate in the database for ' f'version {current_product_version}: {current_resource_rate} vs {latest_resource_rate}; ' @@ -77,7 +77,7 @@ async def _refresh_resources_from_retail_prices(self, prices: List[Price]): if current_product_version and current_product_version != latest_product_version: # this prevents having too many resources in the database with redundant information - if current_resource_rate is not None and current_resource_rate == latest_resource_rate: + if current_resource_rate == latest_resource_rate: log.info( f'ignoring price update for product {product} -- the latest rate is equal to the previous rate' )