feat: propagate trace context through outbox and add pipeline saturation metrics

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 19:54:37 +03:00
co-authored by Claude Opus 5.5
parent ff0073e8e3
commit 72cfa9aaf6
64 changed files with 4699 additions and 552 deletions
+10 -4
View File
@@ -18,7 +18,7 @@ from src.infra.s3 import (
StoredObjectInfo,
StoredObjectPage,
)
from src.schemas.dataclasses import RenderedVariantsDTO
from src.schemas.dataclasses import JobPublicationDTO, RenderedVariantsDTO
from .database import FakeDatabase
@@ -207,16 +207,22 @@ class FakeJobPublisher:
self.unconfirmed: set[UUID] = set()
self.ready = 0
self.published: list[UUID] = []
# элементы публикаций с контекстом и номером попытки (design change
# job-trace-propagation, решение 3)
self.items: list[JobPublicationDTO] = []
async def publish_many(
self,
items: Sequence[tuple[UUID, bytes]],
items: Sequence[JobPublicationDTO],
) -> set[UUID]:
self._db.record("publisher.publish_many")
confirmed = {
job_id for job_id, _ in items if job_id not in self.unconfirmed
item.job_id
for item in items
if item.job_id not in self.unconfirmed
}
self.published.extend(job_id for job_id, _ in items)
self.published.extend(item.job_id for item in items)
self.items.extend(items)
return confirmed
async def ready_messages(self) -> int:
+35
View File
@@ -666,6 +666,8 @@ class FakeAttachmentJobRepository(
attempt=job.attempt,
created_at=job.created_at,
updated_at=job.updated_at,
traceparent=job.traceparent,
tracestate=job.tracestate,
)
return job
@@ -700,6 +702,39 @@ class FakeAttachmentJobRepository(
)
return sum(min(len(group), limit) for group in groups)
async def queue_snapshot(
self,
*,
now: datetime,
) -> dataclasses.QueueSnapshotDTO:
unfinished = [
job
for job in self._db.jobs.values()
if job.state
in {AttachmentJobState.QUEUED, AttachmentJobState.PROCESSING}
]
outbox = [
job
for job in unfinished
if job.state == AttachmentJobState.QUEUED
and job.published_at is None
]
return dataclasses.QueueSnapshotDTO(
taken_at=now,
scheduled=sum(1 for job in outbox if _due_at(job) > now),
outbox=sum(1 for job in outbox if _due_at(job) <= now),
published=len(self._published()),
processing=sum(
1
for job in unfinished
if job.state == AttachmentJobState.PROCESSING
),
oldest_created_at=min(
(job.created_at for job in unfinished),
default=None,
),
)
async def get_attachment_job(
self,
*,