Skip to content
Merged
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
File renamed without changes.
5 changes: 4 additions & 1 deletion k8s/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: app-container
image: varenikvkusny/fastapi-with-bot:1.0
image: varenikvkusny/fastapi-with-bot:1.2
resources:
requests:
memory: "64Mi"
Expand Down Expand Up @@ -64,6 +64,9 @@ kind: Service
metadata:
name: app-service
namespace: fastapi-with-bot
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
spec:
selector:
app: app
Expand Down
2 changes: 1 addition & 1 deletion k8s/bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: app-container
image: varenikvkusny/fastapi-with-bot:1.0
image: varenikvkusny/fastapi-with-bot:1.2

command: ["python", "-m", "src.tg_bot.main_bot"]

Expand Down
40 changes: 40 additions & 0 deletions k8s/grafana-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana-deployment
namespace: fastapi-with-bot
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
containers:
- name: grafana
image: grafana/grafana:latest
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "256Mi"
cpu: "250m"
ports:
- containerPort: 3000

---
apiVersion: v1
kind: Service
metadata:
name: grafana-service
namespace: fastapi-with-bot
spec:
selector:
app: grafana
ports:
- port: 3000
targetPort: 3000
2 changes: 1 addition & 1 deletion k8s/migration-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:

containers:
- name: migration-container
image: varenikvkusny/fastapi-with-bot:1.0
image: varenikvkusny/fastapi-with-bot:1.2
command: ["alembic", "upgrade", "head"]

envFrom:
Expand Down
17 changes: 17 additions & 0 deletions k8s/prometheus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
namespace: fastapi-with-bot
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'kubernetes-services'
kubernetes_sd_configs:
- role: service
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: true
51 changes: 51 additions & 0 deletions k8s/prometheus-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: fastapi-with-bot
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
serviceAccountName: prometheus
containers:
- name: prometheus-container
image: prom/prometheus:latest
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "256Mi"
cpu: "250m"
ports:
- containerPort: 9090
args:
- "--config.file=/etc/prometheus/prometheus.yml"
volumeMounts:
- name: prometheus-volume
mountPath: /etc/prometheus/

volumes:
- name: prometheus-volume
configMap:
name: prometheus-config

---
apiVersion: v1
kind: Service
metadata:
name: prometheus-service
namespace: fastapi-with-bot
spec:
selector:
app: prometheus
ports:
- port: 9090
targetPort: 9090
33 changes: 33 additions & 0 deletions k8s/prometheus-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus
namespace: fastapi-with-bot

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: prometheus
rules:
- apiGroups: [""]
resources:
- nodes
- pods
- services
- endpoints
verbs: ["get", "list", "watch"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: prometheus
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: prometheus
subjects:
- kind: ServiceAccount
name: prometheus
namespace: fastapi-with-bot
Binary file modified requirements.txt
Binary file not shown.
18 changes: 12 additions & 6 deletions src/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import redis.asyncio as redis
from fastapi import FastAPI
from contextlib import asynccontextmanager
from prometheus_fastapi_instrumentator import Instrumentator
from .routers import auth, posts
from . import clients
from .config import get_settings
Expand All @@ -10,21 +11,26 @@

logging.basicConfig(level=logging.INFO)


@asynccontextmanager
async def lifespan(app: FastAPI):

logging.info('Приложение запускается')

logging.info('Инициализирую redis_client')
logging.info("Приложение запускается")

clients.redis_client = redis.from_url(settings.redis_url, encoding='utf-8', decode_responses=True)
logging.info("Инициализирую redis_client")

clients.redis_client = redis.from_url(
settings.redis_url, encoding="utf-8", decode_responses=True
)

yield

logging.info('Приложение остановлено')
logging.info("Приложение остановлено")


app = FastAPI(lifespan=lifespan)
instrumentator = Instrumentator().instrument(app)
instrumentator.expose(app)

app.include_router(auth.router)
app.include_router(posts.router)
app.include_router(posts.router)