Перенести реализацию мессенджера из ЛР 6

Файлы скопированы без изменений из solution/BPI2301-Vozzhin
репозитория mtusi2026lab6. Доработки ЛР 7 идут отдельными коммитами.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-12-03 19:48:41 +05:00
co-authored by Claude Opus 5.5
parent 20afc2c790
commit 31d441184b
92 changed files with 6153 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
from __future__ import annotations
import os
from dataclasses import dataclass
def _positive_int(name: str, default: str) -> int:
try:
value = int(os.getenv(name, default))
except ValueError as exc:
raise RuntimeError(f'{name} должен быть целым числом') from exc
if value <= 0:
raise RuntimeError(f'{name} должен быть больше нуля')
return value
@dataclass(frozen=True, slots=True)
class ObservabilitySettings:
enabled: bool
endpoint: str
service_name: str
service_version: str
environment: str
export_timeout_seconds: int
span_queue_size: int
log_queue_size: int
metric_export_interval_ms: int
def load_observability_settings(default_service_name: str) -> ObservabilitySettings:
disabled = os.getenv('OTEL_SDK_DISABLED', 'false').strip().lower()
if disabled not in {'true', 'false'}:
raise RuntimeError('OTEL_SDK_DISABLED должен быть true или false')
endpoint = os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://otel-collector:4318')
return ObservabilitySettings(
enabled=disabled != 'true',
endpoint=endpoint.rstrip('/'),
service_name=os.getenv('OTEL_SERVICE_NAME', default_service_name),
service_version=os.getenv('OTEL_SERVICE_VERSION', '1.6.0'),
environment=os.getenv('OTEL_DEPLOYMENT_ENVIRONMENT', 'lab'),
export_timeout_seconds=_positive_int('OTEL_EXPORTER_OTLP_TIMEOUT', '2'),
span_queue_size=_positive_int('OTEL_BSP_MAX_QUEUE_SIZE', '2048'),
log_queue_size=_positive_int('OTEL_BLRP_MAX_QUEUE_SIZE', '2048'),
metric_export_interval_ms=_positive_int('OTEL_METRIC_EXPORT_INTERVAL', '5000'),
)