Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimon committed Nov 18, 2024
1 parent 0561cc0 commit a2cff82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions apitally/client/client_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import random
import time
from functools import partial
from typing import Any, Dict, Iterable, Optional, Tuple
from typing import Any, AsyncIterator, Dict, Optional, Tuple
from uuid import UUID

import backoff
Expand Down Expand Up @@ -62,6 +62,11 @@ async def _run_sync_loop(self) -> None:
except Exception: # pragma: no cover
logger.exception("An error occurred during sync with Apitally hub")

try:
self.request_logger.maybe_rotate_file()
except Exception: # pragma: no cover
logger.exception("An error occurred while rotating request log files")

await asyncio.sleep(1)

def stop_sync_loop(self) -> None:
Expand Down Expand Up @@ -139,7 +144,7 @@ async def _send_sync_data(self, client: httpx.AsyncClient, data: Dict[str, Any])
response = await client.post(url="/sync", json=data)
self._handle_hub_response(response)

async def _send_log_data(self, client: httpx.AsyncClient, uuid: UUID, stream: Iterable[bytes]) -> None:
async def _send_log_data(self, client: httpx.AsyncClient, uuid: UUID, stream: AsyncIterator[bytes]) -> None:
logger.debug("Streaming request log data to Apitally hub")
response = await client.post(url=f"{self.hub_url}/log?uuid={uuid}", content=stream)
self._handle_hub_response(response)

Check warning on line 150 in apitally/client/client_asyncio.py

View check run for this annotation

Codecov / codecov/patch

apitally/client/client_asyncio.py#L148-L150

Added lines #L148 - L150 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions apitally/client/request_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import lru_cache
from io import BufferedReader
from pathlib import Path
from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Tuple, TypedDict
from typing import Any, AsyncIterator, Callable, Dict, List, Mapping, Optional, Tuple, TypedDict
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
from uuid import uuid4

Expand Down Expand Up @@ -126,7 +126,7 @@ def write_line(self, data: bytes) -> None:
def open_compressed(self) -> BufferedReader:
return open(self.path, "rb")

def stream_lines_compressed(self) -> Iterator[bytes]:
async def stream_lines_compressed(self) -> AsyncIterator[bytes]:
with open(self.path, "rb") as fp:
for line in fp:
yield line
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client_request_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def response_dict() -> ResponseDict:
}


def test_request_logger_end_to_end(
async def test_request_logger_end_to_end(
request_logger: RequestLogger, request_dict: RequestDict, response_dict: ResponseDict
):
for _ in range(3):
Expand All @@ -70,7 +70,7 @@ def test_request_logger_end_to_end(
assert file is not None

compressed_data1 = b""
for chunk in file.stream_lines_compressed():
async for chunk in file.stream_lines_compressed():
compressed_data1 += chunk
assert len(compressed_data1) > 0

Expand Down

0 comments on commit a2cff82

Please sign in to comment.