Implement Lab 7 service security
This commit is contained in:
@@ -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).
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
extensions:
|
||||
bearertokenauth/ingest:
|
||||
filename: /run/secrets/otel_ingest
|
||||
bearertokenauth/storage:
|
||||
filename: /run/secrets/otel_write
|
||||
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /run/tls/collector.crt
|
||||
key_file: /run/tls/collector.key
|
||||
auth:
|
||||
authenticator: bearertokenauth/ingest
|
||||
|
||||
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
|
||||
tls:
|
||||
cert_file: /run/tls/collector.crt
|
||||
key_file: /run/tls/collector.key
|
||||
metric_expiration: 5m
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
otlphttp/loki:
|
||||
endpoint: https://telemetry-edge:9443/otlp
|
||||
tls:
|
||||
ca_file: /run/tls/ca.crt
|
||||
auth:
|
||||
authenticator: bearertokenauth/storage
|
||||
timeout: 3s
|
||||
sending_queue:
|
||||
queue_size: 128
|
||||
retry_on_failure:
|
||||
max_elapsed_time: 30s
|
||||
otlphttp/tempo:
|
||||
endpoint: https://telemetry-edge:9444
|
||||
tls:
|
||||
ca_file: /run/tls/ca.crt
|
||||
auth:
|
||||
authenticator: bearertokenauth/storage
|
||||
timeout: 3s
|
||||
sending_queue:
|
||||
queue_size: 128
|
||||
retry_on_failure:
|
||||
max_elapsed_time: 30s
|
||||
|
||||
service:
|
||||
extensions: [bearertokenauth/ingest, bearertokenauth/storage]
|
||||
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,46 @@
|
||||
global
|
||||
maxconn 256
|
||||
ssl-default-bind-options ssl-min-ver TLSv1.2
|
||||
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 3s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
default-server inter 2s
|
||||
|
||||
listen grafana
|
||||
bind :9445 ssl crt /run/tls/telemetry-edge.pem
|
||||
http-request set-header X-Forwarded-Proto https
|
||||
server grafana 127.0.0.1:3000
|
||||
|
||||
listen prometheus-query
|
||||
bind :9440 ssl crt /run/tls/telemetry-edge.pem
|
||||
http-request deny unless { req.hdr(Authorization) -m str -f /run/secrets/grafana_read_header }
|
||||
http-request deny unless { method GET } or { path /api/v1/query /api/v1/query_range }
|
||||
http-request del-header Authorization
|
||||
server prometheus 127.0.0.1:9090
|
||||
|
||||
listen loki-query
|
||||
bind :9441 ssl crt /run/tls/telemetry-edge.pem
|
||||
http-request deny unless { req.hdr(Authorization) -m str -f /run/secrets/grafana_read_header } { method GET }
|
||||
http-request del-header Authorization
|
||||
server loki 127.0.0.1:3100
|
||||
|
||||
listen tempo-query
|
||||
bind :9442 ssl crt /run/tls/telemetry-edge.pem
|
||||
http-request deny unless { req.hdr(Authorization) -m str -f /run/secrets/grafana_read_header } { method GET }
|
||||
http-request del-header Authorization
|
||||
server tempo 127.0.0.1:3200
|
||||
|
||||
listen loki-write
|
||||
bind :9443 ssl crt /run/tls/telemetry-edge.pem
|
||||
http-request deny unless { req.hdr(Authorization) -m str -f /run/secrets/otel_write_header } { method POST } { path /otlp/v1/logs }
|
||||
http-request del-header Authorization
|
||||
server loki 127.0.0.1:3100
|
||||
|
||||
listen tempo-write
|
||||
bind :9444 ssl crt /run/tls/telemetry-edge.pem
|
||||
http-request deny unless { req.hdr(Authorization) -m str -f /run/secrets/otel_write_header } { method POST } { path /v1/traces }
|
||||
http-request del-header Authorization
|
||||
server tempo 127.0.0.1:4318
|
||||
@@ -0,0 +1,182 @@
|
||||
{
|
||||
"uid": "lab-messenger",
|
||||
"title": "Мессенджер — лабораторная 7",
|
||||
"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,37 @@
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: lab-prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: https://telemetry-edge:9440
|
||||
isDefault: true
|
||||
jsonData:
|
||||
timeInterval: 5s
|
||||
httpHeaderName1: Authorization
|
||||
secureJsonData:
|
||||
httpHeaderValue1: $GF_LAB_QUERY
|
||||
- name: Loki
|
||||
uid: lab-loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: https://telemetry-edge:9441
|
||||
jsonData:
|
||||
httpHeaderName1: Authorization
|
||||
derivedFields:
|
||||
- name: Trace
|
||||
matcherRegex: '"trace_id":"([0-9a-f]{32})"'
|
||||
datasourceUid: lab-tempo
|
||||
url: '$${__value.raw}'
|
||||
secureJsonData:
|
||||
httpHeaderValue1: $GF_LAB_QUERY
|
||||
- name: Tempo
|
||||
uid: lab-tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: https://telemetry-edge:9442
|
||||
jsonData:
|
||||
httpHeaderName1: Authorization
|
||||
secureJsonData:
|
||||
httpHeaderValue1: $GF_LAB_QUERY
|
||||
@@ -0,0 +1,51 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
http_listen_port: 3100
|
||||
grpc_listen_address: 127.0.0.1
|
||||
grpc_listen_port: 9096
|
||||
|
||||
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
|
||||
@@ -0,0 +1,13 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector
|
||||
honor_labels: true
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/tls/ca.crt
|
||||
server_name: otel-collector
|
||||
static_configs:
|
||||
- targets: ["otel-collector:9464"]
|
||||
@@ -0,0 +1,26 @@
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
http_listen_port: 3200
|
||||
grpc_listen_address: 127.0.0.1
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1: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
|
||||
Reference in New Issue
Block a user