Files
mtusi2026lab7/infra/otel/collector.yaml
T

116 lines
4.3 KiB
YAML

# OpenTelemetry Collector (otel/opentelemetry-collector-contrib 0.165.0), labs 6-7.
#
# API x2 / relay / worker --OTLP/HTTPS (mTLS) :4318--> [receiver otlp]
# -> memory_limiter -> batch -> exporters (all HTTPS + client certificate otel-collector):
# traces -> Tempo (otlp_http/tempo, https://tempo:4318/v1/traces)
# metrics -> Prometheus (otlp_http/prometheus, https://prometheus:9090/api/v1/otlp/v1/metrics)
# logs -> Loki (otlp_http/loki, https://loki:3100/otlp/v1/logs)
#
# Lab 7 (contracts/trust-matrix.md): the receiver speaks TLS only and REQUIRES a client certificate
# of the internal CA (client_ca_file): a process on the `telemetry` network without such a
# certificate cannot ingest anything. Every exporter verifies the backend (internal CA + hostname)
# and authenticates with the Collector's own certificate (SAN otel-collector); Prometheus also
# checks that SAN against its allowlist.
# The Collector stores nothing for long: it receives, limits, batches and forwards. When a backend
# is down, each exporter keeps a BOUNDED queue (sending_queue) and retries for at most
# max_elapsed_time; then the data is dropped and counted (otelcol_exporter_send_failed_*,
# otelcol_exporter_enqueue_failed_*). memory_limiter refuses new data above its limit.
# Its own metrics: PUSHED over OTLP/HTTPS to Prometheus (lab 7; the lab 6 pull endpoint :8888 had no
# TLS). health_check listens on the container's loopback only.
#
# Traces pipeline variants (lab 6 track 1): this file keeps EVERY span; the overlay
# traces-tail.yaml (passed as a second --config, compose OTEL_COLLECTOR_TRACES) adds tail sampling.
extensions:
health_check:
endpoint: 127.0.0.1:13133
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
max_request_body_size: 8388608 # 8 MiB per export request
tls:
cert_file: /run/secrets/otel-collector.crt
key_file: /run/secrets/otel-collector.key
client_ca_file: /run/secrets/internal-ca.crt # = RequireAndVerifyClientCert
min_version: "1.2"
processors:
# First in every pipeline. Container limit 512 MiB: soft limit = 400 - 80 = 320 MiB (start
# refusing + GC), hard limit 400 MiB (forced GC). The contrib binary alone is ~150 MiB RSS.
memory_limiter:
check_interval: 1s
limit_mib: 400
spike_limit_mib: 80
# Fewer, larger requests to the backends; at most 2 s of delay.
batch:
send_batch_size: 1024
send_batch_max_size: 2048
timeout: 2s
exporters:
otlp_http/tempo:
endpoint: https://tempo:4318
timeout: 5s
tls: &mtls
ca_file: /run/secrets/internal-ca.crt
cert_file: /run/secrets/otel-collector.crt
key_file: /run/secrets/otel-collector.key
min_version: "1.2"
sending_queue: &queue
enabled: true
num_consumers: 2
queue_size: 100 # batches (<= 2048 items each): bounded, in memory only
retry_on_failure: &retry
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 60s # then the batch is dropped (counted), never retried forever
otlp_http/prometheus:
endpoint: https://prometheus:9090/api/v1/otlp
timeout: 5s
tls: *mtls
sending_queue: *queue
retry_on_failure: *retry
otlp_http/loki:
endpoint: https://loki:3100/otlp
timeout: 5s
tls: *mtls
sending_queue: *queue
retry_on_failure: *retry
service:
extensions: [health_check]
telemetry:
resource:
service.name: otel-collector
logs:
level: warn
metrics:
level: normal
readers:
- periodic:
interval: 15000
exporter:
otlp:
protocol: http/protobuf
endpoint: https://prometheus:9090/api/v1/otlp/v1/metrics
certificate: /run/secrets/internal-ca.crt
client_certificate: /run/secrets/otel-collector.crt
client_key: /run/secrets/otel-collector.key
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/tempo]
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/loki]