forked from mtusi2026/mtusi2026lab7
ЛР 7: реализация мессенджера и сценарии проверки
This commit is contained in:
@@ -0,0 +1,354 @@
|
||||
{
|
||||
"uid": "messenger-mtusi",
|
||||
"title": "Мессенджер МТУСИ",
|
||||
"tags": [
|
||||
"mtusi"
|
||||
],
|
||||
"schemaVersion": 40,
|
||||
"refresh": "10s",
|
||||
"time": {
|
||||
"from": "now-15m",
|
||||
"to": "now"
|
||||
},
|
||||
"panels": [
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "API – запросы в секунду",
|
||||
"id": 1,
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(messenger_http_requests_total{route!~\"/health/.*\"}[1m]))",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "API – доля 5xx",
|
||||
"id": 2,
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(messenger_http_requests_total{status_class=\"5xx\",route!~\"/health/.*\"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total{route!~\"/health/.*\"}[1m])),0.001)",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "API – задержка",
|
||||
"id": 3,
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 7,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5,sum by(le)(rate(messenger_http_duration_seconds_bucket{route!~\"/health/.*\"}[2m])))",
|
||||
"legendFormat": "p50"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95,sum by(le)(rate(messenger_http_duration_seconds_bucket{route!~\"/health/.*\"}[2m])))",
|
||||
"legendFormat": "p95"
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99,sum by(le)(rate(messenger_http_duration_seconds_bucket{route!~\"/health/.*\"}[2m])))",
|
||||
"legendFormat": "p99"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Worker – задачи по исходу, в секунду",
|
||||
"id": 4,
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 7,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "ops"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by(outcome)(rate(messenger_jobs_total[1m]))",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Worker – p95 обработки",
|
||||
"id": 5,
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 14,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95,sum by(le)(rate(messenger_job_duration_seconds_bucket[2m])))",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Время до ready – p95",
|
||||
"id": 6,
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 14,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95,sum by(le)(rate(messenger_time_to_ready_seconds_bucket[2m])))",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Очередь – глубина",
|
||||
"id": 7,
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 21,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max by(queue)(messenger_queue_depth)",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Возраст старейшей задачи",
|
||||
"id": 8,
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 21,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max by(queue)(messenger_oldest_job_age_seconds)",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Пул PostgreSQL",
|
||||
"id": 9,
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 28,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by(role)(messenger_db_pool_used)",
|
||||
"legendFormat": "занято {{role}}"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum by(role)(messenger_db_pool_waiting)",
|
||||
"legendFormat": "ожидание {{role}}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Загрузка worker",
|
||||
"id": 10,
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 28,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max(messenger_worker_busy)",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "RSS процесса",
|
||||
"id": 11,
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 35,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "bytes"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max by(role)(messenger_process_rss_bytes)",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "CPU процесса",
|
||||
"id": 12,
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 35,
|
||||
"w": 12,
|
||||
"h": 7
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "cores"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by(role)(rate(messenger_process_cpu_time_seconds[1m]))",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: messenger
|
||||
type: file
|
||||
folder: MTUSI
|
||||
options: {path: /var/lib/grafana/dashboards}
|
||||
@@ -0,0 +1,5 @@
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- {name: Prometheus, uid: prometheus, type: prometheus, access: proxy, url: "http://prometheus:9090", isDefault: true}
|
||||
- {name: Loki, uid: loki, type: loki, access: proxy, url: "http://loki:3100"}
|
||||
- {name: Tempo, uid: tempo, type: tempo, access: proxy, url: "http://tempo:3200"}
|
||||
@@ -0,0 +1,31 @@
|
||||
global
|
||||
maxconn 128
|
||||
log stdout format raw local0
|
||||
|
||||
defaults
|
||||
mode http
|
||||
log global
|
||||
timeout connect 1s
|
||||
timeout client 15s
|
||||
timeout server 15s
|
||||
timeout http-request 8s
|
||||
timeout queue 2s
|
||||
timeout check 1s
|
||||
retries 0
|
||||
|
||||
resolvers docker
|
||||
nameserver internal 127.0.0.11:53
|
||||
resolve_retries 2
|
||||
timeout resolve 500ms
|
||||
timeout retry 500ms
|
||||
hold valid 2s
|
||||
|
||||
frontend public
|
||||
bind :8443 ssl crt /run/secrets/public_pem ssl-min-ver TLSv1.2 no-tls-tickets
|
||||
default_backend messenger
|
||||
|
||||
backend messenger
|
||||
balance roundrobin
|
||||
option httpchk GET /health/ready
|
||||
http-check expect status 200
|
||||
server-template api 8 api:8080 ssl verify required verifyhost api ca-file /run/secrets/lab_ca crt /run/secrets/lb_pem sni str(api) check-sni api check inter 500ms fall 2 rise 1 resolvers docker resolve-prefer ipv4 init-addr none
|
||||
@@ -0,0 +1,3 @@
|
||||
path "messenger/data/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
path "messenger/data/relay" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
ui = true
|
||||
disable_mlock = true
|
||||
api_addr = "https://bao:8200"
|
||||
|
||||
storage "file" {
|
||||
path = "/openbao/file"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_min_version = "tls12"
|
||||
tls_cert_file = "/run/secrets/bao_server_crt"
|
||||
tls_key_file = "/run/secrets/bao_server_key"
|
||||
tls_client_ca_file = "/run/secrets/lab_ca"
|
||||
tls_disable_client_certs = false
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
path "messenger/data/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
groups:
|
||||
- name: messenger
|
||||
rules:
|
||||
- alert: MessengerHttpErrorRatioHigh
|
||||
expr: |
|
||||
sum(rate(messenger_http_requests_total{route!~"/health/.*",status_class="5xx"}[1m]))
|
||||
/ clamp_min(sum(rate(messenger_http_requests_total{route!~"/health/.*"}[1m])), 0.001) > 0.10
|
||||
for: 20s
|
||||
labels: {severity: warning}
|
||||
annotations: {summary: "Проверьте trace API и доступность PostgreSQL по readiness."}
|
||||
- alert: MessengerOldestImageJobHigh
|
||||
expr: max(messenger_oldest_job_age_seconds) > 20
|
||||
for: 15s
|
||||
labels: {severity: warning}
|
||||
annotations: {summary: "Проверьте worker, очередь и доступность S3, затем дождитесь уменьшения backlog."}
|
||||
@@ -0,0 +1,46 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1:4318
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 128
|
||||
spike_limit_mib: 24
|
||||
batch:
|
||||
send_batch_size: 128
|
||||
send_batch_max_size: 256
|
||||
timeout: 1s
|
||||
exporters:
|
||||
prometheus:
|
||||
endpoint: 127.0.0.1:8889
|
||||
metric_expiration: 45s
|
||||
otlphttp/loki:
|
||||
endpoint: https://loki:3443/otlp
|
||||
tls: &backend-tls
|
||||
ca_file: /run/secrets/lab_ca
|
||||
cert_file: /run/secrets/collector_client_crt
|
||||
key_file: /run/secrets/collector_client_key
|
||||
timeout: 3s
|
||||
sending_queue: {queue_size: 64, num_consumers: 1}
|
||||
retry_on_failure: {initial_interval: 1s, max_interval: 3s, max_elapsed_time: 10s}
|
||||
otlphttp/tempo:
|
||||
endpoint: https://tempo:44318
|
||||
tls: *backend-tls
|
||||
timeout: 3s
|
||||
sending_queue: {queue_size: 64, num_consumers: 1}
|
||||
retry_on_failure: {initial_interval: 1s, max_interval: 3s, max_elapsed_time: 10s}
|
||||
service:
|
||||
telemetry:
|
||||
metrics:
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 127.0.0.1
|
||||
port: 8888
|
||||
pipelines:
|
||||
metrics: {receivers: [otlp], processors: [memory_limiter, batch], exporters: [prometheus]}
|
||||
logs: {receivers: [otlp], processors: [memory_limiter, batch], exporters: [otlphttp/loki]}
|
||||
traces: {receivers: [otlp], processors: [memory_limiter, batch], exporters: [otlphttp/tempo]}
|
||||
@@ -0,0 +1,32 @@
|
||||
auth_enabled: false
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
http_listen_port: 3100
|
||||
common:
|
||||
instance_addr: 127.0.0.1
|
||||
path_prefix: /loki
|
||||
storage:
|
||||
filesystem:
|
||||
chunks_directory: /loki/chunks
|
||||
rules_directory: /loki/rules
|
||||
replication_factor: 1
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
schema_config:
|
||||
configs:
|
||||
- from: "2024-01-01"
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index: {prefix: index_, period: 24h}
|
||||
limits_config:
|
||||
allow_structured_metadata: true
|
||||
otlp_config:
|
||||
resource_attributes:
|
||||
ignore_defaults: true
|
||||
attributes_config:
|
||||
- action: index_label
|
||||
attributes: [service.name]
|
||||
analytics:
|
||||
reporting_enabled: false
|
||||
@@ -0,0 +1,18 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
rule_files: [/etc/prometheus/alerts.yml]
|
||||
scrape_configs:
|
||||
- job_name: messenger
|
||||
scheme: https
|
||||
tls_config: &collector-tls
|
||||
ca_file: /run/secrets/lab_ca
|
||||
cert_file: /run/secrets/prom_client_crt
|
||||
key_file: /run/secrets/prom_client_key
|
||||
static_configs:
|
||||
- targets: [collector:9443]
|
||||
- job_name: collector
|
||||
scheme: https
|
||||
tls_config: *collector-tls
|
||||
static_configs:
|
||||
- targets: [collector:9444]
|
||||
@@ -0,0 +1,21 @@
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
http_listen_port: 3200
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1:4318
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
local:
|
||||
path: /var/tempo/blocks
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 72h
|
||||
usage_report:
|
||||
reporting_enabled: false
|
||||
@@ -0,0 +1,5 @@
|
||||
local all all trust
|
||||
hostssl all all 0.0.0.0/0 scram-sha-256
|
||||
hostssl all all ::/0 scram-sha-256
|
||||
hostnossl all all 0.0.0.0/0 reject
|
||||
hostnossl all all ::/0 reject
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /tmp/pg-tls
|
||||
cp /run/secrets/db_crt /tmp/pg-tls/server.crt
|
||||
cp /run/secrets/db_key /tmp/pg-tls/server.key
|
||||
chown postgres:postgres /tmp/pg-tls/server.key /tmp/pg-tls/server.crt
|
||||
chmod 0600 /tmp/pg-tls/server.key
|
||||
exec docker-entrypoint.sh postgres + -c ssl=on + -c ssl_cert_file=/tmp/pg-tls/server.crt + -c ssl_key_file=/tmp/pg-tls/server.key + -c hba_file=/etc/postgresql/pg_tls_hba.conf
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{"Effect": "Allow", "Action": ["s3:ListBucket"], "Resource": ["arn:aws:s3:::attachments"]},
|
||||
{"Effect": "Allow", "Action": ["s3:PutObject"], "Resource": ["arn:aws:s3:::attachments/staging/*"]},
|
||||
{"Effect": "Allow", "Action": ["s3:GetObject"],
|
||||
"Resource": ["arn:aws:s3:::attachments/original/*", "arn:aws:s3:::attachments/results/*"]}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
export HOME=/tmp
|
||||
export SSL_CERT_FILE=/run/secrets/lab_ca
|
||||
rc alias set lab https://s3:9000 "$RUSTFS_ACCESS_KEY" "$RUSTFS_SECRET_KEY"
|
||||
rc mb --ignore-existing lab/attachments
|
||||
access=$(cat /run/secrets/s3_access)
|
||||
secret=$(cat /run/secrets/s3_secret)
|
||||
rc admin user add lab/ "$access" "$secret"
|
||||
rc admin policy create lab/ messenger-objects /bootstrap/api-policy.json
|
||||
rc admin policy attach lab/ messenger-objects --user "$access"
|
||||
worker=$(cat /run/secrets/worker_s3_access)
|
||||
worker_secret=$(cat /run/secrets/worker_s3_secret)
|
||||
rc admin user add lab/ "$worker" "$worker_secret"
|
||||
rc admin policy create lab/ messenger-worker /bootstrap/worker-policy.json
|
||||
rc admin policy attach lab/ messenger-worker --user "$worker"
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{"Effect": "Allow", "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::attachments/staging/*"]},
|
||||
{"Effect": "Allow", "Action": ["s3:PutObject"], "Resource": ["arn:aws:s3:::attachments/results/*"]}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user