Implement Lab 6 observability

This commit is contained in:
dmice9
2026-12-03 20:20:07 +03:00
parent 470d9d6f1e
commit dec4ede429
41 changed files with 2828 additions and 29 deletions
+3 -5
View File
@@ -1,7 +1,5 @@
# Конфигурация наблюдаемости — реализовать
# Конфигурация наблюдаемости
Добавьте `collector.yaml` с OTLP receivers, processors и exporters выбранной версии Collector. Укажите явные bind endpoints, внутренние сети, memory limits/batch и поведение при backpressure по уровню. Сопоставьте все три pipeline с реально развёрнутыми backend.
`collector.yaml` принимает OTLP/HTTP от API и worker, экспортирует логи в Loki, трассы в Tempo и отдаёт метрики Prometheus. В `prometheus.yaml`, `loki.yaml` и `tempo.yaml` заданы параметры хранения.
Добавьте конфигурации storage, Grafana provisioning/datasources, provisioning/dashboards и импортируемые dashboard JSON. На 4 — alert rules и runbooks. Пустой dashboard или debug exporter, который только печатает данные в stdout, не заменяют хранилища/доказательства из `contracts/observability.md`.
Не публикуйте OTLP/metrics/административные ports в общую сеть без необходимости. В lab7 реализуйте TLS/mTLS по trust matrix; экспорт Authorization и message bodies запрещён.
В `grafana/` находятся настройки источников и дашборд. Grafana доступна по loopback, остальные сервисы телеметрии доступны внутри Compose. Команды запуска и запросы для проверки есть в [REPORT.md](../../REPORT.md).
+51
View File
@@ -0,0 +1,51 @@
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 192
spike_limit_mib: 48
batch:
timeout: 1s
send_batch_size: 256
send_batch_max_size: 512
exporters:
prometheus:
endpoint: 0.0.0.0:9464
metric_expiration: 5m
resource_to_telemetry_conversion:
enabled: true
otlphttp/loki:
endpoint: http://loki:3100/otlp
timeout: 3s
sending_queue:
queue_size: 128
retry_on_failure:
max_elapsed_time: 30s
otlphttp/tempo:
endpoint: http://tempo:4318
timeout: 3s
sending_queue:
queue_size: 128
retry_on_failure:
max_elapsed_time: 30s
service:
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,182 @@
{
"uid": "lab-messenger",
"title": "Мессенджер — лабораторная 6",
"schemaVersion": 39,
"version": 1,
"refresh": "10s",
"time": {
"from": "now-15m",
"to": "now"
},
"tags": [
"mtusi"
],
"panels": [
{
"id": 1,
"type": "timeseries",
"title": "API — запросы в секунду",
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (http_route) (rate(messenger_http_requests_total[1m]))",
"legendFormat": "{{http_route}}"
}
]
},
{
"id": 2,
"type": "timeseries",
"title": "API — ответы 5xx в секунду",
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (http_route) (rate(messenger_http_requests_total{http_status_class=\"5xx\"}[1m]))",
"legendFormat": "{{http_route}}"
}
]
},
{
"id": 3,
"type": "timeseries",
"title": "API — средняя длительность",
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (http_route) (rate(messenger_http_duration_seconds_sum[1m])) / sum by (http_route) (rate(messenger_http_duration_seconds_count[1m]))",
"legendFormat": "{{http_route}}"
}
]
},
{
"id": 4,
"type": "timeseries",
"title": "Worker — задания по исходу",
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (job_outcome) (messenger_job_deliveries_total)",
"legendFormat": "{{job_outcome}}"
}
]
},
{
"id": 5,
"type": "timeseries",
"title": "Worker — средняя длительность",
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (job_outcome) (rate(messenger_job_duration_seconds_sum[1m])) / sum by (job_outcome) (rate(messenger_job_duration_seconds_count[1m]))",
"legendFormat": "{{job_outcome}}"
}
]
},
{
"id": 6,
"type": "logs",
"title": "Логи API и worker",
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"datasource": {
"type": "loki",
"uid": "lab-loki"
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-api|messenger-worker\"}"
}
],
"options": {
"showTime": true,
"showLogDetails": true,
"sortOrder": "Descending"
}
}
]
}
@@ -0,0 +1,8 @@
apiVersion: 1
providers:
- name: Messenger
folder: MTUSI
type: file
options:
path: /etc/grafana/dashboards
@@ -0,0 +1,27 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: lab-prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
jsonData:
timeInterval: 5s
- name: Loki
uid: lab-loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
derivedFields:
- name: Trace
matcherRegex: '"trace_id":"([0-9a-f]{32})"'
datasourceUid: lab-tempo
url: '$${__value.raw}'
- name: Tempo
uid: lab-tempo
type: tempo
access: proxy
url: http://tempo:3200
+48
View File
@@ -0,0 +1,48 @@
auth_enabled: false
server:
http_listen_port: 3100
common:
instance_addr: 127.0.0.1
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
ring:
kvstore:
store: inmemory
replication_factor: 1
ingester:
wal:
dir: /loki/wal
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: lab_index_
period: 24h
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
limits_config:
allow_structured_metadata: true
retention_period: 72h
otlp_config:
resource_attributes:
ignore_defaults: true
attributes_config:
- action: index_label
attributes: [service.name, deployment.environment.name]
analytics:
reporting_enabled: false
+9
View File
@@ -0,0 +1,9 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: otel-collector
honor_labels: true
static_configs:
- targets: ["otel-collector:9464"]
+24
View File
@@ -0,0 +1,24 @@
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
storage:
trace:
backend: local
local:
path: /var/tempo/blocks
wal:
path: /var/tempo/wal
compactor:
compaction:
block_retention: 72h
usage_report:
reporting_enabled: false