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
47 changes: 44 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,55 @@ version: '3.9'

services:
web:
container_name: web
build:
context: .
dockerfile: ./Dockerfile
ports:
- "8000:8000"
image: ghcr.io/procollab-github/api:latest
restart: always
env_file:
- .env
environment:
HOST: 0.0.0.0
HOST: 0.0.0.0
grafana:
container_name: grafana
image: grafana/grafana:latest
ports:
- "3000"
volumes:
- grafana-data:/var/lib/grafana
- grafana-configs:/etc/grafana
environment:
- GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s:%(http_port)s/grafana
- GF_SERVER_SERVE_FROM_SUB_PATH=true
prometheus:
container_name: prometheus
image: prom/prometheus:v2.36.0
ports:
- "9090"
volumes:
- prom-data:/prometheus
- ./prometheus:/etc/prometheus
node-exporter:
image: prom/node-exporter:v1.3.1
ports:
- "9100"
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.mount-points-exclude'
- '^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)'
nginx:
container_name: nginx
build: ./nginx
ports:
- 8000:80
volumes:
grafana-data:
grafana-configs:
prom-data:
prom-configs:
4 changes: 4 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.21-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
19 changes: 19 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {

listen 80;

server_name api.procollab.ru;
client_max_body_size 100M;

location / {
proxy_pass http://web:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}

location /grafana {
proxy_pass http://grafana:3000;
proxy_set_header Host $host;
}
}
30 changes: 29 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 33 additions & 4 deletions procollab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from decouple import config
from sentry_sdk.integrations.django import DjangoIntegration


mimetypes.add_type("application/javascript", ".js", True)
mimetypes.add_type("text/css", ".css", True)
mimetypes.add_type("text/html", ".html", True)
Expand All @@ -26,7 +27,9 @@
TAGGIT_CASE_INSENSITIVE = True

CSRF_TRUSTED_ORIGINS = [
"http://localhost",
"http://localhost:8000",
"http://127.0.0.1:8000",
"http://0.0.0.0:8000",
"https://api.procollab.ru",
"https://procollab.ru",
"https://www.procollab.ru",
Expand All @@ -40,7 +43,9 @@
"0.0.0.0",
"api.procollab.ru",
"app.procollab.ru",
"dev.procollab.ru",
"procollab.ru",
"web", # From Docker
]

PASSWORD_HASHERS = [
Expand Down Expand Up @@ -99,9 +104,11 @@
"drf_yasg",
"channels",
"taggit",
"django_prometheus",
]

MIDDLEWARE = [
"django_prometheus.middleware.PrometheusBeforeMiddleware",
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand All @@ -112,6 +119,7 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django_prometheus.middleware.PrometheusAfterMiddleware",
]

# CORS_ALLOWED_ORIGINS = [
Expand Down Expand Up @@ -169,14 +177,15 @@
if DEBUG:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"ENGINE": "django_prometheus.db.backends.sqlite3",
"NAME": "db.sqlite3",
}
}

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"BACKEND": "django_prometheus.cache.backends.filebased.FileBasedCache",
"LOCATION": "/var/tmp/django_cache",
}
}

Expand Down Expand Up @@ -215,7 +224,7 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"ENGINE": "django_prometheus.db.backends.postgresql",
"NAME": config("DATABASE_NAME", default="postgres", cast=str),
"USER": config("DATABASE_USER", default="postgres", cast=str),
"PASSWORD": config("DATABASE_PASSWORD", default="postgres", cast=str),
Expand Down Expand Up @@ -313,3 +322,23 @@
SELECTEL_CONTAINER_PASSWORD = config(
"SELECTEL_CONTAINER_PASSWORD", cast=str, default="PWD"
)

PROMETHEUS_LATENCY_BUCKETS = (
0.01,
0.025,
0.05,
0.075,
0.1,
0.25,
0.5,
0.75,
1.0,
2.5,
5.0,
7.5,
10.0,
25.0,
50.0,
75.0,
float("inf"),
)
Comment on lines +326 to +344
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Странно, что это нужно указывать в настройках
Я бы такие бакеты поставил, но в целом as you wish
0.1
0.5
1
3
5
10

10

1 change: 1 addition & 0 deletions procollab/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("api/token/verify/", TokenVerifyView.as_view(), name="token_verify"),
path("", include("metrics.urls", namespace="metrics")),
path("django_prometheus/", include("django_prometheus.urls")),
]

if settings.DEBUG:
Expand Down
10 changes: 10 additions & 0 deletions prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: monitoring
metrics_path: /django_prometheus/metrics
static_configs:
- targets:
- web:8000
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ python-magic = "^0.4.27"
python-magic-bin = {version = "^0.4.14", markers = "sys_platform == 'win32'"}
requests = "^2.31.0"
coreapi = "^2.3.3"
django-prometheus = "^2.3.1"


[build-system]
Expand Down
38 changes: 38 additions & 0 deletions users/migrations/0039_alter_customuser_first_name_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.3 on 2023-07-25 20:49

from django.db import migrations, models
import users.validators


class Migration(migrations.Migration):

dependencies = [
("users", "0038_alter_customuser_options_customuser_ordering_score"),
]

operations = [
migrations.AlterField(
model_name="customuser",
name="first_name",
field=models.CharField(
max_length=255, validators=[users.validators.user_name_validator]
),
),
migrations.AlterField(
model_name="customuser",
name="last_name",
field=models.CharField(
max_length=255, validators=[users.validators.user_name_validator]
),
),
migrations.AlterField(
model_name="customuser",
name="patronymic",
field=models.CharField(
blank=True,
max_length=255,
null=True,
validators=[users.validators.user_name_validator],
),
),
]