From f1963e5f199c40310d486f7a1257f439367620d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=85=D0=B2=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A0=D0=B5?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 2 Oct 2026 17:06:13 +0300 Subject: [PATCH] Bound Tempo blocks and complete telemetry diagnostics --- compose.telemetry.yaml | 1 + infra/grafana/dashboards/telemetry.json | 22 ++++++++++++++++++---- infra/tempo/config.yaml | 5 +++++ scripts/slo_watch.py | 2 +- src/store.py | 16 +++++++++++----- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/compose.telemetry.yaml b/compose.telemetry.yaml index 89358ff..2513324 100644 --- a/compose.telemetry.yaml +++ b/compose.telemetry.yaml @@ -34,6 +34,7 @@ services: tempo: image: grafana/tempo:2.9.5 + mem_limit: 768m command: ["-config.file=/etc/tempo/config.yaml"] volumes: - ./infra/tempo/config.yaml:/etc/tempo/config.yaml:ro diff --git a/infra/grafana/dashboards/telemetry.json b/infra/grafana/dashboards/telemetry.json index adfc8da..d4d3559 100644 --- a/infra/grafana/dashboards/telemetry.json +++ b/infra/grafana/dashboards/telemetry.json @@ -94,7 +94,7 @@ "targets": [ { "refId": "A", - "expr": "sum(rate(messenger_http_requests_total{status_class=\"5xx\",route!~\"/health/.*\"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total{route!~\"/health/.*\"}[1m])),0.001)", + "expr": "(sum(rate(messenger_http_requests_total{status_class=\"5xx\",route!~\"/health/.*\"}[1m])) or vector(0)) / clamp_min(sum(rate(messenger_http_requests_total{route!~\"/health/.*\"}[1m])),0.001)", "legendFormat": "series 1" } ], @@ -519,17 +519,17 @@ }, { "refId": "B", - "expr": "sum(rate(otelcol_exporter_send_failed_metric_points_total[1m]))", + "expr": "sum(rate(otelcol_exporter_send_failed_metric_points[1m]))", "legendFormat": "series 2" }, { "refId": "C", - "expr": "sum(rate(otelcol_exporter_send_failed_log_records_total[1m]))", + "expr": "sum(rate(otelcol_exporter_send_failed_log_records[1m]))", "legendFormat": "series 3" }, { "refId": "D", - "expr": "sum(rate(otelcol_exporter_send_failed_spans_total[1m]))", + "expr": "sum(rate(otelcol_exporter_send_failed_spans[1m]))", "legendFormat": "series 4" } ], @@ -587,6 +587,20 @@ "x": 0, "y": 56 } + }, + { + "id": 16, + "type": "timeseries", + "title": "HTTP 4xx RPS (client responses)", + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "targets": [{ + "refId": "A", + "expr": "sum(rate(messenger_http_requests_total{status_class=\"4xx\",route!~\"/health/.*\"}[1m])) or vector(0)", + "legendFormat": "4xx" + }], + "fieldConfig": {"defaults": {"unit": "reqps", "min": 0}, "overrides": []}, + "options": {"legend": {"displayMode": "list", "placement": "bottom"}}, + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 56} } ] } diff --git a/infra/tempo/config.yaml b/infra/tempo/config.yaml index 9f813a2..14f76b5 100644 --- a/infra/tempo/config.yaml +++ b/infra/tempo/config.yaml @@ -8,6 +8,11 @@ distributor: grpc: endpoint: 0.0.0.0:4317 +ingester: + max_block_bytes: 5000000 + max_block_duration: 1m + concurrent_flushes: 1 + storage: trace: backend: local diff --git a/scripts/slo_watch.py b/scripts/slo_watch.py index 2c0b0eb..1f4b98a 100644 --- a/scripts/slo_watch.py +++ b/scripts/slo_watch.py @@ -14,7 +14,7 @@ QUERIES = { "http_5xx_ratio_30s": 'sum(rate(messenger_http_requests_total{status_class="5xx",route!~"/health/.*"}[30s])) / clamp_min(sum(rate(messenger_http_requests_total{route!~"/health/.*"}[30s])),0.001)', "queue_oldest_seconds": 'max(messenger_queue_oldest_age_seconds{queue_name="attachments.process"})', "ready_slow_ratio_30s": '(sum(rate(messenger_attachments_ready_duration_seconds_count[30s])) - sum(rate(messenger_attachments_ready_duration_seconds_bucket{le="5"}[30s]))) / clamp_min(sum(rate(messenger_attachments_ready_duration_seconds_count[30s])),0.001)', - "collector_failed_spans": 'sum(otelcol_exporter_send_failed_spans_total)', + "collector_failed_spans": 'sum(otelcol_exporter_send_failed_spans)', } diff --git a/src/store.py b/src/store.py index 298109a..0a701b0 100644 --- a/src/store.py +++ b/src/store.py @@ -14,6 +14,8 @@ import psycopg from argon2 import PasswordHasher from argon2.exceptions import InvalidHashError, VerificationError from fastapi import HTTPException +from opentelemetry import trace +from opentelemetry.trace import Status, StatusCode from psycopg.errors import UniqueViolation from psycopg_pool import PoolTimeout @@ -21,6 +23,7 @@ from . import db from .auth import BASIC_CHALLENGE, BEARER_CHALLENGE, token_hash, unauthorized password_hasher = PasswordHasher() +tracer = trace.get_tracer(__name__) def timestamp(value: datetime) -> str: @@ -53,11 +56,14 @@ def decode_cursor(cursor: str | None, resource: str) -> tuple[datetime, UUID] | @contextmanager def connection(): - try: - with db.pool().connection() as conn: - yield conn - except (psycopg.Error, PoolTimeout, OSError): - raise HTTPException(503) from None + with tracer.start_as_current_span("db.store", record_exception=False, set_status_on_exception=False) as span: + span.set_attribute("db.system.name", "postgresql") + try: + with db.pool().connection() as conn: + yield conn + except (psycopg.Error, PoolTimeout, OSError): + span.set_status(Status(StatusCode.ERROR)) + raise HTTPException(503) from None def user_view(row: dict) -> dict: