Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramchike committed Nov 16, 2024
2 parents 0037a02 + 82111bd commit eead326
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ TG_CHANNEL_LINK=https://t.me/channel

API_URL=http://127.0.0.1:8000
ROOT_PATH=/api

LOKI_URL=http://loki:3100/loki/api/v1/push
RABBIT_URL=amqp://rabbitmq:5672/
Binary file modified backend/requirements.txt
Binary file not shown.
8 changes: 3 additions & 5 deletions backend/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
TG_CHANNEL_LINK = os.environ.get("TG_CHANNEL_LINK")
TG_API_URL = "https://api.telegram.org/bot" + TG_TOKEN

# ----- [[ TELEGRAM ]] -----

RABBIT_URL = os.environ.get("RABBIT_URL")

# ----- [[ SETTINGS ]] -----

MAX_AVATAR_SIZE = 1024 * 1024 * 3 # Bytes
Expand Down Expand Up @@ -69,4 +65,6 @@
# ----- [[ OTHER ]] -----

API_URL = os.environ.get("API_URL")
ROOT_PATH = os.environ.get("ROOT_PATH", "")
ROOT_PATH = os.environ.get("ROOT_PATH", "")
RABBIT_URL = os.environ.get("RABBIT_URL")
LOKI_URL = os.environ.get("LOKI_URL")
18 changes: 16 additions & 2 deletions backend/src/infrastructure/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from fastapi import FastAPI, APIRouter, Request
from starlette.middleware.cors import CORSMiddleware
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
# from logging_loki import LokiQueueHandler
# from multiprocessing import Queue
import logging

from src.config import ROOT_PATH
from src.config import IS_PROD, LOKI_URL, ROOT_PATH
from src.infrastructure.db import get_session, CTX_SESSION
from src.infrastructure.exc import HTTPError
# from src.infrastructure.utils import PrometheusMiddleware, metrics
Expand Down Expand Up @@ -58,7 +60,19 @@ async def lifespan(app: FastAPI):

app.add_exception_handler(HTTPError, HTTPError.handler)

logging.getLogger("uvicorn.access").addFilter(LoggingFilter(ignoring_log_endpoints))
logger = logging.getLogger("uvicorn.access")
logger.addFilter(LoggingFilter(ignoring_log_endpoints))
# if IS_PROD:
# loki_logs_handler = LokiQueueHandler(
# Queue(-1),
# url=LOKI_URL,
# tags={"application": "mt2107"}
# )
# logger.addHandler(loki_logs_handler)

logging.basicConfig(
format = '[%(asctime)s.%(msecs)03dZ] %(name)s %(levelname)s %(message)s'
)

@app.middleware("http")
async def session_middleware(request: Request, coro):
Expand Down
19 changes: 14 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ services:
rabbitmq:
condition: service_healthy
restart: true
deploy:
resources:
limits:
cpus: '0.3'
memory: 256M
# loki:
# condition: service_started
# deploy:
# resources:
# limits:
# cpus: '0.3'
# memory: 256M

db:
image: postgres:alpine
Expand Down Expand Up @@ -123,6 +125,13 @@ services:
# - '--config.file=/etc/prometheus/prometheus.yml'
# restart: unless-stopped

# loki:
# image: grafana/loki
# container_name: mt2107_loki
# expose:
# - 3100
# restart: unless-stopped

grafana:
image: grafana/grafana
container_name: mt2107_grafana
Expand Down

0 comments on commit eead326

Please sign in to comment.