diff --git a/Dockerfile b/Dockerfile index dffc574b..e75cfa50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:alpine WORKDIR /app COPY . /app -RUN apk update && apk add --no-cache build-base git gcc curl python3-dev musl-dev postgresql-dev +RUN apk update && apk add --no-cache build-base icu-data-ru curl python3-dev musl-dev postgresql-dev RUN curl -sSL https://install.python-poetry.org | python ENV PATH="${PATH}:/root/.local/bin" RUN poetry config virtualenvs.create false && poetry install --only main diff --git a/services/auth.py b/services/auth.py index 2ea05478..ea6c6371 100644 --- a/services/auth.py +++ b/services/auth.py @@ -1,11 +1,10 @@ import logging from functools import wraps +import httpx -from aiohttp import ClientSession from starlette.exceptions import HTTPException -from settings import AUTH_SECRET, AUTH_URL - +from settings import ADMIN_SECRET, AUTH_URL logger = logging.getLogger('\t[services.auth]\t') logger.setLevel(logging.DEBUG) @@ -15,16 +14,15 @@ async def request_data(gql, headers=None): if headers is None: headers = {'Content-Type': 'application/json'} try: - # Asynchronous HTTP request to the authentication server - async with ClientSession() as session: - async with session.post(AUTH_URL, json=gql, headers=headers) as response: - if response.status == 200: - data = await response.json() - errors = data.get('errors') - if errors: - logger.error(f'HTTP Errors: {errors}') - else: - return data + async with httpx.AsyncClient() as client: + response = await client.post(AUTH_URL, json=gql, headers=headers) + if response.status_code == 200: + data = response.json() + errors = data.get('errors') + if errors: + logger.error(f'HTTP Errors: {errors}') + else: + return data except Exception as e: # Handling and logging exceptions during authentication check logger.error(f'[services.auth] request_data error: {e}') @@ -70,7 +68,7 @@ async def add_user_role(user_id): operation = 'UpdateUserRoles' headers = { 'Content-Type': 'application/json', - 'x-authorizer-admin-secret': AUTH_SECRET, + 'x-authorizer-admin-secret': ADMIN_SECRET, } variables = {'params': {'roles': 'author, reader', 'id': user_id}} gql = { diff --git a/services/db.py b/services/db.py index c25a6800..ef59a952 100644 --- a/services/db.py +++ b/services/db.py @@ -1,6 +1,4 @@ import logging -import sys -import math import time from typing import Any, Callable, Dict, TypeVar @@ -15,24 +13,20 @@ from settings import DB_URL # Настройка журнала logging.basicConfig(level=logging.DEBUG) +logger = logging.getLogger('\t [services.db]\t') +logger.setLevel(logging.DEBUG) -# Создание обработчика журнала для записи сообщений в stdout -logger = logging.getLogger('sqlalchemy.profiler') -console_handler = logging.StreamHandler(sys.stdout) -console_handler.setLevel(logging.DEBUG) -logger.addHandler(console_handler) @event.listens_for(Engine, 'before_cursor_execute') def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): conn.info.setdefault('query_start_time', []).append(time.time()) + logger.debug(f" {statement}") @event.listens_for(Engine, 'after_cursor_execute') def after_cursor_execute(conn, cursor, statement, parameters, context, executemany): total = time.time() - conn.info['query_start_time'].pop(-1) - total = math.floor(total * 10000) / 10000 - if total > 25: - logger.debug(f'Long running query: {statement}, Execution Time: {total} s') + logger.debug(f' Finished in {total*1000} ms ') engine = create_engine(DB_URL, echo=False, pool_size=10, max_overflow=20) diff --git a/services/sentry.py b/services/sentry.py index 249a565e..19da4942 100644 --- a/services/sentry.py +++ b/services/sentry.py @@ -1,5 +1,4 @@ import sentry_sdk -from sentry_sdk.integrations.aiohttp import AioHttpIntegration from sentry_sdk.integrations.ariadne import AriadneIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration from sentry_sdk.integrations.starlette import StarletteIntegration @@ -23,9 +22,7 @@ def start_sentry(): integrations=[ StarletteIntegration(), AriadneIntegration(), - SqlalchemyIntegration(), - # RedisIntegration(), - AioHttpIntegration() + SqlalchemyIntegration() ] ) except Exception as e: