Boavizta / boaviztapi

🛠 Giving access to BOAVIZTA reference data and methodologies trough a RESTful API
GNU Affero General Public License v3.0
75 stars 25 forks source link

cloud/instance with is4gen.8xlarge leads to "ZeroDivisionError: float division by zero" #285

Open bpetit opened 7 months ago

bpetit commented 7 months ago

Bug description

Querying the cloud/instance route with provider AWS and instance = "is4gen.8xlarge" leads to this 500 internal error with this trace:

Traceback (most recent call last): File "/app/boaviztapi/main.py", line 45, in catch_exceptions_middleware return await call_next(request) File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 84, in call_next raise app_exc File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 70, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/usr/local/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in call raise exc File "/usr/local/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in call await self.app(scope, receive, sender) File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call raise e File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 718, in call await route.handle(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 66, in app response = await func(request) File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 237, in app raw_response = await run_endpoint_function( File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 163, in run_endpoint_function return await dependant.call(**values) File "/app/boaviztapi/routers/cloud_router.py", line 50, in instance_cloud_impact return await cloud_instance_impact( File "/app/boaviztapi/routers/cloud_router.py", line 107, in cloud_instance_impact impacts = compute_impacts(model=cloud_instance, selected_criteria=criteria, duration=duration) File "/app/boaviztapi/service/impacts_computation.py", line 50, in compute_impacts compute_single_impact(model, phase, criteria.name, duration) File "/app/boaviztapi/service/impacts_computation.py", line 25, in compute_single_impact impact, min_impact, max_impact, warnings = impact_function(criteria, duration, model) File "/app/boaviztapi/service/impacts_computation.py", line 453, in cloud_impact_embedded default_allocation = cloud_instance.vcpu.value / cloud_instance.platform.get_total_vcpu() ZeroDivisionError: float division by zero

This seems to be because is4gen.8xlarge server/platform has a value of 0 CPU units : https://github.com/Boavizta/boaviztapi/blob/a97f79bf89ad5d48b279183e0a5de3e80da746e1/boaviztapi/data/archetypes/server.csv#L84

As the is4gen.8xlarge instance has 32 vcpus but the server's "Annapurna Labs Graviton2" CPU has 64 logical cores, it seems that the script generating server.csv record sets 0 (maybe a round(32/64) somewhere ?) as CPU.units, which leads to the error.

To Reproduce

Query cloud/instance with provider = aws and instance_type = "is4gen.8xlarge"

Expected behavior

200 OK with a result

JacobValdemar commented 5 months ago

The following instance types produce an Internal Server Error (version 1.2.4):

g3.4xlarge
g3.8xlarge
g3.16xlarge
g3s.xlarge
is4gen.medium
is4gen.large
is4gen.xlarge
is4gen.2xlarge
is4gen.4xlarge
is4gen.8xlarge
m1.medium
m1.small
m1.large
m1.xlarge
m7gd.medium
m7gd.large
m7gd.xlarge
m7gd.2xlarge
m7gd.4xlarge
m7gd.8xlarge
m7gd.12xlarge
m7gd.16xlarge
mac2.metal
ra3.4xlarge
ra3.16xlarge
bpetit commented 5 months ago

Hi ! it might be a duplicate of https://github.com/Boavizta/boaviztapi/issues/284 :)

The current issue is specifically about a ZeroDivisionError

JacobValdemar commented 5 months ago

Ah, my bad. Thought it was related 😁

da-ekchajzer commented 1 month ago

Commit : https://github.com/Boavizta/boaviztapi/commit/1dbbead88073077953d09c5aff7f725505714f9f fixes this bug.