Защитить мессенджер TLS и OpenBao и проверить отзыв прав worker

This commit is contained in:
2026-11-06 18:32:19 +03:00
parent 20afc2c790
commit 8f82949094
89 changed files with 8323 additions and 76 deletions
+27
View File
@@ -0,0 +1,27 @@
groups:
- name: messenger
rules:
- alert: MessengerHttpErrors
expr: |
sum(rate(messenger_http_requests_total{route!~"/health/.*",status_class="5xx"}[20s]))
/ clamp_min(sum(rate(messenger_http_requests_total{route!~"/health/.*"}[20s])), 0.01)
> 0.05
for: 6s
labels: {severity: warning}
annotations:
summary: More than 5% of business requests have failed for six seconds
runbook: "REPORT.md#диагностика"
- alert: MessengerQueueLag
expr: max(messenger_queue_oldest_seconds) > 5 and max(messenger_queue_depth) > 0
for: 6s
labels: {severity: warning}
annotations:
summary: The oldest unfinished job is more than five seconds old
runbook: "REPORT.md#диагностика"
- alert: MessengerDatabaseErrors
expr: sum(increase(messenger_db_errors_total[20s])) > 0
for: 4s
labels: {severity: warning}
annotations:
summary: PostgreSQL requests are failing
runbook: "REPORT.md#диагностика"
+61
View File
@@ -0,0 +1,61 @@
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 128
spike_limit_mib: 32
batch:
timeout: 500ms
send_batch_size: 128
send_batch_max_size: 256
exporters:
prometheus:
endpoint: 127.0.0.1:18889
metric_expiration: 15s
otlp_http/tempo:
endpoint: https://tempo:4318
tls:
ca_file: /run/tls/trust/ca.crt
cert_file: /run/tls/client/service.crt
key_file: /run/tls/client/service.key
timeout: 2s
sending_queue: {queue_size: 16, num_consumers: 1}
retry_on_failure: {initial_interval: 500ms, max_interval: 2s, max_elapsed_time: 5s}
otlp_http/loki:
endpoint: https://loki:3100/otlp
tls:
ca_file: /run/tls/trust/ca.crt
cert_file: /run/tls/client/service.crt
key_file: /run/tls/client/service.key
timeout: 2s
sending_queue: {queue_size: 16, num_consumers: 1}
retry_on_failure: {initial_interval: 500ms, max_interval: 2s, max_elapsed_time: 5s}
service:
telemetry:
metrics:
readers:
- pull:
exporter:
prometheus:
host: 127.0.0.1
port: 18888
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/loki]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/tempo]
@@ -0,0 +1,453 @@
{
"uid": "messenger",
"title": "MTUSI Messenger",
"schemaVersion": 41,
"version": 1,
"editable": false,
"timezone": "browser",
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
},
"panels": [
{
"id": 1,
"type": "timeseries",
"title": "API / запросов в секунду",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_requests_total{route!~\"/health/.*\"}[30s]))",
"legendFormat": ""
}
]
},
{
"id": 2,
"type": "timeseries",
"title": "API / доля 5xx",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_requests_total{status_class=\"5xx\",route!~\"/health/.*\"}[30s])) / clamp_min(sum(rate(messenger_http_requests_total{route!~\"/health/.*\"}[30s])),0.001)",
"legendFormat": ""
}
]
},
{
"id": 3,
"type": "timeseries",
"title": "API / p50, p95, p99",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_http_duration_seconds_bucket{route!~\"/health/.*\"}[30s])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket{route!~\"/health/.*\"}[30s])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_http_duration_seconds_bucket{route!~\"/health/.*\"}[30s])))",
"legendFormat": "p99"
}
]
},
{
"id": 4,
"type": "timeseries",
"title": "Worker / исходы в секунду",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (rate(messenger_jobs_processed_total[30s]))",
"legendFormat": "{{outcome}}"
}
]
},
{
"id": 5,
"type": "timeseries",
"title": "Worker / p95 по исходу",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le,outcome) (rate(messenger_jobs_duration_seconds_bucket[30s])))",
"legendFormat": ""
}
]
},
{
"id": 6,
"type": "timeseries",
"title": "Upload → ready / p95",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_ready_duration_seconds_bucket[30s])))",
"legendFormat": ""
}
]
},
{
"id": 7,
"type": "timeseries",
"title": "Backlog / заданий",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_depth)",
"legendFormat": ""
}
]
},
{
"id": 8,
"type": "timeseries",
"title": "Возраст старейшего задания",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_oldest_seconds)",
"legendFormat": ""
}
]
},
{
"id": 9,
"type": "timeseries",
"title": "PostgreSQL / занято и ожидает",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "messenger_db_pool_used",
"legendFormat": ""
},
{
"refId": "B",
"expr": "messenger_db_pool_waiting",
"legendFormat": ""
}
]
},
{
"id": 10,
"type": "timeseries",
"title": "Worker / занято и доступно",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(messenger_worker_busy)",
"legendFormat": ""
},
{
"refId": "B",
"expr": "sum(messenger_worker_capacity)",
"legendFormat": ""
}
]
},
{
"id": 11,
"type": "timeseries",
"title": "CPU процессов",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "cores"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "rate(messenger_process_cpu_seconds_total[30s])",
"legendFormat": ""
}
]
},
{
"id": 12,
"type": "timeseries",
"title": "RSS процессов",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 40,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "bytes"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "messenger_process_rss_bytes",
"legendFormat": ""
}
]
},
{
"id": 13,
"type": "timeseries",
"title": "Потери экспорта Collector",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (exporter) (increase(otelcol_exporter_send_failed_spans_total[30s]))",
"legendFormat": ""
},
{
"refId": "B",
"expr": "sum by (exporter) (increase(otelcol_exporter_send_failed_log_records_total[30s]))",
"legendFormat": ""
}
]
},
{
"id": 14,
"type": "timeseries",
"title": "Алерты",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "ALERTS{alertname=~\"Messenger.*\"}",
"legendFormat": ""
}
]
},
{
"id": 30,
"type": "logs",
"title": "API, relay и worker / связанные логи",
"datasource": {
"type": "loki",
"uid": "loki"
},
"gridPos": {
"x": 0,
"y": 56,
"w": 24,
"h": 10
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-(api|relay|worker)\"}"
}
]
}
]
}
@@ -0,0 +1,7 @@
apiVersion: 1
providers:
- name: messenger
folder: MTUSI
type: file
allowUiUpdates: false
options: {path: /var/lib/grafana/dashboards}
+38
View File
@@ -0,0 +1,38 @@
auth_enabled: false
server:
grpc_listen_address: 127.0.0.1
http_listen_address: 127.0.0.1
http_listen_port: 13100
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}
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
limits_config:
retention_period: 72h
allow_structured_metadata: true
otlp_config:
resource_attributes:
ignore_defaults: true
attributes_config:
- action: index_label
attributes: [service.name, deployment.environment.name]
analytics:
reporting_enabled: false
+23
View File
@@ -0,0 +1,23 @@
global:
scrape_interval: 2s
evaluation_interval: 2s
rule_files:
- /etc/prometheus/alerts.yaml
scrape_configs:
- job_name: messenger-otel
honor_labels: true
scheme: https
tls_config:
ca_file: /run/tls/trust/ca.crt
cert_file: /run/tls/client/service.crt
key_file: /run/tls/client/service.key
static_configs: [{targets: ["otel-collector:8889"]}]
- job_name: collector
scheme: https
tls_config:
ca_file: /run/tls/trust/ca.crt
cert_file: /run/tls/client/service.crt
key_file: /run/tls/client/service.key
static_configs: [{targets: ["otel-collector:8888"]}]
+20
View File
@@ -0,0 +1,20 @@
server:
grpc_listen_address: 127.0.0.1
http_listen_address: 127.0.0.1
http_listen_port: 13200
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318
storage:
trace:
backend: local
wal: {path: /var/tempo/wal}
local: {path: /var/tempo/blocks}
compactor:
compaction:
block_retention: 72h
usage_report:
reporting_enabled: false