This commit is contained in:
2026-11-20 15:30:33 +03:00
parent 20afc2c790
commit 36a56b3fe3
187 changed files with 431228 additions and 291 deletions
+23
View File
@@ -0,0 +1,23 @@
groups:
- name: lab6
interval: 2s
rules:
- alert: ApiHighErrorRate
expr: |
(sum(increase(http_server_requests_total{route=~"/api/v1/.*",status_class="5xx"}[30s]))
/ clamp_min(sum(increase(http_server_requests_total{route=~"/api/v1/.*"}[30s])), 1) > 0.05)
and sum(increase(http_server_requests_total{route=~"/api/v1/.*"}[30s])) >= 3
for: 5s
labels:
severity: warning
annotations:
summary: "Business API 5xx ratio exceeds 5% over 30 seconds"
description: "Exclude health and client errors. Inspect DB spans, db.error logs and pool waiting. See RUNBOOK.md."
- alert: QueueLagGrowing
expr: max(queue_oldest_age_seconds) > 15 and max(queue_depth) > 0
for: 5s
labels:
severity: warning
annotations:
summary: "Oldest accepted job has waited more than 15 seconds"
description: "Inspect queue depth, worker capacity/busy and job traces. Restore worker and verify lag returns to zero. See RUNBOOK.md."
+133
View File
@@ -0,0 +1,133 @@
{
"receivers": {
"otlp": {
"protocols": {
"http": {
"endpoint": "127.0.0.1:14318"
}
}
}
},
"processors": {
"memory_limiter": {
"check_interval": "1s",
"limit_mib": 192,
"spike_limit_mib": 32
},
"batch": {
"timeout": "1s",
"send_batch_size": 128,
"send_batch_max_size": 256
}
},
"exporters": {
"prometheus": {
"endpoint": "127.0.0.1:18889",
"resource_to_telemetry_conversion": {
"enabled": true
}
},
"otlphttp/tempo": {
"endpoint": "https://tempo:4318",
"tls": {
"ca_file": "/run/trust/ca.crt",
"cert_file": "/run/identity/service.crt",
"key_file": "/run/identity/service.key"
},
"timeout": "2s",
"sending_queue": {
"enabled": true,
"num_consumers": 2,
"queue_size": 64
},
"retry_on_failure": {
"initial_interval": "1s",
"max_interval": "3s",
"max_elapsed_time": "10s"
}
},
"otlphttp/loki": {
"endpoint": "https://loki:3100/otlp",
"tls": {
"ca_file": "/run/trust/ca.crt",
"cert_file": "/run/identity/service.crt",
"key_file": "/run/identity/service.key"
},
"timeout": "2s",
"sending_queue": {
"enabled": true,
"num_consumers": 2,
"queue_size": 64
},
"retry_on_failure": {
"initial_interval": "1s",
"max_interval": "3s",
"max_elapsed_time": "10s"
}
}
},
"extensions": {
"health_check": {
"endpoint": "127.0.0.1:13134"
}
},
"service": {
"extensions": [
"health_check"
],
"telemetry": {
"metrics": {
"readers": [
{
"pull": {
"exporter": {
"prometheus": {
"host": "127.0.0.1",
"port": 18888
}
}
}
}
]
}
},
"pipelines": {
"traces": {
"receivers": [
"otlp"
],
"processors": [
"memory_limiter",
"batch"
],
"exporters": [
"otlphttp/tempo"
]
},
"logs": {
"receivers": [
"otlp"
],
"processors": [
"memory_limiter",
"batch"
],
"exporters": [
"otlphttp/loki"
]
},
"metrics": {
"receivers": [
"otlp"
],
"processors": [
"memory_limiter",
"batch"
],
"exporters": [
"prometheus"
]
}
}
}
}
@@ -0,0 +1,519 @@
{
"uid": "messenger-lab6",
"title": "Мессенджер · Lab6 · Каменский Андрей",
"schemaVersion": 39,
"version": 1,
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
},
"tags": [
"lab6",
"messenger"
],
"panels": [
{
"id": 1,
"title": "Business API requests / second",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(rate(http_server_requests_total{route=~\"/api/v1/.*\"}[1m]))",
"legendFormat": "RPS",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
}
},
{
"id": 2,
"title": "Business API 5xx ratio",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(rate(http_server_requests_total{route=~\"/api/v1/.*\",status_class=\"5xx\"}[1m])) / clamp_min(sum(rate(http_server_requests_total{route=~\"/api/v1/.*\"}[1m])), 0.00001)",
"legendFormat": "5xx / all business requests",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
}
},
{
"id": 3,
"title": "API latency p50 (histogram, all replicas)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.5, sum by (le) (rate(http_server_duration_seconds_bucket{route=~\"/api/v1/.*\"}[1m])))",
"legendFormat": "p50",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 4,
"title": "API latency p95 (histogram, all replicas)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_duration_seconds_bucket{route=~\"/api/v1/.*\"}[1m])))",
"legendFormat": "p95",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 5,
"title": "API latency p99 (histogram, all replicas)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_duration_seconds_bucket{route=~\"/api/v1/.*\"}[1m])))",
"legendFormat": "p99",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 6,
"title": "Jobs per second by outcome",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(outcome)(rate(worker_jobs_total[1m]))",
"legendFormat": "{{outcome}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
}
},
{
"id": 7,
"title": "Worker processing p95",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95, sum by(le)(rate(worker_job_duration_seconds_bucket[1m])))",
"legendFormat": "p95",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 8,
"title": "Acceptance to ready p95",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95, sum by(le)(rate(attachment_ready_duration_seconds_bucket[1m])))",
"legendFormat": "p95",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 9,
"title": "Accepted unfinished jobs (includes outbox)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "max(queue_depth)",
"legendFormat": "jobs",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 10,
"title": "Oldest unfinished job age",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "max(queue_oldest_age_seconds)",
"legendFormat": "age",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 11,
"title": "DB pool used / waiting",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(service_name)(db_pool_used)",
"legendFormat": "{{service_name}}",
"refId": "A"
},
{
"expr": "sum by(service_name)(db_pool_waiting)",
"legendFormat": "{{service_name}} waiting",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 12,
"title": "Worker saturation",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(worker_busy) / clamp_min(sum(worker_capacity),1)",
"legendFormat": "busy / capacity",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
}
},
{
"id": 13,
"title": "Process resident memory",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(service_name)(process_memory_rss_bytes)",
"legendFormat": "{{service_name}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "bytes"
},
"overrides": []
}
},
{
"id": 14,
"title": "Process CPU cores",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(service_name)(rate(process_cpu_time_seconds_total[1m]))",
"legendFormat": "{{service_name}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 15,
"title": "API availability SLI (5m), SLO 99%",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "1 - (sum(increase(http_server_requests_total{route=~\"/api/v1/.*\",status_class=\"5xx\"}[5m])) or vector(0)) / clamp_min(sum(increase(http_server_requests_total{route=~\"/api/v1/.*\"}[5m])),1)",
"legendFormat": "SLI",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
}
},
{
"id": 16,
"title": "Collector export failures / second",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(exporter)(rate(otelcol_exporter_send_failed_spans_total[1m]))",
"legendFormat": "{{exporter}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
}
},
{
"id": 17,
"title": "Local firing alerts",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 64,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "ALERTS{alertstate=\"firing\"}",
"legendFormat": "{{alertname}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 99,
"title": "Structured API / worker logs — trace_id links to Tempo",
"type": "logs",
"datasource": {
"type": "loki",
"uid": "loki"
},
"gridPos": {
"x": 0,
"y": 72,
"w": 24,
"h": 10
},
"targets": [
{
"expr": "{service_name=~\"messenger-(api|worker)\"}",
"refId": "A"
}
]
}
]
}
@@ -0,0 +1,10 @@
apiVersion: 1
providers:
- name: messenger
orgId: 1
folder: Lab6
type: file
disableDeletion: true
updateIntervalSeconds: 10
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,34 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
jsonData:
timeInterval: 2s
- name: Loki
uid: loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
derivedFields:
- name: TraceID
matcherRegex: '"trace_id":\s*"([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
spanStartTimeShift: '-1m'
spanEndTimeShift: '1m'
filterByTraceID: false
customQuery: true
query: '{service_name=~"messenger-.*"} | json | trace_id="$${__trace.traceId}"'
+32
View File
@@ -0,0 +1,32 @@
auth_enabled: false
server:
http_listen_port: 13100
http_listen_address: 127.0.0.1
grpc_listen_address: 127.0.0.1
common:
path_prefix: /loki
instance_addr: 127.0.0.1
replication_factor: 1
ring:
kvstore:
store: inmemory
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
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
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
+43
View File
@@ -0,0 +1,43 @@
{
"global": {
"scrape_interval": "2s",
"evaluation_interval": "2s"
},
"rule_files": [
"/etc/prometheus/alerts.yaml"
],
"scrape_configs": [
{
"job_name": "messenger",
"scheme": "https",
"tls_config": {
"ca_file": "/run/trust/ca.crt",
"cert_file": "/run/identity/service.crt",
"key_file": "/run/identity/service.key"
},
"static_configs": [
{
"targets": [
"otel-collector:8889"
]
}
]
},
{
"job_name": "collector",
"scheme": "https",
"tls_config": {
"ca_file": "/run/trust/ca.crt",
"cert_file": "/run/identity/service.crt",
"key_file": "/run/identity/service.key"
},
"static_configs": [
{
"targets": [
"otel-collector:8888"
]
}
]
}
]
}
+23
View File
@@ -0,0 +1,23 @@
server:
http_listen_port: 13200
http_listen_address: 127.0.0.1
grpc_listen_address: 127.0.0.1
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318
ingester:
trace_idle_period: 2s
max_block_duration: 1m
compactor:
compaction:
block_retention: 168h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks