ЛР6 - БВТ2302 - Зюлина - на 3

This commit is contained in:
2026-11-23 19:12:15 +03:00
parent 470d9d6f1e
commit 6fdb550abc
41 changed files with 2233 additions and 20 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
set -eu
until mc alias set local http://minio:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" >/dev/null 2>&1; do sleep 2; done
mc mb --ignore-existing "local/$S3_BUCKET"
mc anonymous set none "local/$S3_BUCKET"
if ! mc admin user info local "$S3_ACCESS_KEY" >/dev/null 2>&1; then
mc admin user add local "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
fi
cat >/tmp/attachment-policy.json <<EOF
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::$S3_BUCKET"],"Condition":{"StringLike":{"s3:prefix":["staging/*","original/*","variants/*"]}}},{"Effect":"Allow","Action":["s3:GetObject","s3:PutObject","s3:DeleteObject"],"Resource":["arn:aws:s3:::$S3_BUCKET/staging/*","arn:aws:s3:::$S3_BUCKET/original/*","arn:aws:s3:::$S3_BUCKET/variants/*"]}]}
EOF
if ! mc admin policy info local attachments-api >/dev/null 2>&1; then
mc admin policy create local attachments-api /tmp/attachment-policy.json
fi
mc admin policy attach local attachments-api --user "$S3_ACCESS_KEY"
+42
View File
@@ -0,0 +1,42 @@
upstream api_backend {
zone api_backend 64k;
resolver 127.0.0.11 valid=2s ipv6=off;
server api1:8080 resolve max_fails=1 fail_timeout=2s;
server api2:8080 resolve max_fails=1 fail_timeout=2s;
}
server {
listen 8080;
# Leave a small margin so the API returns its documented JSON 413 at 10 MiB.
client_max_body_size 11m;
client_body_timeout 20s;
proxy_connect_timeout 1s;
proxy_send_timeout 20s;
proxy_read_timeout 20s;
error_page 502 504 = @upstream_unavailable;
location / {
proxy_pass http://api_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Request-Id $request_id;
proxy_intercept_errors on;
# Retry GET/HEAD on a failed backend. Nginx never replays a POST after
# its request has been sent unless `non_idempotent` is enabled; uploads
# therefore remain single-shot, while message retries stay client-led.
proxy_next_upstream error timeout http_502 http_503 http_504;
proxy_next_upstream_tries 2;
proxy_next_upstream_timeout 5s;
}
# Keep the public API error contract when all upstreams are unavailable.
location @upstream_unavailable {
default_type application/json;
add_header X-Request-Id $request_id always;
add_header X-Instance-Id "lb" always;
return 503 '{"error":{"code":"unavailable","message":"API upstream unavailable","request_id":"$request_id"}}';
}
}
+59
View File
@@ -0,0 +1,59 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
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: 512
send_batch_max_size: 1024
exporters:
prometheus:
endpoint: 0.0.0.0:8889
resource_constant_labels:
included: [service.name, service.instance.id, service.version, deployment.environment.name]
otlp_grpc/tempo:
endpoint: tempo:4317
tls:
insecure: true
sending_queue:
enabled: true
num_consumers: 2
queue_size: 512
retry_on_failure:
enabled: true
max_elapsed_time: 30s
otlp_http/loki:
logs_endpoint: http://loki:3100/otlp/v1/logs
sending_queue:
enabled: true
num_consumers: 2
queue_size: 512
retry_on_failure:
enabled: true
max_elapsed_time: 30s
extensions:
health_check:
endpoint: 0.0.0.0:13133
service:
extensions: [health_check]
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_grpc/tempo]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/loki]
@@ -0,0 +1,17 @@
{
"uid": "messenger-overview",
"title": "Messenger observability",
"tags": ["lab6", "messenger"],
"timezone": "browser",
"schemaVersion": 39,
"version": 1,
"refresh": "5s",
"time": {"from": "now-15m", "to": "now"},
"panels": [
{"id": 1, "type": "timeseries", "title": "HTTP requests per second", "datasource": {"type": "prometheus", "uid": "prometheus"}, "gridPos": {"h": 8, "w": 12, "x": 0, "y": 0}, "targets": [{"expr": "sum by (service_name) (rate(messenger_http_requests_total[1m]))", "legendFormat": "{{service_name}}", "refId": "A"}], "fieldConfig": {"defaults": {"unit": "reqps"}, "overrides": []}},
{"id": 2, "type": "timeseries", "title": "HTTP 5xx per second", "datasource": {"type": "prometheus", "uid": "prometheus"}, "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0}, "targets": [{"expr": "sum(rate(messenger_http_requests_total{http_response_status_class=\"5xx\"}[1m]))", "legendFormat": "5xx", "refId": "A"}], "fieldConfig": {"defaults": {"unit": "reqps"}, "overrides": []}},
{"id": 3, "type": "timeseries", "title": "HTTP request duration p95", "datasource": {"type": "prometheus", "uid": "prometheus"}, "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}, "targets": [{"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket[5m])))", "legendFormat": "p95", "refId": "A"}], "fieldConfig": {"defaults": {"unit": "s"}, "overrides": []}},
{"id": 4, "type": "timeseries", "title": "Attachment jobs by outcome", "datasource": {"type": "prometheus", "uid": "prometheus"}, "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}, "targets": [{"expr": "sum by (job_outcome) (rate(messenger_jobs_processed_total[1m]))", "legendFormat": "{{job_outcome}}", "refId": "A"}], "fieldConfig": {"defaults": {"unit": "ops"}, "overrides": []}},
{"id": 5, "type": "timeseries", "title": "Worker processing duration p95", "datasource": {"type": "prometheus", "uid": "prometheus"}, "gridPos": {"h": 8, "w": 24, "x": 0, "y": 16}, "targets": [{"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_jobs_duration_seconds_bucket[5m])))", "legendFormat": "p95", "refId": "A"}], "fieldConfig": {"defaults": {"unit": "s"}, "overrides": []}}
]
}
@@ -0,0 +1,10 @@
apiVersion: 1
providers:
- name: messenger
orgId: 1
folder: Messenger
type: file
disableDeletion: false
editable: true
options:
path: /etc/grafana/provisioning/dashboards-json
@@ -0,0 +1,33 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
- name: Loki
uid: loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
derivedFields:
- name: TraceID
matcherRegex: 'trace_id="?([a-f0-9]{32})"?'
datasourceUid: tempo
url: '$${__value.raw}'
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: http://tempo:3200
jsonData:
tracesToLogsV2:
datasourceUid: loki
spanStartTimeShift: "-1m"
spanEndTimeShift: "1m"
filterByTraceID: true
filterBySpanID: false
customQuery: true
query: '{${__tags}} | trace_id="${__trace.traceId}"'
+30
View File
@@ -0,0 +1,30 @@
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
path_prefix: /loki
replication_factor: 1
ring:
kvstore:
store: inmemory
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
schema_config:
configs:
- from: "2024-01-01"
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
allow_structured_metadata: true
retention_period: 168h
compactor:
working_directory: /loki/retention
retention_enabled: true
delete_request_store: filesystem
+7
View File
@@ -0,0 +1,7 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: otel-collector
static_configs:
- targets: [otel-collector:8889]
+27
View File
@@ -0,0 +1,27 @@
stream_over_http_enabled: true
server:
http_listen_port: 3200
grpc_listen_port: 9095
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
ingester:
max_block_duration: 5m
trace_idle_period: 10s
compactor:
compaction:
block_retention: 168h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
block:
version: vParquet4