Files
mtusi2026lab7/infra/otel/collector.yaml
T

146 lines
6.6 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# lab7: Collector слушает ТОЛЬКО 127.0.0.1 в общем network namespace с otel-gate (HAProxy): mTLS и проверку
# identity клиента (api/worker/dispatcher/janitor) делает gate (infra/otel/gate.cfg). До хранилищ — mTLS
# с identity CN=otel-collector, проверка сертификата сервера и его имени (tempo, loki, prometheus).
#
# OpenTelemetry Collector (otel/opentelemetry-collector-contrib:0.164.0) — единственный приёмник
# телеметрии приложения. Не хранит данные: принимает OTLP, ограничивает память, пакетирует и
# отправляет в три хранилища. Проверка конфигурации: otelcol-contrib validate --config=collector.yaml
#
# api/worker/dispatcher/janitor --OTLP/HTTP+mTLS :4318--> otel-gate --127.0.0.1:4319--> receiver otlp
# traces -> memory_limiter -> attributes/scrub -> batch -> otlp_grpc/tempo (Tempo :4317)
# logs -> memory_limiter -> attributes/scrub -> batch -> otlp_http/loki (Loki /otlp)
# metrics -> memory_limiter -> batch -> otlp_http/prometheus (Prometheus /api/v1/otlp)
#
# Порты 4319/8888/13133 — только 127.0.0.1 (наружу их отдаёт gate: 4318 и 8889, оба mTLS).
#
# Поведение при недоступном хранилище (ограниченная буферизация, RAM не растёт бесконечно):
# - у каждого exporter своя очередь в памяти (sending_queue) фиксированного размера: заполнилась ->
# новые пакеты отбрасываются и считаются (otelcol_exporter_enqueue_failed_*);
# - повтор с экспоненциальной задержкой не дольше max_elapsed_time, потом пакет отбрасывается
# (otelcol_exporter_send_failed_*);
# - memory_limiter: при приближении к лимиту receiver отказывает клиентам (SDK получает ошибку и
# сам отбрасывает данные в своей ограниченной очереди), процесс не уходит в OOM;
# - остальные pipeline работают независимо: упал Tempo — логи и метрики продолжают доходить.
# Очередь только в памяти: при рестарте Collector неотправленное теряется (осознанный компромисс,
# file_storage не нужен для учебного стенда).
extensions:
health_check:
endpoint: 127.0.0.1:13133
receivers:
otlp:
protocols:
# gRPC не нужен (SDK приложения шлёт OTLP/HTTP) — выключен, меньше открытых портов.
http:
endpoint: 127.0.0.1:4319
processors:
# Первым в каждом pipeline: проверка heap Go раз в секунду. Мягкий предел = limit - spike = 160 MiB
# (receiver начинает отказывать), жёсткий 200 MiB (принудительный GC). Лимит контейнера 384 MiB:
# RSS включает ещё runtime Go и отображённый в память бинарник contrib (~150 MiB, вытесняемые страницы).
memory_limiter:
check_interval: 1s
limit_mib: 200
spike_limit_mib: 40
# Защита в глубину: приложение не пишет секреты в атрибуты, но если бы инструментирование ошиблось,
# такие ключи не дойдут до хранилищ. Удаляются по шаблону имени ключа (спаны и логи).
attributes/scrub:
actions:
- pattern: (?i).*(password|passwd|authorization|cookie|secret|token|api[_.-]?key|signature).*
action: delete
- key: db.statement.parameters
action: delete
- key: db.query.parameter
action: delete
batch:
timeout: 2s
send_batch_size: 1024
send_batch_max_size: 2048
exporters:
otlp_grpc/tempo:
endpoint: tempo:4317
tls:
ca_file: /run/tls-ca/ca.crt # сертификат Tempo: наш CA + имя tempo
cert_file: /run/tls/tls.crt # identity CN=otel-collector (mTLS)
key_file: /run/tls/tls.key
min_version: "1.2"
timeout: 5s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 200 # пакетов (до 2048 спанов каждый)
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 120s
otlp_http/loki:
endpoint: https://loki:3100/otlp # -> /otlp/v1/logs
tls:
ca_file: /run/tls-ca/ca.crt
cert_file: /run/tls/tls.crt
key_file: /run/tls/tls.key
min_version: "1.2"
timeout: 5s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 200
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 120s
otlp_http/prometheus:
endpoint: https://prometheus:9090/api/v1/otlp # -> /api/v1/otlp/v1/metrics
tls:
ca_file: /run/tls-ca/ca.crt
cert_file: /run/tls/tls.crt
key_file: /run/tls/tls.key
min_version: "1.2"
timeout: 5s
sending_queue:
enabled: true
num_consumers: 1 # один поток: точки одной серии приходят по порядку
queue_size: 100
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 120s
service:
extensions: [health_check]
telemetry:
logs:
level: info
# Собственные метрики Collector (принято/отправлено/отброшено, размер очередей, RSS) —
# Prometheus забирает их pull-ом через gate: https://otel-collector:8889 (mTLS, CN=prometheus) -> 127.0.0.1:8888.
metrics:
level: detailed
readers:
- pull:
exporter:
prometheus:
host: 127.0.0.1
port: 8888
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, attributes/scrub, batch]
exporters: [otlp_grpc/tempo]
logs:
receivers: [otlp]
processors: [memory_limiter, attributes/scrub, batch]
exporters: [otlp_http/loki]
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/prometheus]