Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion nuclia_e2e/nuclia_e2e/tests/nua/test_da_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def wait_for_task_completion(
client: aiohttp.ClientSession,
dataset_id: str,
task_id: str,
max_duration: int = 300,
max_duration: int = 60 * 8, # 8 minutes
):
start_time = asyncio.get_event_loop().time()
while True:
Expand Down
2 changes: 2 additions & 0 deletions nuclia_e2e/nuclia_e2e/tests/test_kb_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import asyncio
import backoff
import base64
import httpx
import pytest

Logger = Callable[[str], None]
Expand Down Expand Up @@ -95,13 +96,14 @@
assert success, "File was not indexed in time, not enough paragraphs found on resource"


@backoff.on_exception(backoff.constant, (httpx.ReadError, ClientError), max_tries=3, interval=5)
async def run_test_import_kb(regional_api_config, ndb: AsyncNucliaDBClient, logger: Logger):
"""
Imports a kb with three resources and some labelsets already created
"""
kb = AsyncNucliaKB()

response = await kb.imports.start(path=f"{ASSETS_FILE_PATH}/e2e.financial.mini.export", ndb=ndb)

Check failure on line 106 in nuclia_e2e/nuclia_e2e/tests/test_kb_features.py

View workflow job for this annotation

GitHub Actions / JUnit Test Report

test_kb_features.test_kb_usage[gke-stage-1]

httpx.ReadError
Raw output
@contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
>           yield

nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_transports/default.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_transports/default.py:394: in handle_async_request
    resp = await self._pool.handle_async_request(req)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py:256: in handle_async_request
    raise exc from None
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py:236: in handle_async_request
    response = await connection.handle_async_request(
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/connection.py:103: in handle_async_request
    return await self._connection.handle_async_request(request)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py:136: in handle_async_request
    raise exc
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py:106: in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py:177: in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py:217: in _receive_event
    data = await self._network_stream.read(
nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_backends/anyio.py:32: in read
    with map_exceptions(exc_map):
/usr/lib/python3.10/contextlib.py:153: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

map = {<class 'TimeoutError'>: <class 'httpcore.ReadTimeout'>, <class 'anyio.BrokenResourceError'>: <class 'httpcore.ReadErr... 'anyio.ClosedResourceError'>: <class 'httpcore.ReadError'>, <class 'anyio.EndOfStream'>: <class 'httpcore.ReadError'>}

    @contextlib.contextmanager
    def map_exceptions(map: ExceptionMapping) -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from exc
E                   httpcore.ReadError

nuclia_e2e/.venv/lib/python3.10/site-packages/httpcore/_exceptions.py:14: ReadError

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

request = <FixtureRequest for <Function test_kb_usage[gke-stage-1]>>
regional_api_config = ZoneConfig(name='gke-stage-1', zone_slug='europe-1', test_kb_slug='nuclia-e2e-live-europe-1', permanent_nua_key='eyJhb...1f-4197-be76-6fc611082fe8', grafana_url='http://platform.grafana.nuclia.com', tempo_datasource_id='P95F6455D1776E941'))
global_api = <nuclia_e2e.tests.conftest.GlobalAPI object at 0x7f4367db6110>

    @pytest.mark.asyncio_cooperative
    async def test_kb_usage(
        request: pytest.FixtureRequest, regional_api_config: ZoneConfig, global_api: GlobalAPI
    ):
        """
        This test is conducted separately from the main test_kb to ensure more deterministic results. The retries
        that typically occur in test_kb make it difficult to achieve the level of precision required for this
        validation.
    
        In this test, the actual response from the ask endpoint is not relevant—as long as the request consumes
        input tokens, the test remains valid. The primary objective is to verify that all usage data generated by
        an ask request is properly collected and integrated into the audit event. This includes tracking data from
        NucliaDB, Predict, and ensuring it aligns with the data recorded by Accounting.
    
        Since usage tracking is performed on a per-request basis, this test assumes that only a single request is
        being made and that the data captured by Accounting corresponds solely to that request.
        """
    
        def logger(msg):
            print(f"{request.node.name} ::: {msg}")
    
        zone = regional_api_config.zone_slug
        assert regional_api_config.global_config is not None
        account = regional_api_config.global_config.permanent_account_id  # noqa: F841
        auth = get_auth()
        kb_slug = f"{regional_api_config.test_kb_slug}-test_kb_usage"
    
        # Make sure the kb used for this test is deleted, as the slug is reused:
        old_kbid = await get_kbid_from_slug(regional_api_config.zone_slug, kb_slug)
        if old_kbid is not None:
            await AsyncNucliaKBS().delete(zone=regional_api_config.zone_slug, id=old_kbid)
    
        # Creates a brand new kb that will be used troughout this test
        kbid = await create_test_kb(regional_api_config, kb_slug, logger)
    
        # Configures a nucliadb client defaulting to a specific kb, to be used
        # to override all the sdk endpoints that automagically creates the client
        # as this is incompatible with the cooperative tests
        async_ndb = get_async_kb_ndb_client(zone, kbid, user_token=auth._config.token)
    
        # Import a preexisting export containing several resources (coming from the financial-news kb)
        # and wait for the resources to be completely imported
>       await run_test_import_kb(regional_api_config, async_ndb, logger)

nuclia_e2e/nuclia_e2e/tests/test_kb_features.py:909: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
nuclia_e2e/.venv/lib/python3.10/site-packages/backoff/_async.py:151: in retry
    ret = await target(*args, **kwargs)
nuclia_e2e/nuclia_e2e/tests/test_kb_features.py:106: in run_test_import_kb
    response = await kb.imports.start(path=f"{ASSETS_FILE_PATH}/e2e.financial.mini.export", ndb=ndb)
nuclia_e2e/.venv/lib/python3.10/site-packages/nuclia/decorators.py:44: in async_wrapper_checkout
    return await func(*args, **kwargs)
nuclia_e2e/.venv/lib/python3.10/site-packages/nuclia/sdk/export_import.py:209: in start
    response = await ndb.ndb.start_import(kbid=ndb.kbid, content=iterator(path))
nuclia_e2e/.venv/lib/python3.10/site-packages/nucliadb_sdk/v2/sdk.py:756: in _func
    resp = await self._request(
nuclia_e2e/.venv/lib/python3.10/site-packages/nucliadb_sdk/v2/sdk.py:1180: in _request
    response: httpx.Response = await getattr(self.session, method.lower())(url, **opts)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_client.py:1859: in post
    return await self.request(
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_client.py:1540: in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_client.py:1629: in send
    response = await self._send_handling_auth(
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_client.py:1657: in _send_handling_auth
    response = await self._send_handling_redirects(
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_client.py:1694: in _send_handling_redirects
    response = await self._send_single_request(request)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_client.py:1730: in _send_single_request
    response = await transport.handle_async_request(request)
nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_transports/default.py:393: in handle_async_request
    with map_httpcore_exceptions():
/usr/lib/python3.10/contextlib.py:153: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
            yield
        except Exception as exc:
            mapped_exc = None
    
            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc
    
            if mapped_exc is None:  # pragma: no cover
                raise
    
            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ReadError

nuclia_e2e/.venv/lib/python3.10/site-packages/httpx/_transports/default.py:118: ReadError
logger(f"Import started with id {response.import_id}")

def resources_are_imported(resources):
Expand Down
Loading