Реализовать уровень 4: сквозные трассы, SLO, отказы и отчёт
This commit is contained in:
@@ -16,12 +16,25 @@ from collections.abc import AsyncIterator
|
||||
from contextlib import AsyncExitStack
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, BinaryIO
|
||||
from functools import wraps
|
||||
|
||||
from aiobotocore.config import AioConfig
|
||||
from aiobotocore.session import get_session
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
|
||||
from app.config import settings
|
||||
from app.telemetry import span
|
||||
|
||||
|
||||
def observed(operation):
|
||||
"""Export operation/outcome only, never S3 URL, key or credentials."""
|
||||
def decorate(method):
|
||||
@wraps(method)
|
||||
async def run(*args, **kwargs):
|
||||
with span("s3." + operation, {"rpc.system": "aws-api", "rpc.method": operation}):
|
||||
return await method(*args, **kwargs)
|
||||
return run
|
||||
return decorate
|
||||
|
||||
|
||||
logger = logging.getLogger("messenger.storage")
|
||||
@@ -89,6 +102,7 @@ class ObjectStorage:
|
||||
raise StorageUnavailable("S3 client is not started")
|
||||
return self._client
|
||||
|
||||
@observed("PutObject")
|
||||
async def put(
|
||||
self,
|
||||
key: str,
|
||||
@@ -112,6 +126,7 @@ class ObjectStorage:
|
||||
except (BotoCoreError, ClientError, OSError, asyncio.TimeoutError) as exc:
|
||||
raise StorageUnavailable(type(exc).__name__) from exc
|
||||
|
||||
@observed("GetObject")
|
||||
async def open_download(self, key: str) -> tuple[AsyncIterator[bytes], int]:
|
||||
"""GET the object; S3 errors surface here, before any byte is sent."""
|
||||
client = self._require_client()
|
||||
@@ -136,6 +151,7 @@ class ObjectStorage:
|
||||
|
||||
return chunks(), int(response["ContentLength"])
|
||||
|
||||
@observed("DeleteObject")
|
||||
async def delete(self, key: str) -> None:
|
||||
"""Idempotent: deleting a missing key succeeds in S3."""
|
||||
client = self._require_client()
|
||||
@@ -145,6 +161,7 @@ class ObjectStorage:
|
||||
except (BotoCoreError, ClientError, OSError, asyncio.TimeoutError) as exc:
|
||||
raise StorageUnavailable(type(exc).__name__) from exc
|
||||
|
||||
@observed("HeadObject")
|
||||
async def exists(self, key: str) -> bool:
|
||||
client = self._require_client()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user