feat: telemetry cost profile with head sampling, coarse buckets and balanced tail sampling

- [telemetry] trace_sample_ratio (ParentBased(TraceIdRatioBased), 1 keeps
  ParentBased(ALWAYS_ON)) and metric_buckets (default|coarse with SLO bounds),
  export interval <= 30 s; otel.sdk.span.started, span.live dropped; startup
  records name ratio, buckets and interval
- bench: telemetry services on mtusi-bench, TELEMETRY=on switch for uploads
  and queue, make bench_telemetry[_quick] with off/full/full-aa/head/tail/
  metrics/balanced, rare events, lookup from Tempo/Loki/Prometheus, cost
  sampler, verdicts H1-H8 and B1-B5; collector layers and lean Prometheus in
  bench/otel with preflight checks
- REPORT: telemetry cost hypotheses and criteria before the label

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:17:25 +03:00
co-authored by Claude Opus 5.5
parent 37f86801d6
commit 509afca89e
43 changed files with 5784 additions and 159 deletions
+31 -4
View File
@@ -1,5 +1,6 @@
"""Файлы классов профиля очереди (design change `track1-queue-overload`,
решение 5): `s`, `m`, `lj`, `lp`, детерминированно от зерна.
решение 5): `s`, `m`, `lj`, `lp`, детерминированно от зерна; класс `bad` —
профиль цены телеметрии (design change `track1-telemetry-cost`, решение 8).
Только в контейнере `mtusi-bench-images` на образе стенда: Pillow образа и та же
его версия, что у процесса обработки; `src` не импортируется. На stdout — JSON с
@@ -15,7 +16,7 @@ import random
import sys
from pathlib import Path
from PIL import Image, ImageChops
from PIL import Image, ImageChops, UnidentifiedImageError
from uploads import png_noise
MAX_BYTES = 10_485_760
@@ -29,6 +30,8 @@ FINE_DIVISOR = 6
TILE = 512
AMPLITUDE = 24
POSTERIZE_MASK = 0xF0
# точность в SOF, которую Pillow не декодирует
PRECISION_12 = 12
def noise_l(width: int, height: int, seed: int) -> Image.Image:
@@ -125,11 +128,36 @@ def build_m(seed: int) -> bytes:
return png_noise(NOISE_HEIGHT, seed + NOISE_HEIGHT)
def build_bad(seed: int) -> bytes:
"""Класс `bad` профиля цены телеметрии (design change
`track1-telemetry-cost`, решение 8): байты `s` с 12 битами точности в
SOF — структура верна (202), Pillow не декодирует (`failed`,
`invalid_image`), как `images.jpeg_precision_12()` тестов."""
data = bytearray(build_s(seed))
sof = data.index(b"\xff\xc0")
data[sof + 4] = PRECISION_12
return bytes(data)
def image_size(data: bytes) -> tuple[int, int]:
"""Ширина и высота: Pillow, а у `bad`, который Pillow не открывает, —
поля SOF (высота и ширина после точности)."""
try:
with Image.open(io.BytesIO(data)) as image:
return image.size
except UnidentifiedImageError:
sof = data.index(b"\xff\xc0")
height = int.from_bytes(data[sof + 5 : sof + 7], "big")
width = int.from_bytes(data[sof + 7 : sof + 9], "big")
return width, height
BUILDERS = {
"s": (build_s, "s.jpg", "image/jpeg"),
"m": (build_m, "m.png", "image/png"),
"lj": (build_lj, "lj.jpg", "image/jpeg"),
"lp": (build_lp, "lp.png", "image/png"),
"bad": (build_bad, "bad.jpg", "image/jpeg"),
}
@@ -139,8 +167,7 @@ def main() -> int:
code = 0
for name, (build, filename, media) in BUILDERS.items():
data = build(seed)
with Image.open(io.BytesIO(data)) as image:
width, height = image.size
width, height = image_size(data)
(directory / filename).write_bytes(data)
report[name] = {
"file": filename,