From 4f0f155af634261414a051817bb5f20ed48e57ef Mon Sep 17 00:00:00 2001 From: vasyukova Date: Sat, 31 Oct 2026 00:11:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=87=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=204=20(=D0=BD=D0=B5=D0=B4=D0=BE=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BD=D1=8B=D0=B5=20percentile):=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=D0=B8=20OTel=20SDK=20=D0=B4?= =?UTF-8?q?=D0=BE=201.31.0,=20=D0=B3=D0=B4=D0=B5=20explicit=5Fbucket=5Fbou?= =?UTF-8?q?ndaries=5Fadvisory=20=D1=80=D0=B5=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D0=BD=D1=8F=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20OTLP-=D1=8D=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82=D1=91?= =?UTF-8?q?=D1=80=D0=BE=D0=BC,=20=D0=BF=D0=BE=D1=8D=D1=82=D0=BE=D0=BC?= =?UTF-8?q?=D1=83=20=D0=B3=D0=B8=D1=81=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D1=8E=D1=82=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BC=D0=B8=D0=BB?= =?UTF-8?q?=D0=BB=D0=B8=D1=81=D0=B5=D0=BA=D1=83=D0=BD=D0=B4=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B2?= =?UTF-8?q?=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D0=B4=D0=B5=D1=84=D0=BE=D0=BB?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D1=85=20[0,=205,=2010,=20=E2=80=A6]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 10 +++++----- src/app/main.py | 9 +++++++++ src/app/worker.py | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index d75deb8..3d15f49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,8 +6,8 @@ redis==5.2.0 boto3==1.35.74 Pillow==11.0.0 pika==1.3.2 -opentelemetry-api==1.28.2 -opentelemetry-sdk==1.28.2 -opentelemetry-exporter-otlp-proto-http==1.28.2 -opentelemetry-instrumentation-fastapi==0.49b2 -opentelemetry-instrumentation-requests==0.49b2 \ No newline at end of file +opentelemetry-api==1.31.0 +opentelemetry-sdk==1.31.0 +opentelemetry-exporter-otlp-proto-http==1.31.0 +opentelemetry-instrumentation-fastapi==0.52b0 +opentelemetry-instrumentation-requests==0.52b0 \ No newline at end of file diff --git a/src/app/main.py b/src/app/main.py index 354c8ce..6514053 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -56,10 +56,19 @@ _http_counter = meter("messenger").create_counter( description="HTTP requests count", unit="1", ) +# Явные границы бакетов в СЕКУНДАХ, с разрешением в миллисекундном диапазоне +# и вокруг порога SLO 2s (upload p95 alert). Дефолтные экспоненциальные +# бакеты (0, 5, 10, 25, …) грубы: миллисекундные запросы попадали в один +# широкий bucket, а histogram_quantile интерполировал ложные секунды. +_HTTP_DURATION_BUCKETS = [ + 0.001, 0.0025, 0.005, 0.0075, 0.01, 0.015, 0.02, 0.03, 0.05, + 0.075, 0.1, 0.15, 0.2, 0.3, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0, 10.0, +] _http_hist = meter("messenger").create_histogram( "http_request_duration_seconds", description="HTTP request duration", unit="s", + explicit_bucket_boundaries_advisory=_HTTP_DURATION_BUCKETS, ) # Фильтр: убираем реальные UUID из маршрута → route template. diff --git a/src/app/worker.py b/src/app/worker.py index d646d8d..2528eb8 100644 --- a/src/app/worker.py +++ b/src/app/worker.py @@ -42,15 +42,25 @@ _stop = False _propagator = TraceContextTextMapPropagator() -# OTel инициализация — до первого сообщения. +# OTel инициализация — до первого сообщения init_telemetry("messenger-worker", "1.6.0") _tracer = trace.get_tracer("worker") _meter = meter("messenger-worker") _jobs_counter = _meter.create_counter( "jobs_processed_total", description="Jobs processed by outcome", unit="1", ) +# Явные границы бакетов в СЕКУНДАХ: job-обработка (decode + resize + 3×S3 PUT +# + DB) обычно от десятков мс до единиц секунд. Дефолтные экспоненциальные +# бакеты слишком грубы для p95/p99 на этой шкале. +_JOB_DURATION_BUCKETS = [ + 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.15, 0.25, 0.5, + 0.75, 1.0, 1.5, 2.0, 3.0, 5.0, 10.0, 30.0, +] _jobs_hist = _meter.create_histogram( - "job_processing_duration_seconds", description="Job processing duration", unit="s", + "job_processing_duration_seconds", + description="Job processing duration", + unit="s", + explicit_bucket_boundaries_advisory=_JOB_DURATION_BUCKETS, )