feat: ЛР6 - наблюдаемость OpenTelemetry, Grafana и исследование цены наблюдаемости

This commit is contained in:
Ильяс
2026-11-27 20:09:36 +03:00
parent 38a00e1930
commit c549409d7b
25 changed files with 2599 additions and 187 deletions
@@ -0,0 +1,390 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": null,
"links": [],
"liveNow": false,
"panels": [
{
"collapsed": false,
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 },
"id": 100,
"title": "API Metrics",
"type": "row"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth"
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 1 },
"id": 1,
"options": {
"legend": { "displayMode": "table", "placement": "bottom" },
"tooltip": { "mode": "multi" }
},
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "sum(rate(messenger_http_requests_total[1m])) by (route, status)",
"legendFormat": "{{route}} - {{status}}",
"range": true,
"refId": "A"
}
],
"title": "HTTP Request Rate (RPS)",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth"
},
"unit": "s"
},
"overrides": []
},
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 1 },
"id": 2,
"options": {
"legend": { "displayMode": "table", "placement": "bottom" },
"tooltip": { "mode": "multi" }
},
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.50, sum(rate(messenger_http_request_duration_seconds_bucket[1m])) by (le))",
"legendFormat": "p50",
"range": true,
"refId": "A"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.95, sum(rate(messenger_http_request_duration_seconds_bucket[1m])) by (le))",
"legendFormat": "p95",
"range": true,
"refId": "B"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.99, sum(rate(messenger_http_request_duration_seconds_bucket[1m])) by (le))",
"legendFormat": "p99",
"range": true,
"refId": "C"
}
],
"title": "HTTP Latency Quantiles",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"color": { "mode": "thresholds" },
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{ "color": "green", "value": null },
{ "color": "yellow", "value": 0.01 },
{ "color": "red", "value": 0.05 }
]
},
"unit": "percentunit"
},
"overrides": []
},
"gridPos": { "h": 6, "w": 8, "x": 0, "y": 9 },
"id": 3,
"options": {
"orientation": "auto",
"reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false },
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "(sum(rate(messenger_http_requests_total{status=~\"5..\"}[1m])) or vector(0)) / (sum(rate(messenger_http_requests_total[1m])) > 0 or vector(1))",
"legendFormat": "5xx Ratio",
"range": true,
"refId": "A"
}
],
"title": "HTTP 5xx Error Ratio",
"type": "gauge"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "stepAfter"
},
"unit": "short"
},
"overrides": []
},
"gridPos": { "h": 6, "w": 8, "x": 8, "y": 9 },
"id": 4,
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "messenger_queue_depth",
"legendFormat": "Queue Depth",
"range": true,
"refId": "A"
}
],
"title": "RabbitMQ Queue Depth",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "linear"
},
"unit": "short"
},
"overrides": []
},
"gridPos": { "h": 6, "w": 8, "x": 16, "y": 9 },
"id": 5,
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "messenger_db_pool_connections",
"legendFormat": "DB Active Pool",
"range": true,
"refId": "A"
}
],
"title": "PostgreSQL Active Connections",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 15 },
"id": 101,
"title": "Worker Metrics",
"type": "row"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth"
},
"unit": "s"
},
"overrides": []
},
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 16 },
"id": 6,
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.50, sum(rate(messenger_job_processing_duration_seconds_bucket[1m])) by (le))",
"legendFormat": "p50",
"range": true,
"refId": "A"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.95, sum(rate(messenger_job_processing_duration_seconds_bucket[1m])) by (le))",
"legendFormat": "p95",
"range": true,
"refId": "B"
}
],
"title": "Worker Job Processing Latency",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth"
},
"unit": "ops"
},
"overrides": []
},
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 16 },
"id": 7,
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "sum(rate(messenger_jobs_processed_total[1m]))",
"legendFormat": "Processed rate",
"range": true,
"refId": "A"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "sum(rate(messenger_jobs_failed_total[1m]))",
"legendFormat": "Failed rate",
"range": true,
"refId": "B"
}
],
"title": "Worker Jobs Throughput & Failures",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth"
},
"unit": "s"
},
"overrides": []
},
"gridPos": { "h": 6, "w": 12, "x": 0, "y": 24 },
"id": 9,
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "messenger_queue_oldest_job_age_seconds",
"legendFormat": "Oldest Job Age",
"range": true,
"refId": "A"
}
],
"title": "Oldest Waiting Job Age",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth"
},
"unit": "s"
},
"overrides": []
},
"gridPos": { "h": 6, "w": 12, "x": 12, "y": 24 },
"id": 10,
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.95, sum(rate(messenger_attachment_time_to_ready_seconds_bucket[1m])) by (le))",
"legendFormat": "p95 Time-to-Ready",
"range": true,
"refId": "A"
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"editorMode": "code",
"expr": "histogram_quantile(0.50, sum(rate(messenger_attachment_time_to_ready_seconds_bucket[1m])) by (le))",
"legendFormat": "p50 Time-to-Ready",
"range": true,
"refId": "B"
}
],
"title": "Attachment End-to-End Time to Ready",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 30 },
"id": 102,
"title": "Logs & Tracing",
"type": "row"
},
{
"datasource": { "type": "loki", "uid": "loki" },
"gridPos": { "h": 10, "w": 24, "x": 0, "y": 31 },
"id": 8,
"options": {
"dedupStrategy": "none",
"enableLogDetails": true,
"prettifyLogMessage": false,
"showCommonLabels": false,
"showLabels": false,
"showTime": true,
"sortOrder": "Descending",
"wrapLogMessage": true
},
"targets": [
{
"datasource": { "type": "loki", "uid": "loki" },
"editorMode": "code",
"expr": "{service_name=~\".+\"}",
"queryType": "range",
"refId": "A"
}
],
"title": "Live Application Logs (Loki)",
"type": "logs"
}
],
"refresh": "5s",
"schemaVersion": 38,
"style": "dark",
"tags": ["lab6", "messenger", "observability"],
"time": {
"from": "now-15m",
"to": "now"
},
"timepicker": {
"refresh_intervals": ["5s", "10s", "30s", "1m"]
},
"timezone": "browser",
"title": "Messenger System Overview",
"uid": "messenger-overview",
"version": 1
}
@@ -0,0 +1,229 @@
apiVersion: 1
contactPoints:
- orgId: 1
name: default-channel
receivers:
- uid: default-channel
type: email
settings:
addresses: admin@example.com
policies:
- orgId: 1
receiver: default-channel
group_by: ['alertname', 'grafana_folder']
groups:
- orgId: 1
name: messenger_alerts
folder: Messenger Alerts
interval: 10s
rules:
- uid: high_http_error_rate
title: HighHttpErrorRate
condition: C
for: 1m
noDataState: OK
execErrState: Error
data:
- refId: A
relativeTimeRange:
from: 300
to: 0
datasourceUid: prometheus
model:
editorMode: code
expr: ((sum(rate(messenger_http_requests_total{status=~"5.."}[1m])) or vector(0)) / (sum(rate(messenger_http_requests_total[1m])) or vector(1))) > 0.05
instant: true
range: false
refId: A
- refId: C
relativeTimeRange:
from: 300
to: 0
datasourceUid: __expr__
model:
conditions:
- eval:
params:
- 0
type: gt
operator:
type: and
query:
params:
- A
reducer:
params: []
type: last
type: query
datasource:
name: Expression
type: __expr__
uid: __expr__
expression: A
refId: C
type: threshold
annotations:
summary: High HTTP 5xx error rate detected
description: More than 5% of requests returned 5xx status codes over the last minute.
runbook_url: file:///RUNBOOK.md#highhttperrorrate
labels:
severity: critical
- uid: queue_lag_growing
title: QueueLagGrowing
condition: C
for: 1m
noDataState: OK
execErrState: Error
data:
- refId: A
relativeTimeRange:
from: 300
to: 0
datasourceUid: prometheus
model:
editorMode: code
expr: (messenger_queue_depth or vector(0)) > 10
instant: true
range: false
refId: A
- refId: C
relativeTimeRange:
from: 300
to: 0
datasourceUid: __expr__
model:
conditions:
- eval:
params:
- 0
type: gt
operator:
type: and
query:
params:
- A
reducer:
params: []
type: last
type: query
datasource:
name: Expression
type: __expr__
uid: __expr__
expression: A
refId: C
type: threshold
annotations:
summary: Worker queue depth is growing
description: RabbitMQ task queue depth has exceeded 10 messages for over 1 minute.
runbook_url: file:///RUNBOOK.md#queuelaggrowing
labels:
severity: warning
- uid: high_http_latency_p95
title: HighHttpLatencyP95
condition: C
for: 1m
noDataState: OK
execErrState: Error
data:
- refId: A
relativeTimeRange:
from: 300
to: 0
datasourceUid: prometheus
model:
editorMode: code
expr: (histogram_quantile(0.95, sum(rate(messenger_http_request_duration_seconds_bucket[1m])) by (le)) or vector(0)) > 1.0
instant: true
range: false
refId: A
- refId: C
relativeTimeRange:
from: 300
to: 0
datasourceUid: __expr__
model:
conditions:
- eval:
params:
- 0
type: gt
operator:
type: and
query:
params:
- A
reducer:
params: []
type: last
type: query
datasource:
name: Expression
type: __expr__
uid: __expr__
expression: A
refId: C
type: threshold
annotations:
summary: HTTP request latency p95 exceeded 1 second
description: 95th percentile of request duration is higher than 1s over the last minute.
runbook_url: file:///RUNBOOK.md#highhttplatencyp95
labels:
severity: warning
- uid: worker_job_failure_rate
title: WorkerJobFailureRate
condition: C
for: 1m
noDataState: OK
execErrState: Error
data:
- refId: A
relativeTimeRange:
from: 300
to: 0
datasourceUid: prometheus
model:
editorMode: code
expr: (sum(rate(messenger_jobs_failed_total[1m])) or vector(0)) > 0.05
instant: true
range: false
refId: A
- refId: C
relativeTimeRange:
from: 300
to: 0
datasourceUid: __expr__
model:
conditions:
- eval:
params:
- 0
type: gt
operator:
type: and
query:
params:
- A
reducer:
params: []
type: last
type: query
datasource:
name: Expression
type: __expr__
uid: __expr__
expression: A
refId: C
type: threshold
annotations:
summary: Worker job failure rate elevated
description: Attachment worker is encountering permanent task failures.
runbook_url: file:///RUNBOOK.md#workerjobfailurerate
labels:
severity: critical
@@ -0,0 +1,12 @@
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: true
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,43 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
jsonData:
httpMethod: POST
timeInterval: 5s
- name: Tempo
type: tempo
access: proxy
url: http://tempo:3200
jsonData:
httpMethod: GET
tracesToLogsV2:
datasourceUid: 'loki'
tags: ['job', 'instance', 'service.name']
filterByTraceID: true
filterBySpanID: true
serviceMap:
datasourceUid: 'prometheus'
nodeGraph:
enabled: true
search:
hide: false
lokiSearch:
datasourceUid: 'loki'
- name: Loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
maxLines: 1000
derivedFields:
- datasourceUid: tempo
matcherRegex: '"trace_id":\s*"([0-9a-f]{32})"'
name: TraceID
url: '$${__value.raw}'
+32
View File
@@ -0,0 +1,32 @@
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
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
reject_old_samples: true
reject_old_samples_max_age: 168h
+43
View File
@@ -0,0 +1,43 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 75
spike_limit_percentage: 20
batch:
timeout: 1s
send_batch_size: 256
exporters:
prometheus:
endpoint: "0.0.0.0:8889"
namespace: "messenger"
send_timestamps: true
otlp/tempo:
endpoint: "tempo:4317"
tls:
insecure: true
otlphttp/loki:
endpoint: "http://loki:3100/otlp"
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp/tempo]
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/loki]
+11
View File
@@ -0,0 +1,11 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: "otel-collector"
static_configs:
- targets: ["otel-collector:8889"]
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
+34
View File
@@ -0,0 +1,34 @@
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
ingester:
lifecycler:
ring:
replication_factor: 1
trace_idle_period: 10s
max_block_bytes: 1000000
max_block_duration: 5m
compactor:
compaction:
compaction_window: 1h
max_block_bytes: 100000000
block_retention: 1h
compacted_block_retention: 10m
storage:
trace:
backend: local
local:
path: /var/tempo/traces
wal:
path: /var/tempo/wal