lab6: observability, otel, grafana, incidents and dashboard

This commit is contained in:
2026-11-17 15:57:31 +03:00
parent 470d9d6f1e
commit 0f7b4461cb
44 changed files with 2792 additions and 44 deletions
+30
View File
@@ -0,0 +1,30 @@
"""Bootstraps a private S3 identity configuration from non-committed .env.
The server reads it from a shared internal-only configuration volume.
"""
import json
import os
from pathlib import Path
bucket = os.environ["S3_BUCKET"]
assert bucket == "messenger-attachments", "Fixed bucket name; change policy and config deliberately"
config = {
"identities": [
{
"name": "lab4-admin",
"credentials": [{"accessKey": os.environ["S3_ROOT_USER"],
"secretKey": os.environ["S3_ROOT_PASSWORD"]}],
"actions": ["Admin", "Read", "Write", "List", "Tagging"],
},
{
"name": "lab4-api",
"credentials": [{"accessKey": os.environ["S3_ACCESS_KEY_ID"],
"secretKey": os.environ["S3_SECRET_ACCESS_KEY"]}],
"actions": [f"Read:{bucket}", f"Write:{bucket}", f"List:{bucket}"],
},
],
}
target = Path("/s3-config/s3.json")
target.write_text(json.dumps(config, indent=2), encoding="utf-8")
target.chmod(0o644) # Only mounted into S3 service; SeaweedFS runs non-root on some images.
print("PASS: private S3 identity config generated; credentials not logged")
+38
View File
@@ -0,0 +1,38 @@
global
log stdout format raw local0
maxconn 512
defaults
mode http
log global
option httplog
timeout connect 3s
timeout client 75s
timeout server 75s
timeout check 2s
retries 1
option redispatch
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 2
timeout resolve 1s
timeout retry 1s
hold valid 1s
hold obsolete 1s
hold nx 1s
hold refused 1s
hold timeout 1s
hold other 1s
frontend public
bind :8080
default_backend api
backend api
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
default-server check inter 1s fall 2 rise 1 resolvers docker init-addr libc,none
server api1 api1:8080
server api2 api2:8080
+62
View File
@@ -0,0 +1,62 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 2s
limit_mib: 96
spike_limit_mib: 24
batch:
timeout: 3s
send_batch_size: 256
send_batch_max_size: 512
exporters:
prometheus:
endpoint: 0.0.0.0:8889
resource_to_telemetry_conversion:
enabled: true
otlp/tempo:
endpoint: tempo:4317
tls:
insecure: true
sending_queue:
enabled: true
num_consumers: 2
queue_size: 128
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 5s
max_elapsed_time: 30s
otlphttp/loki:
endpoint: http://loki:3100/otlp
sending_queue:
enabled: true
num_consumers: 2
queue_size: 128
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 5s
max_elapsed_time: 30s
service:
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp/tempo]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/loki]
telemetry:
logs:
level: warn
@@ -0,0 +1,10 @@
apiVersion: 1
providers:
- name: Messenger Lab 6
orgId: 1
folder: MTUCI
type: file
disableDeletion: false
allowUiUpdates: false
options:
path: /etc/grafana/provisioning/dashboards/json
@@ -0,0 +1,481 @@
{
"id": null,
"uid": "mtuci-votchitseva-lab6",
"title": "МТУСИ · ЛР6 · Мессенджер",
"description": "API + RabbitMQ worker, OpenTelemetry Collector, Prometheus, Loki and Tempo. All metric labels are low-cardinality.",
"tags": [
"mtuci",
"lab6",
"observability"
],
"timezone": "browser",
"schemaVersion": 40,
"version": 1,
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
},
"panels": [
{
"id": 1,
"type": "timeseries",
"title": "API — запросов в секунду",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_requests_total{route!=\"/health\"}[1m]))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "req/s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
}
},
{
"id": 2,
"type": "timeseries",
"title": "API — доля ошибок 5xx",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"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.000001)",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
}
},
{
"id": 3,
"type": "timeseries",
"title": "HTTP p50",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.50, sum by(le) (rate(messenger_http_duration_seconds_bucket{route!=\"/health\"}[5m])))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
}
},
{
"id": 4,
"type": "timeseries",
"title": "HTTP p95",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by(le) (rate(messenger_http_duration_seconds_bucket{route!=\"/health\"}[5m])))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
}
},
{
"id": 5,
"type": "timeseries",
"title": "HTTP p99",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.99, sum by(le) (rate(messenger_http_duration_seconds_bucket{route!=\"/health\"}[5m])))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 16
}
},
{
"id": 6,
"type": "timeseries",
"title": "Очередь — ожидают обработки",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_depth)",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 16
}
},
{
"id": 7,
"type": "timeseries",
"title": "Очередь — возраст старейшей",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_oldest_age_seconds)",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 24
}
},
{
"id": 8,
"type": "timeseries",
"title": "Worker — jobs/sec",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum by(outcome)(rate(messenger_jobs_total[1m]))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 24
}
},
{
"id": 9,
"type": "timeseries",
"title": "Worker — p95 обработки",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by(le) (rate(messenger_job_duration_seconds_bucket[5m])))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 32
}
},
{
"id": 10,
"type": "timeseries",
"title": "Время до ready — p95",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by(le) (rate(messenger_time_to_ready_seconds_bucket[5m])))",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 32
}
},
{
"id": 11,
"type": "timeseries",
"title": "DB pool — занято",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum(messenger_db_pool_used{service_name=\"messenger-api\"})",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 40
}
},
{
"id": 12,
"type": "timeseries",
"title": "Worker — загрузка",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_worker_busy{service_name=\"messenger-worker\"}) / clamp_min(max(messenger_worker_capacity{service_name=\"messenger-worker\"}), 1)",
"legendFormat": "{{service_name}} {{outcome}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 40
}
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0,211,255,1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
}
}
@@ -0,0 +1,30 @@
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
jsonData:
derivedFields:
- name: TraceID
matcherRegex: 'trace_id=([0-9a-f]{32})'
datasourceUid: tempo
url: '$${__value.raw}'
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: http://tempo:3200
jsonData:
tracesToLogsV2:
datasourceUid: loki
filterByTraceID: true
tracesToMetrics:
datasourceUid: prometheus
+27
View File
@@ -0,0 +1,27 @@
auth_enabled: false
server:
http_listen_port: 3100
common:
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
retention_period: 168h
analytics:
reporting_enabled: false
+23
View File
@@ -0,0 +1,23 @@
groups:
- name: lab6-signals
interval: 5s
rules:
- alert: MessengerHighErrorRate
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.000001)) > 0.10
and sum(rate(messenger_http_requests_total{route!="/health"}[1m])) > 0.05
for: 15s
labels:
severity: warning
annotations:
summary: '5xx responses exceed 10% of business requests'
runbook: 'Check API error rate, Loki errors, Tempo DB spans and postgres health'
- alert: MessengerQueueLagGrowing
expr: max(messenger_queue_oldest_age_seconds) > 20
for: 15s
labels:
severity: warning
annotations:
summary: 'Oldest queued attachment is older than 20 seconds'
runbook: 'Check worker status, RabbitMQ queue and job failure spans in Tempo'
+12
View File
@@ -0,0 +1,12 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
rule_files:
- /etc/prometheus/alerts.yml
scrape_configs:
- job_name: collector
static_configs:
- targets: ['otel-collector:8889']
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
+18
View File
@@ -0,0 +1,18 @@
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/traces
compactor:
compaction:
block_retention: 168h