PrefectHQ / prefect-airbyte

https://PrefectHQ.github.io/prefect-airbyte/
Apache License 2.0
40 stars 5 forks source link

Include message in exceptions raised for failed API calls #29

Closed lucienfregosibodyguard closed 1 year ago

lucienfregosibodyguard commented 1 year ago

Hi I've aldready opened this ticket regarding timeout between Prefect and airbyte.

Since the 0.1.1 it works way better thanks for that

However I got a new timeout error with a 409 error code

Encountered exception during execution:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/prefect_airbyte/client.py", line 161, in trigger_manual_sync_connection
    response.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/httpx/_models.py", line 736, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '409 Conflict' for url 'http://airbyte-prd-webapp.airbyte.svc.cluster.local/api/v1/connections/sync/'
For more information check: https://httpstatuses.com/409

Any idea ? This is the first time it happens

desertaxle commented 1 year ago

A 409 indicates that a request can't be completed due a conflict in state. 409 errors aren't documented in the Airbyte API docs, so it's hard to say what cause this error. I expect that the Airbyte server is returning a message that would give info on how to resolve this error, but we aren't bubbling that up. We can enhance our error handling so that in the future we'll be able to see the reason for errors like this.

lucienfregosibodyguard commented 1 year ago

Actually, the root cause is not the 409 error

It's first a timeout issue (with no more details in the error) and then when retrying (specified in with_options) I got a 409 error (which seems to be a side effect).

So it's still a timeout issue like below

Encountered exception during execution:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 33, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1265, in receive
    await self._protocol.read_event.wait()
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 226, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 35, in read
    return b""
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 105, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 84, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 148, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 177, in _receive_event
    data = await self._network_stream.read(
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 35, in read
    return b""
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ReadTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/prefect/engine.py", line 1185, in orchestrate_task_run
    result = await task.fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/prefect_airbyte/connections.py", line 127, in trigger_sync
    job_status, job_created_at, job_updated_at = await airbyte.get_job_status(
  File "/usr/local/lib/python3.9/site-packages/prefect_airbyte/client.py", line 191, in get_job_status
    response = await client.post(get_connection_url, json={"id": job_id})
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1842, in post
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

And here are my trigger_sync definition

        return trigger_sync.with_options(retries=10, retry_delay_seconds=5)(
            connection_id=connection_id,
            poll_interval_s=5,
            status_updates=True,
            airbyte_server_host=urlparse(airbyte_api_base_url).hostname,
            airbyte_server_port=urlparse(airbyte_api_base_url).port,
            timeout=100,
        )

I will try to reduce my poll interval

lucienfregosibodyguard commented 1 year ago

At the end it seems related to a lack of CPU from my airbyte server pod