ЛР 6: OpenTelemetry, Prometheus, Loki, Tempo и Grafana — на 3

This commit is contained in:
2026-11-20 21:52:10 +03:00
parent 470d9d6f1e
commit dc7745064d
72 changed files with 4684 additions and 44 deletions
+15
View File
@@ -0,0 +1,15 @@
FROM docker:27.5.1-cli
RUN apk add --no-cache python3 py3-pip make && python3 -m venv /opt/venv
ENV PATH=/opt/venv/bin:$PATH PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /workspace
COPY infra/requirements-tools.lock /tmp/requirements-tools.lock
RUN pip install --no-cache-dir -r /tmp/requirements-tools.lock
COPY Makefile lab.json README.md COURSE.md CONTRIBUTING.md REPORT.md ./
COPY contracts/ ./contracts/
COPY tests/ ./tests/
COPY scripts/check_contract.py scripts/validate_openapi.py ./scripts/
COPY --chmod=0755 scripts/restart.sh scripts/stop-one.sh scripts/lab-containers.sh ./scripts/
RUN mkdir -p /workspace/evidence
COPY student-tests/ ./student-tests/
ENTRYPOINT []
CMD ["make", "check"]
+176
View File
@@ -0,0 +1,176 @@
{
"title": "ЛР6 · Messenger",
"uid": "lab6-messenger",
"schemaVersion": 39,
"version": 1,
"editable": false,
"time": {
"from": "now-15m",
"to": "now"
},
"refresh": "10s",
"timezone": "browser",
"panels": [
{
"id": 1,
"title": "API · запросы/с",
"type": "timeseries",
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (method, route) (rate(messenger_http_requests_total{route!~\"/health/.*\"}[1m]))"
}
]
},
{
"id": 2,
"title": "API · 4xx и 5xx/с",
"type": "timeseries",
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (status_class) (rate(messenger_http_requests_total{status_class=~\"4xx|5xx\",route!~\"/health/.*\"}[1m]))"
}
]
},
{
"id": 3,
"title": "API · средняя длительность",
"type": "timeseries",
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_duration_seconds_sum{route!~\"/health/.*\"}[1m])) / sum(rate(messenger_http_duration_seconds_count{route!~\"/health/.*\"}[1m]))"
}
]
},
{
"id": 4,
"title": "Worker · успешные и неуспешные задания",
"type": "timeseries",
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (messenger_job_outcomes_total)"
}
]
},
{
"id": 5,
"title": "Worker · средняя длительность",
"type": "timeseries",
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (messenger_job_duration_seconds_sum) / sum by (outcome) (messenger_job_duration_seconds_count)"
}
]
},
{
"id": 6,
"title": "События API и worker",
"type": "logs",
"gridPos": {
"x": 0,
"y": 24,
"w": 24,
"h": 10
},
"datasource": {
"type": "loki",
"uid": "lab6-loki"
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-api|messenger-worker\"} | event != \"\"",
"queryType": "range"
}
],
"options": {
"showTime": true,
"enableLogDetails": true
}
}
]
}
@@ -0,0 +1,8 @@
apiVersion: 1
providers:
- name: lab6
type: file
disableDeletion: true
updateIntervalSeconds: 30
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,30 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: lab6-prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
editable: false
jsonData:
timeInterval: 5s
- name: Loki
uid: lab6-loki
type: loki
access: proxy
url: http://loki:3100
editable: false
jsonData:
derivedFields:
- name: Trace
matcherType: label
matcherRegex: trace_id
datasourceUid: lab6-tempo
url: '$${__value.raw}'
- name: Tempo
uid: lab6-tempo
type: tempo
access: proxy
url: http://tempo:3200
editable: false
+29
View File
@@ -0,0 +1,29 @@
defaults
mode http
timeout http-request 5s
timeout connect 500ms
timeout client 15s
timeout server 10s
timeout check 1s
retries 1
retry-on conn-failure
option redispatch
resolvers docker
nameserver embedded 127.0.0.11:53
timeout resolve 500ms
timeout retry 500ms
hold valid 1s
hold nx 1s
frontend public_http
bind :8080
default_backend messenger
backend messenger
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
default-server check inter 1s fastinter 500ms downinter 1s fall 2 rise 1 resolvers docker init-addr none resolve-prefer ipv4
server api1 api1:8080
server api2 api2:8080
+51
View File
@@ -0,0 +1,51 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 128
spike_limit_mib: 32
batch:
timeout: 1s
send_batch_size: 256
send_batch_max_size: 512
exporters:
prometheus:
endpoint: 0.0.0.0:8889
metric_expiration: 5m
otlphttp/loki:
endpoint: http://loki:3100/otlp
timeout: 3s
sending_queue: {queue_size: 32, num_consumers: 2}
retry_on_failure: {initial_interval: 1s, max_interval: 5s, max_elapsed_time: 20s}
otlp/tempo:
endpoint: tempo:4317
tls: {insecure: true}
timeout: 3s
sending_queue: {queue_size: 32, num_consumers: 2}
retry_on_failure: {initial_interval: 1s, max_interval: 5s, max_elapsed_time: 20s}
service:
extensions: [health_check]
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: [otlp/tempo]
+39
View File
@@ -0,0 +1,39 @@
auth_enabled: false
analytics:
reporting_enabled: false
server:
http_listen_port: 3100
log_level: warn
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}
ingester:
wal:
dir: /loki/wal
flush_on_shutdown: true
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
limits_config:
allow_structured_metadata: true
retention_period: 48h
otlp_config:
resource_attributes:
ignore_defaults: true
attributes_config:
- action: index_label
attributes: [service.name]
+8
View File
@@ -0,0 +1,8 @@
global:
scrape_interval: 5s
scrape_timeout: 3s
scrape_configs:
- job_name: otel-collector
honor_labels: true
static_configs:
- targets: ['otel-collector:8889']
+24
View File
@@ -0,0 +1,24 @@
server:
http_listen_port: 3200
log_level: warn
usage_report:
reporting_enabled: false
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
ingester:
max_block_duration: 30s
flush_all_on_shutdown: true
compactor:
compaction:
block_retention: 48h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
+20
View File
@@ -0,0 +1,20 @@
attrs==26.1.0
certifi==2026.10.23
charset-normalizer==3.5.2
idna==3.20
jsonschema==4.26.0
jsonschema-path==0.3.4
jsonschema-specifications==2025.9.1
lazy-object-proxy==1.13.0
openapi-schema-validator==0.6.3
openapi-spec-validator==0.7.2
pathable==0.4.4
PyYAML==6.0.3
referencing==0.36.2
requests==2.34.2
rfc3339-validator==0.1.4
rpds-py==2026.9.1
six==1.17.0
typing_extensions==4.16.0
urllib3==2.8.0
Pillow==12.2.0