Перенос решения ЛР 6 без изменений (src, migrations, student-tests, bench, infra, scripts, compose, Dockerfile, docs)

This commit is contained in:
Alexey Bodanyuk
2026-11-27 16:01:21 +03:00
parent 20afc2c790
commit 6435b6a1c5
111 changed files with 19604 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
-- Lab 6: trace context of a job and an index for the queue gauges.
--
-- jobs.traceparent / jobs.tracestate: W3C trace context of the request that created the job
-- (the upload, taken inside its HTTP server span). The relay publishes every outbox row of the
-- job (first attempt, retries, lease expiry, republish) as a PRODUCER span whose parent is this
-- context, and puts the producer's own context into the message (`traceparent` of
-- contracts/jobs.schema.json). One upload is therefore ONE trace: HTTP POST -> db enqueue ->
-- publish (relay) -> process (worker) -> S3/DB ... -> publish of the retry -> process ...
-- A job created by the operator CLI (jobctl replay/reprocess) has no context: NULL, and the relay
-- starts a new trace for it. The value is a 55-character technical id, never user data.
ALTER TABLE jobs
ADD COLUMN traceparent text COLLATE "C",
ADD COLUMN tracestate text COLLATE "C",
ADD CONSTRAINT jobs_traceparent CHECK (traceparent IS NULL OR traceparent ~ '^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$'),
ADD CONSTRAINT jobs_tracestate CHECK (tracestate IS NULL OR length(tracestate) <= 512);
-- Queue gauges of the relay (messenger.queue.depth / messenger.queue.oldest_age, every 5 s):
-- unfinished jobs by age. Partial index = only the few active rows, not the whole history.
CREATE INDEX jobs_active_age ON jobs (created_at) WHERE state IN ('queued', 'processing');