feat: put telemetry backends, LB metrics and Grafana behind mTLS gateways
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,7 @@ Prometheus, квантили из buckets против журнала. Резу
|
||||
import contextlib
|
||||
import json
|
||||
import math
|
||||
import ssl
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
@@ -32,16 +33,43 @@ import urllib.request
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Any
|
||||
|
||||
PROMETHEUS = "http://prometheus:9090"
|
||||
LOKI = "http://loki:3100"
|
||||
TEMPO = "http://tempo:3200"
|
||||
COLLECTOR = "http://otel-collector:8888"
|
||||
# С change telemetry-backends-tls (design, решение 11) хранилища — за
|
||||
# TLS-шлюзами: запросы — https с клиентским leaf grafana-client (права
|
||||
# шлюзов — только чтение), метрики Collector — prometheus-client; сервер — по
|
||||
# CA прогона и имени. Файлы — /pki в контейнере (только CA и две пары, на
|
||||
# чтение). Готовность — пути, которые шлюзы разрешают этим identity:
|
||||
# /-/ready и /ready закрыты шлюзами (служебные пути)
|
||||
PROMETHEUS = "https://prometheus:9090"
|
||||
LOKI = "https://loki:3100"
|
||||
TEMPO = "https://tempo:3200"
|
||||
COLLECTOR = "https://otel-collector:8888"
|
||||
PKI = "/pki"
|
||||
READY = (
|
||||
f"{PROMETHEUS}/-/ready",
|
||||
f"{LOKI}/ready",
|
||||
f"{TEMPO}/ready",
|
||||
f"{PROMETHEUS}/api/v1/query?query=1",
|
||||
f"{LOKI}/loki/api/v1/labels",
|
||||
f"{TEMPO}/api/echo",
|
||||
f"{COLLECTOR}/metrics",
|
||||
)
|
||||
CONTEXTS: dict[str, ssl.SSLContext] = {}
|
||||
|
||||
|
||||
def tls_context(url: str) -> ssl.SSLContext:
|
||||
"""Контекст mTLS по адресу: метрики Collector — prometheus-client,
|
||||
хранилища — grafana-client; проверка сервера по CA прогона всегда."""
|
||||
identity = (
|
||||
"prometheus-client" if url.startswith(COLLECTOR) else "grafana-client"
|
||||
)
|
||||
if identity not in CONTEXTS:
|
||||
context = ssl.create_default_context(cafile=f"{PKI}/ca.crt")
|
||||
context.minimum_version = ssl.TLSVersion.TLSv1_3
|
||||
context.load_cert_chain(
|
||||
f"{PKI}/{identity}.crt",
|
||||
f"{PKI}/{identity}.key",
|
||||
)
|
||||
CONTEXTS[identity] = context
|
||||
return CONTEXTS[identity]
|
||||
|
||||
|
||||
THREADS = 8
|
||||
# переходы журнал → трасса: потоков на класс (классы идут параллельно)
|
||||
LINK_THREADS = 2
|
||||
@@ -212,7 +240,11 @@ def fetch(url: str) -> bytes:
|
||||
try:
|
||||
with (
|
||||
gate,
|
||||
urllib.request.urlopen(url, timeout=TIMEOUT_S) as response,
|
||||
urllib.request.urlopen(
|
||||
url,
|
||||
timeout=TIMEOUT_S,
|
||||
context=tls_context(url),
|
||||
) as response,
|
||||
):
|
||||
return response.read()
|
||||
except urllib.error.HTTPError as exc:
|
||||
@@ -249,7 +281,11 @@ def wait_ready(timeout: float) -> int:
|
||||
left = []
|
||||
for url in pending:
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=3) as response:
|
||||
with urllib.request.urlopen(
|
||||
url,
|
||||
timeout=3,
|
||||
context=tls_context(url),
|
||||
) as response:
|
||||
response.read()
|
||||
if response.status != 200:
|
||||
left.append(url)
|
||||
|
||||
Reference in New Issue
Block a user