Files
mtusi2026lab7/infra/otel/collector.yaml
T

127 lines
6.5 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.
# OpenTelemetry Collector (contrib 0.130.0) — получатель/обработчик/экспортёр, НЕ хранилище.
# lab7: приём — ТОЛЬКО через mTLS-шлюз otel-gw (сайдкар в том же сетевом namespace): API/worker → TLS :4318
# с клиентским сертификатом (identity api|worker, проверка CA/CRL/CN в шлюзе) → 127.0.0.1:14318 (этот
# receiver; loopback, снаружи namespace недоступен). Шлюз передаёт identity в X-Client-Identity, процессор
# resource/identity записывает её в messenger.peer.identity, transform/identity ПРИНУДИТЕЛЬНО ставит
# service.name = messenger-<identity>: сертификат worker не позволяет писать telemetry от имени API.
# Экспорт — mTLS с identity otel-collector через шлюзы backend'ов (least privilege: только запись):
# traces → Tempo (https://tempo:4318/v1/traces)
# metrics → Prometheus (https://prometheus:9090/api/v1/otlp)
# logs → Loki (https://loki:3100/otlp)
# Защита памяти и поведение при недоступном backend:
# * memory_limiter — первым в каждой pipeline: при росте RAM выше limit-spike Collector отклоняет приём
# (SDK получает 503/429, повторяет и затем отбрасывает — потери считаются на стороне SDK);
# * sending_queue каждого экспортёра — ограниченная очередь в памяти (queue_size батчей); при переполнении
# новые данные отбрасываются (otelcol_exporter_enqueue_failed_*), а не накапливаются бесконечно;
# * retry_on_failure — повтор с экспоненциальной паузой, не дольше max_elapsed_time, затем батч отбрасывается
# (otelcol_exporter_send_failed_*). Telemetry — «best effort»: бизнес-запросы от неё не зависят.
# lab7: приём — только через mTLS-шлюз otel-gw (identity api|worker); экспорт — mTLS к шлюзам backend'ов.
extensions:
health_check:
endpoint: 127.0.0.1:13133 # только loopback namespace
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318 # только loopback: снаружи — через mTLS-шлюз otel-gw
max_request_body_size: 8388608 # 8 MiB на запрос экспорта
include_metadata: true # заголовок X-Client-Identity от шлюза → client.Info.Metadata
processors:
# Identity клиента mTLS (из шлюза) — в ресурс; service.name — по identity, а не по словам клиента.
resource/identity:
attributes:
- key: messenger.peer.identity
from_context: metadata.x-client-identity
action: upsert
transform/identity:
error_mode: ignore
trace_statements: &identity_statements
- context: resource
statements:
- set(attributes["service.name"], "messenger-unknown") where attributes["messenger.peer.identity"] == nil
- set(attributes["service.name"], Concat(["messenger", attributes["messenger.peer.identity"]], "-")) where attributes["messenger.peer.identity"] != nil
metric_statements: *identity_statements
log_statements: *identity_statements
memory_limiter:
check_interval: 1s
limit_mib: 200 # контейнер ограничен 256 MiB
spike_limit_mib: 50 # мягкий порог 150 MiB: дальше приём отклоняется
batch:
send_batch_size: 1024
send_batch_max_size: 2048
timeout: 2s
# Защита «в глубину»: даже если код по ошибке положит такой атрибут, в хранилища он не уйдёт.
attributes/scrub:
actions:
- pattern: '(?i)^(.*\.)?(password|passwd|token|access_token|session_token|authorization|cookie|secret|api_key|secret_id|role_id|client_token|db_password|redis_password|s3_secret_access_key)$'
action: delete
- pattern: '(?i)^http\.request\.header\.(authorization|cookie|x-api-key)$'
action: delete
- key: db.query.parameters
action: delete
exporters:
otlphttp/tempo:
endpoint: https://tempo:4318
tls: &mtls
ca_file: /run/tls/trust/ca.crt # проверка сервера: наш CA + hostname (без insecure)
cert_file: /run/tls/self/tls.crt # identity otel-collector
key_file: /run/tls/self/tls.key
min_version: "1.2"
compression: gzip
timeout: 5s
sending_queue: &queue
enabled: true
num_consumers: 2
queue_size: 200 # батчей (≤ 2048 элементов каждый) — предел RAM очереди
retry_on_failure: &retry
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 120s
otlphttp/loki:
endpoint: https://loki:3100/otlp
tls: *mtls
compression: gzip
timeout: 5s
sending_queue: *queue
retry_on_failure: *retry
otlphttp/prometheus:
endpoint: https://prometheus:9090/api/v1/otlp
tls: *mtls
compression: gzip
timeout: 5s
sending_queue: *queue
retry_on_failure: *retry
service:
extensions: [health_check]
telemetry:
logs:
level: info
metrics:
level: detailed # otelcol_* метрики самого Collector: принято/отклонено/отправлено/очереди
readers:
- pull:
exporter:
prometheus:
host: 127.0.0.1
port: 18888 # loopback; Prometheus скрейпит через шлюз otel-gw :8888 (mTLS)
without_units: true # классические имена: otelcol_exporter_sent_spans_total (без «_{spans}»)
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, resource/identity, transform/identity, attributes/scrub, batch]
exporters: [otlphttp/tempo]
metrics:
receivers: [otlp]
processors: [memory_limiter, resource/identity, transform/identity, batch]
exporters: [otlphttp/prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, resource/identity, transform/identity, attributes/scrub, batch]
exporters: [otlphttp/loki]