Files
mtusi2026lab6/infra/otel/grafana/dashboards/messenger-lab6.json
T

415 lines
23 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"uid": "messenger-lab6",
"title": "Messenger — API, worker, relay (lab 6)",
"description": "Signals of contracts/observability.md, levels 3 and 4 (backlog, saturation, time to ready, SLO and alerts — the last row). Metric names are Prometheus forms of OTel instruments: http.server.request.duration -> http_server_request_duration_seconds_*, messenger.job.duration -> messenger_job_duration_seconds_*, messenger.relay.jobs -> messenger_relay_jobs_total. Request counts are _count of the duration histogram; health is not recorded.",
"tags": ["messenger", "lab6", "opentelemetry"],
"editable": false,
"schemaVersion": 39,
"version": 1,
"time": {"from": "now-30m", "to": "now"},
"refresh": "30s",
"timezone": "utc",
"graphTooltip": 1,
"templating": {"list": []},
"annotations": {"list": []},
"links": [],
"panels": [
{
"id": 1,
"type": "row",
"title": "Messenger API replicas",
"collapsed": false,
"gridPos": {"h": 1, "w": 24, "x": 0, "y": 0},
"panels": []
},
{
"id": 2,
"type": "timeseries",
"title": "Request rate: route x status class",
"description": "rate of http_server_request_duration_seconds_count over all replicas; label http_route is the route template.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 1},
"fieldConfig": {"defaults": {"unit": "reqps"}, "overrides": []},
"options": {"legend": {"displayMode": "table", "placement": "right", "calcs": ["lastNotNull"]}},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "sum by (http_request_method, http_route, http_response_status_class) (rate(http_server_request_duration_seconds_count{job=\"messenger-api\"}[$__rate_interval]))",
"legendFormat": "{{http_request_method}} {{http_route}} {{http_response_status_class}}"
}
]
},
{
"id": 3,
"type": "timeseries",
"title": "Server error ratio (5xx / all business requests)",
"description": "Numerator: responses 5xx of the API replicas. Denominator: all API responses except health (health is not recorded). 4xx — client errors, shown separately.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 6, "x": 12, "y": 1},
"fieldConfig": {"defaults": {"unit": "percentunit", "min": 0, "max": 1}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "(sum(rate(http_server_request_duration_seconds_count{job=\"messenger-api\", http_response_status_class=\"5xx\"}[5m])) or vector(0)) / sum(rate(http_server_request_duration_seconds_count{job=\"messenger-api\"}[5m]))",
"legendFormat": "5xx ratio"
}
]
},
{
"id": 4,
"type": "timeseries",
"title": "Client errors (4xx) per second by route",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 6, "x": 18, "y": 1},
"fieldConfig": {"defaults": {"unit": "reqps"}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "sum by (http_route, http_response_status_code) (rate(http_server_request_duration_seconds_count{job=\"messenger-api\", http_response_status_class=\"4xx\"}[$__rate_interval]))",
"legendFormat": "{{http_response_status_code}} {{http_route}}"
}
]
},
{
"id": 5,
"type": "timeseries",
"title": "Request duration p50 / p95 / p99 (from histogram buckets of all replicas)",
"description": "Unit: seconds. histogram_quantile(q, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\"}[5m]))) for q = 0.5, 0.95, 0.99 — buckets of every replica are summed first, not an average of per-replica percentiles. Accuracy is bounded by bucket edges (TELEMETRY_HISTOGRAM_BUCKETS).",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 9},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "histogram_quantile(0.5, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\"}[5m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\"}[5m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\"}[5m])))",
"legendFormat": "p99"
}
]
},
{
"id": 6,
"type": "timeseries",
"title": "p95 latency per route",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 9},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"options": {"legend": {"displayMode": "table", "placement": "right", "calcs": ["lastNotNull"]}},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "histogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\"}[5m])))",
"legendFormat": "{{http_route}}"
}
]
},
{
"id": 7,
"type": "row",
"title": "Background processing (messenger-worker, messenger-relay)",
"collapsed": false,
"gridPos": {"h": 1, "w": 24, "x": 0, "y": 17},
"panels": []
},
{
"id": 8,
"type": "timeseries",
"title": "Job deliveries per second by outcome",
"description": "ready — variants committed; failed — permanent error; retry — scheduled again with backoff; finished/leased/stale/fenced — no-op duplicates; unavailable/error/rejected/cancelled — delivery not completed.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 0, "y": 18},
"fieldConfig": {"defaults": {"unit": "ops"}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "sum by (messenger_job_type, messenger_job_outcome) (rate(messenger_job_duration_seconds_count{job=\"messenger-worker\"}[$__rate_interval]))",
"legendFormat": "{{messenger_job_outcome}}"
}
]
},
{
"id": 9,
"type": "stat",
"title": "Unsuccessful job deliveries, last 1h",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 4, "x": 8, "y": 18},
"fieldConfig": {"defaults": {"unit": "short", "decimals": 0}, "overrides": []},
"options": {"reduceOptions": {"calcs": ["lastNotNull"]}, "colorMode": "value", "textMode": "value_and_name"},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "sum by (messenger_job_outcome) (increase(messenger_job_duration_seconds_count{job=\"messenger-worker\", messenger_job_outcome=~\"failed|retry|error|unavailable|rejected|cancelled\"}[1h]))",
"legendFormat": "{{messenger_job_outcome}}"
}
]
},
{
"id": 10,
"type": "timeseries",
"title": "Job delivery duration p50 / p95 by outcome",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 18},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "histogram_quantile(0.5, sum by (le, messenger_job_outcome) (rate(messenger_job_duration_seconds_bucket{job=\"messenger-worker\"}[5m])))",
"legendFormat": "p50 {{messenger_job_outcome}}"
},
{
"refId": "B",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "histogram_quantile(0.95, sum by (le, messenger_job_outcome) (rate(messenger_job_duration_seconds_bucket{job=\"messenger-worker\"}[5m])))",
"legendFormat": "p95 {{messenger_job_outcome}}"
}
]
},
{
"id": 11,
"type": "timeseries",
"title": "Relay: jobs per second by action",
"description": "published — confirmed by the broker; requeued/exhausted — expired leases; republished — lost messages; failed_* — passes interrupted by the broker or PostgreSQL.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 7, "w": 12, "x": 0, "y": 26},
"fieldConfig": {"defaults": {"unit": "ops"}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "sum by (messenger_relay_action) (rate(messenger_relay_jobs_total{job=\"messenger-relay\"}[$__rate_interval]))",
"legendFormat": "{{messenger_relay_action}}"
}
]
},
{
"id": 12,
"type": "stat",
"title": "Scrape targets up",
"description": "messenger — exporter of the Collector with application metrics; the rest — the telemetry pipeline itself.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 7, "w": 12, "x": 12, "y": 26},
"fieldConfig": {"defaults": {"unit": "short", "decimals": 0, "thresholds": {"mode": "absolute", "steps": [{"color": "red", "value": null}, {"color": "green", "value": 1}]}}, "overrides": []},
"options": {"reduceOptions": {"calcs": ["lastNotNull"]}, "colorMode": "background", "textMode": "value_and_name"},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "up",
"legendFormat": "{{job}}"
}
]
},
{
"id": 13,
"type": "row",
"title": "Loki logs and Tempo traces",
"collapsed": false,
"gridPos": {"h": 1, "w": 24, "x": 0, "y": 33},
"panels": []
},
{
"id": 14,
"type": "logs",
"title": "Application logs (Loki): messenger-api, messenger-worker, messenger-relay",
"description": "Each record carries event, logger, request_id (inside a request) and trace_id/span_id (inside a sampled span); the TraceID link opens the trace in Tempo.",
"datasource": {"type": "loki", "uid": "logs"},
"gridPos": {"h": 10, "w": 24, "x": 0, "y": 34},
"options": {"showTime": true, "wrapLogMessage": true, "sortOrder": "Descending", "enableLogDetails": true, "dedupStrategy": "none"},
"targets": [
{
"refId": "A",
"datasource": {"type": "loki", "uid": "logs"},
"expr": "{service_name=~\"messenger-.+\"}",
"queryType": "range"
}
]
},
{
"id": 15,
"type": "table",
"title": "Recent traces (Tempo): API requests and worker jobs",
"description": "TraceQL search; open a trace ID to see server/consumer spans with PostgreSQL, S3 and render children.",
"datasource": {"type": "tempo", "uid": "traces"},
"gridPos": {"h": 10, "w": 24, "x": 0, "y": 44},
"targets": [
{
"refId": "A",
"datasource": {"type": "tempo", "uid": "traces"},
"queryType": "traceql",
"query": "{resource.service.name=~\"messenger-.+\" && (kind=server || kind=consumer)}",
"limit": 20,
"tableType": "traces"
}
]
},
{
"id": 16,
"type": "row",
"title": "Backlog, saturation and SLO (level 4)",
"collapsed": false,
"gridPos": {"h": 1, "w": 24, "x": 0, "y": 54},
"panels": []
},
{
"id": 17,
"type": "timeseries",
"title": "Job queue depth by state",
"description": "Unit: jobs. sum by (messenger_job_state) (messenger_job_queue_depth). Source: PostgreSQL attachment_jobs counted over partial indexes by relay every 5 s (not the broker queue): outbox — accepted, not yet published; published — in the broker or waiting for retry backoff; processing — leased by worker. Backlog, not processing latency.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 0, "y": 55},
"fieldConfig": {"defaults": {"unit": "short", "decimals": 0, "custom": {"stacking": {"mode": "normal"}, "fillOpacity": 30}}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "sum by (messenger_job_state) (messenger_job_queue_depth)",
"legendFormat": "{{messenger_job_state}}"
}
]
},
{
"id": 18,
"type": "timeseries",
"title": "Oldest unfinished job age",
"description": "Unit: seconds. max by (messaging_destination_name) (messenger_job_queue_oldest_age_seconds): age of the oldest queued or processing job (from its durable acceptance). Red line — threshold of MessengerQueueLagGrowing (60 s for 1 m).",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 8, "y": 55},
"fieldConfig": {"defaults": {"unit": "s", "min": 0, "custom": {"thresholdsStyle": {"mode": "line"}}, "thresholds": {"mode": "absolute", "steps": [{"color": "green", "value": null}, {"color": "red", "value": 60}]}}, "overrides": []},
"targets": [
{
"refId": "A",
"datasource": {"type": "prometheus", "uid": "metrics"},
"expr": "max by (messaging_destination_name) (messenger_job_queue_oldest_age_seconds)",
"legendFormat": "{{messaging_destination_name}}"
}
]
},
{
"id": 19,
"type": "timeseries",
"title": "Time to ready p50 / p95 / p99 (upload accepted → ready)",
"description": "Unit: seconds. histogram_quantile(q, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m]))). Recorded by worker when ready is committed; start — created_at of the job row written before 202. Includes broker wait, retries and backoff. Latency SLO: 95% of successful ready transitions within 30 s over 7 days; failed and unfinished jobs are excluded from this histogram.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 16, "y": 55},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m])))", "legendFormat": "p50"},
{"refId": "B", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m])))", "legendFormat": "p95"},
{"refId": "C", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m])))", "legendFormat": "p99"}
]
},
{
"id": 20,
"type": "timeseries",
"title": "DB pool: used / waiting / max by process",
"description": "Unit: connections and operations. db_client_connection_count{db_client_connection_state=\"used\"} — checked out of the SQLAlchemy pool; db_client_connection_pending_requests — operations waiting for a connection (counted in src/db.py); db_client_connection_max — DB_POOL_SIZE + DB_POOL_OVERFLOW. Summed per job (messenger-api replicas together).",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 0, "y": 63},
"fieldConfig": {"defaults": {"unit": "short", "decimals": 0}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (job) (db_client_connection_count{db_client_connection_state=\"used\"})", "legendFormat": "used {{job}}"},
{"refId": "B", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (job) (db_client_connection_pending_requests)", "legendFormat": "waiting {{job}}"},
{"refId": "C", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (job) (db_client_connection_max)", "legendFormat": "max {{job}}"}
]
},
{
"id": 21,
"type": "timeseries",
"title": "Worker saturation: busy / capacity",
"description": "Unit: tasks. messenger_worker_busy — tasks processing a delivery now; messenger_worker_capacity — WORKER_CONCURRENCY. busy = capacity for long with a growing queue — the worker is the bottleneck. Sampled at metric export (15 s), short bursts are not visible.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 8, "y": 63},
"fieldConfig": {"defaults": {"unit": "short", "decimals": 0, "min": 0}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum(messenger_worker_busy)", "legendFormat": "busy"},
{"refId": "B", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum(messenger_worker_capacity)", "legendFormat": "capacity"}
]
},
{
"id": 22,
"type": "timeseries",
"title": "Process CPU (cores) by service and instance",
"description": "Unit: CPU cores. sum by (job, instance) (rate(process_cpu_time_seconds_total[$__rate_interval])): user + system time of each process; worker includes its finished render subprocesses (os.times children).",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 16, "y": 63},
"fieldConfig": {"defaults": {"unit": "short", "min": 0}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (job, instance) (rate(process_cpu_time_seconds_total[$__rate_interval]))", "legendFormat": "{{job}} {{instance}}"}
]
},
{
"id": 23,
"type": "timeseries",
"title": "Process RSS by service and instance",
"description": "Unit: bytes. process_memory_usage_bytes: resident set of each application process (/proc/self/statm). Collector: otelcol_process_memory_rss (bytes, no unit suffix in 0.164).",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 0, "y": 71},
"fieldConfig": {"defaults": {"unit": "bytes", "min": 0}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "process_memory_usage_bytes", "legendFormat": "{{job}} {{instance}}"},
{"refId": "B", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "otelcol_process_memory_rss", "legendFormat": "otel-collector"}
]
},
{
"id": 24,
"type": "stat",
"title": "7-day SLO: API ≥ 99.5%, 95% of successful jobs ready within 30 s",
"description": "Unit: ratio. messenger:http_availability:ratio_7d = 1 − 5xx / all recorded API responses (health excluded; failures before API entry are not measured). messenger:attachment_ready_30s:ratio_7d = successful ready transitions within 30 s / all observed successful ready transitions; failed and unfinished jobs are excluded. This is a conditional latency SLI, not the success ratio of all accepted uploads. Recording rules: infra/otel/prometheus/rules.yml.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 8, "y": 71},
"fieldConfig": {"defaults": {"unit": "percentunit", "decimals": 2, "thresholds": {"mode": "absolute", "steps": [{"color": "red", "value": null}, {"color": "green", "value": 0.995}]}}, "overrides": [{"matcher": {"id": "byName", "options": "ready ≤ 30 s"}, "properties": [{"id": "thresholds", "value": {"mode": "absolute", "steps": [{"color": "red", "value": null}, {"color": "green", "value": 0.95}]}}]}]},
"options": {"reduceOptions": {"calcs": ["lastNotNull"]}, "colorMode": "background", "textMode": "value_and_name"},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "messenger:http_availability:ratio_7d", "legendFormat": "API availability"},
{"refId": "B", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "messenger:attachment_ready_30s:ratio_7d", "legendFormat": "ready ≤ 30 s"}
]
},
{
"id": 25,
"type": "timeseries",
"title": "Alerts: pending / firing",
"description": "Unit: alerts. sum by (alertname, alertstate) (ALERTS) — built-in series of Prometheus rule evaluation; absence means resolved. Runbooks: infra/otel/runbooks/.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 8, "x": 16, "y": 71},
"fieldConfig": {"defaults": {"unit": "short", "decimals": 0, "min": 0}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (alertname, alertstate) (ALERTS)", "legendFormat": "{{alertname}} {{alertstate}}"}
]
},
{
"id": 26,
"type": "timeseries",
"title": "Telemetry losses and export queue (Collector)",
"description": "Unit: items per second and items. Collector 0.164 exposes its counters without the _total suffix. rate of otelcol_exporter_send_failed_{spans,log_records} — dropped after retries (backend down), otelcol_exporter_enqueue_failed_* — dropped because the export queue (20000 items) is full (appears after the first such drop), otelcol_receiver_refused_* — refused by memory_limiter; otelcol_exporter_queue_size — items buffered now.",
"datasource": {"type": "prometheus", "uid": "metrics"},
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 79},
"fieldConfig": {"defaults": {"unit": "short", "min": 0}, "overrides": []},
"targets": [
{"refId": "A", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (exporter) (rate(otelcol_exporter_send_failed_spans[5m]) or rate(otelcol_exporter_send_failed_log_records[5m]))", "legendFormat": "send failed {{exporter}}"},
{"refId": "B", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (exporter) (rate(otelcol_exporter_enqueue_failed_spans[5m]) or rate(otelcol_exporter_enqueue_failed_log_records[5m]))", "legendFormat": "queue full {{exporter}}"},
{"refId": "C", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum(rate(otelcol_receiver_refused_spans[5m]) or rate(otelcol_receiver_refused_log_records[5m]) or rate(otelcol_receiver_refused_metric_points[5m]))", "legendFormat": "refused by receiver"},
{"refId": "D", "datasource": {"type": "prometheus", "uid": "metrics"}, "expr": "sum by (exporter) (otelcol_exporter_queue_size)", "legendFormat": "queue size {{exporter}}"}
]
}
]
}