cooling-singapore / saas-middleware

Simulation-as-a-Service (SaaS) Middleware
MIT License
0 stars 0 forks source link

Make endpoints/proxies more robust #246

Closed HeikoAydt closed 1 month ago

HeikoAydt commented 2 years ago

Feature description Sometimes endpoint calls seem to not work for unknown reasons. It happens only rarely and probably has something to do with networking. The exceptions generated as a result throw off the applications relying on them. In principle this problem can be addressed on the application level. However, it would be better to make it more robust on the service level.

Pitch The infrastructure layer (SaaS service) needs to be as robust as possible. Making endpoints and related proxies more robust would greatly contribute to that.

Suggestions (if any) None - need to think about it.

Exception Example

2022-07-15 04:52:20.579 [ERROR] [saas.rest.service] Exception on /api/v1/rti/job/o4fBN8Tn [GET]
Traceback (most recent call last):
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/saas/rest/request_manager.py", line 232, in wrapper
    response: (Response, int) = func(*args, **kwargs)
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/saas/rest/request_manager.py", line 220, in wrapper
    return func(*args, **kwargs)
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/saas/rti/blueprint.py", line 140, in get_job_info
    job_info = self._node.rti.get_job_info(job_id)
  File "/Users/x/repositories/duct-servers/venv/lib/python3.9/site-packages/saas/rti/service.py", line 275, in get_job_info
    status = json.load(f)
  File "/usr/local/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/local/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
HeikoAydt commented 2 years ago

The whole JSON encoding/decoding thing should now be fixed by using FastAPI and Pydantic throughout. @reyery any thoughts?

HeikoAydt commented 1 month ago

Obsolete.