Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[batch] Mitigate too many resources with same prices #12654

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions batch/batch/driver/billing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand All @@ -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
):
Expand Down