feat: secure telemetry ingestion and grafana data sources
This commit is contained in:
+91
-39
@@ -23,10 +23,18 @@ x-s3-env: &s3-env
|
||||
S3_REGION: us-east-1
|
||||
|
||||
x-otel-env: &otel-env
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
||||
|
||||
x-telemetry-proxy: &telemetry-proxy
|
||||
<<: *lockdown
|
||||
image: haproxy:3.0.6-alpine
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: "0.15", memory: 64M}
|
||||
|
||||
services:
|
||||
bootstrap:
|
||||
build:
|
||||
@@ -277,99 +285,142 @@ services:
|
||||
limits: {cpus: "0.25", memory: 96M}
|
||||
|
||||
otel-collector:
|
||||
<<: *lockdown
|
||||
image: otel/opentelemetry-collector-contrib:0.115.1@sha256:d2da12c4336a79758826700be9e21ecf4a9f7d945b7f8a58ba55ee3fa45427c8
|
||||
command: ["--config=/etc/otelcol/collector.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otelcol/collector.yaml:ro
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: otel-collector}}
|
||||
networks: [default, telemetry]
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 256M }
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.5", memory: 256M}
|
||||
|
||||
collector-scrape:
|
||||
<<: *telemetry-proxy
|
||||
user: "10001:10001"
|
||||
network_mode: service:otel-collector
|
||||
environment: {READ_PORT: "8888", INGEST_PORT: "8888", MODE: scrape}
|
||||
volumes:
|
||||
- ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: otel-collector}}
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.1.0@sha256:6559acbd5d770b15bb3c954629ce190ac3cbbdb2b7f1c30f0385c4e05104e218
|
||||
<<: *lockdown
|
||||
image: prom/prometheus:v3.1.0
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
- --storage.tsdb.retention.size=1GB
|
||||
- --web.enable-otlp-receiver
|
||||
- --web.listen-address=127.0.0.1:9090
|
||||
volumes:
|
||||
- ./infra/prometheus:/etc/prometheus:ro
|
||||
- prometheusdata:/prometheus
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: prometheus}}
|
||||
networks: [telemetry]
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 512M }
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:9090/-/ready"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.5", memory: 512M}
|
||||
|
||||
prometheus-tls:
|
||||
<<: *telemetry-proxy
|
||||
user: "65534:65534"
|
||||
network_mode: service:prometheus
|
||||
environment: {READ_PORT: "9090", INGEST_PORT: "9090", MODE: backend}
|
||||
volumes:
|
||||
- ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: prometheus}}
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.3.2@sha256:8af2de1abbdd7aa92b27c9bcc96f0f4140c9096b507c77921ffddf1c6ad6c48f
|
||||
<<: *lockdown
|
||||
image: grafana/loki:3.3.2
|
||||
command: ["-config.file=/etc/loki/loki.yaml"]
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- lokidata:/loki
|
||||
networks: [telemetry]
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 512M }
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.5", memory: 512M}
|
||||
|
||||
loki-tls:
|
||||
<<: *telemetry-proxy
|
||||
user: "10001:10001"
|
||||
network_mode: service:loki
|
||||
environment: {READ_PORT: "3100", INGEST_PORT: "3100", MODE: backend}
|
||||
volumes:
|
||||
- ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: loki}}
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.6.1@sha256:ef4384fce6e8ad22b95b243d8fc165628cda655376fd50e7850536ad89d71d50
|
||||
<<: *lockdown
|
||||
image: grafana/tempo:2.6.1
|
||||
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempodata:/var/tempo
|
||||
networks: [telemetry]
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 512M }
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.5", memory: 512M}
|
||||
|
||||
tempo-tls:
|
||||
<<: *telemetry-proxy
|
||||
user: "10001:10001"
|
||||
network_mode: service:tempo
|
||||
environment: {READ_PORT: "3200", INGEST_PORT: "4318", MODE: backend}
|
||||
volumes:
|
||||
- ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: tempo}}
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
|
||||
grafana:
|
||||
<<: *lockdown
|
||||
image: grafana/grafana:11.4.0@sha256:d8ea37798ccc41061a62ab080f2676dda6bf7815558499f901bdb0f533a456fb
|
||||
entrypoint: ["sh", "/work/grafana.sh"]
|
||||
ports:
|
||||
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000"
|
||||
environment:
|
||||
GF_SERVER_PROTOCOL: https
|
||||
GF_SERVER_CERT_FILE: /run/tls/grafana.crt
|
||||
GF_SERVER_CERT_KEY: /run/tls/grafana.key
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/admin_password
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "true"
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
|
||||
GF_USERS_VIEWERS_CAN_EDIT: "true"
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/tls/admin_password
|
||||
GF_SECURITY_COOKIE_SECURE: "true"
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "false"
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
||||
GF_NEWS_NEWS_FEED_ENABLED: "false"
|
||||
volumes:
|
||||
- ./infra/grafana/start.sh:/work/grafana.sh:ro
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafanadata:/var/lib/grafana
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: grafana } }
|
||||
networks: [default, telemetry]
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: grafana}}
|
||||
networks: [telemetry, admin]
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
prometheus-tls: {condition: service_started}
|
||||
loki-tls: {condition: service_started}
|
||||
tempo-tls: {condition: service_started}
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 256M }
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/api/health"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
depends_on:
|
||||
bootstrap:
|
||||
condition: service_completed_successfully
|
||||
prometheus:
|
||||
condition: service_healthy
|
||||
loki:
|
||||
condition: service_started
|
||||
tempo:
|
||||
condition: service_started
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.5", memory: 256M}
|
||||
|
||||
checks:
|
||||
<<: *lockdown
|
||||
@@ -400,3 +451,4 @@ volumes:
|
||||
networks:
|
||||
telemetry:
|
||||
internal: true
|
||||
admin:
|
||||
|
||||
+19
-1
@@ -104,13 +104,14 @@ def main():
|
||||
return
|
||||
os.umask(0o077)
|
||||
names = ("operator", "postgres", "migrate", "s3", "s3-init", "rabbitmq", "lb", "openbao",
|
||||
"grafana", "checks", *ROLES)
|
||||
"otel-collector", "prometheus", "loki", "tempo", "grafana", "checks", *ROLES)
|
||||
directories = {name: ROOT / name for name in names}
|
||||
for directory in directories.values():
|
||||
directory.mkdir(exist_ok=True)
|
||||
operator = directories["operator"]
|
||||
server_ca = ca(operator, "lab7-servers")
|
||||
client_ca = ca(operator, "lab7-clients")
|
||||
telemetry_ca = ca(operator, "lab7-telemetry-clients")
|
||||
for directory in directories.values():
|
||||
copy_ca(directory, server_ca)
|
||||
|
||||
@@ -141,6 +142,18 @@ def main():
|
||||
s3_crt.rename(s3 / "public.crt")
|
||||
leaf(directories["rabbitmq"], "rabbitmq", server_ca)
|
||||
leaf(directories["openbao"], "openbao", server_ca, extra_san=",DNS:localhost,IP:127.0.0.1")
|
||||
leaf(directories["otel-collector"], "otel-collector", server_ca)
|
||||
leaf(directories["grafana"], "grafana", server_ca, extra_san=",DNS:localhost,IP:127.0.0.1")
|
||||
for name in ("prometheus", "loki", "tempo", "otel-collector"):
|
||||
directory = directories[name]
|
||||
server = (directory / f"{name}.key", directory / f"{name}.crt")
|
||||
if name != "otel-collector":
|
||||
server = leaf(directory, name, server_ca)
|
||||
bundle(directory, "https.pem", server)
|
||||
shutil.copyfile(telemetry_ca[1], directory / "telemetry-clients.crt")
|
||||
leaf(directories["otel-collector"], "collector.lab7.internal", telemetry_ca, "client")
|
||||
leaf(directories["grafana"], "grafana.lab7.internal", telemetry_ca, "client")
|
||||
leaf(directories["prometheus"], "scraper.lab7.internal", telemetry_ca, "client")
|
||||
passwords = {role: secrets.token_hex(24) for role in (*ROLES, "migrate", "operator")}
|
||||
for role, password in passwords.items():
|
||||
write(directories["postgres"] / f"{role}_password", password)
|
||||
@@ -154,6 +167,8 @@ def main():
|
||||
relay_password, worker_password = secrets.token_hex(24), secrets.token_hex(24)
|
||||
write(directories["rabbitmq"] / "definitions.json",
|
||||
json.dumps(broker_definitions(relay_password, worker_password)))
|
||||
ingest_token = secrets.token_hex(32)
|
||||
write(directories["otel-collector"] / "ingest_token", ingest_token)
|
||||
configuration = {}
|
||||
for role, limit in ROLES.items():
|
||||
_, cert = leaf(directories[role], f"{role}.bao.lab7.internal", client_ca, "client")
|
||||
@@ -165,10 +180,13 @@ def main():
|
||||
if role in ("relay", "worker"):
|
||||
password = relay_password if role == "relay" else worker_password
|
||||
values["BROKER_URL"] = f"amqps://{role}:{password}@rabbitmq:5671/%2Fmessenger"
|
||||
if role != "reconciler":
|
||||
values["OTEL_EXPORTER_OTLP_HEADERS"] = f"authorization=Bearer%20{ingest_token}"
|
||||
configuration[role] = {"certificate": cert.read_text(), "values": values}
|
||||
write(operator / "roles.json", json.dumps(configuration))
|
||||
shutil.copyfile(api / "api.crt", checks / "api.crt")
|
||||
owners = {"postgres": 70, "rabbitmq": 100, "openbao": 100, "grafana": 472,
|
||||
"otel-collector": 10001, "prometheus": 65534, "loki": 10001, "tempo": 10001,
|
||||
"lb": 1000, "migrate": 1000, **dict.fromkeys(ROLES, 1000)}
|
||||
for name, uid in owners.items():
|
||||
own(directories[name], uid)
|
||||
|
||||
@@ -5,9 +5,15 @@ datasources:
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
url: https://prometheus:9443
|
||||
isDefault: true
|
||||
secureJsonData: &client
|
||||
tlsCACert: $GRAFANA_TLS_CA
|
||||
tlsClientCert: $GRAFANA_CLIENT_CERT
|
||||
tlsClientKey: $GRAFANA_CLIENT_KEY
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
httpMethod: POST
|
||||
exemplarTraceIdDestinations:
|
||||
- name: trace_id
|
||||
@@ -16,8 +22,11 @@ datasources:
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
url: https://loki:9443
|
||||
secureJsonData: *client
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
derivedFields:
|
||||
- name: trace_id
|
||||
matcherType: label
|
||||
@@ -28,8 +37,11 @@ datasources:
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
url: https://tempo:9443
|
||||
secureJsonData: *client
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
spanStartTimeShift: -5m
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
export GRAFANA_TLS_CA="$(cat /run/tls/ca.crt)"
|
||||
export GRAFANA_CLIENT_CERT="$(cat /run/tls/grafana.lab7.internal.crt)"
|
||||
export GRAFANA_CLIENT_KEY="$(cat /run/tls/grafana.lab7.internal.key)"
|
||||
exec /run.sh
|
||||
@@ -0,0 +1,29 @@
|
||||
global
|
||||
log stdout format raw local0 notice
|
||||
ssl-default-bind-options ssl-min-ver TLSv1.2
|
||||
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 2s
|
||||
timeout client 15s
|
||||
timeout server 15s
|
||||
timeout http-request 5s
|
||||
|
||||
frontend tls
|
||||
bind :9443 ssl crt /run/tls/https.pem ca-file /run/tls/telemetry-clients.crt verify required
|
||||
acl collector ssl_c_s_dn(CN) -m str collector.lab7.internal
|
||||
acl grafana ssl_c_s_dn(CN) -m str grafana.lab7.internal
|
||||
acl scraper ssl_c_s_dn(CN) -m str scraper.lab7.internal
|
||||
acl scrape_mode env(MODE) -m str scrape
|
||||
acl metrics_path path -i /metrics
|
||||
acl ingest_path path -i /api/v1/otlp/v1/metrics /otlp/v1/logs /v1/traces
|
||||
acl query_post path -i /api/v1/query /api/v1/query_range /api/v1/series /loki/api/v1/query /loki/api/v1/query_range /loki/api/v1/series
|
||||
http-request deny unless scrape_mode scraper METH_GET metrics_path or !scrape_mode collector METH_POST ingest_path or !scrape_mode grafana METH_GET !ingest_path or !scrape_mode grafana METH_POST query_post
|
||||
use_backend ingest if collector
|
||||
default_backend read
|
||||
|
||||
backend read
|
||||
server local "127.0.0.1:${READ_PORT}"
|
||||
|
||||
backend ingest
|
||||
server local "127.0.0.1:${INGEST_PORT}"
|
||||
@@ -1,7 +1,8 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_address: 0.0.0.0
|
||||
http_listen_address: 127.0.0.1
|
||||
grpc_listen_address: 127.0.0.1
|
||||
http_listen_port: 3100
|
||||
grpc_listen_port: 9096
|
||||
log_level: warn
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extensions:
|
||||
health_check:
|
||||
endpoint: 0.0.0.0:13133
|
||||
bearertokenauth:
|
||||
filename: /run/tls/ingest_token
|
||||
|
||||
receivers:
|
||||
otlp:
|
||||
@@ -8,6 +8,12 @@ receivers:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
max_request_body_size: 4194304
|
||||
auth:
|
||||
authenticator: bearertokenauth
|
||||
tls:
|
||||
cert_file: /run/tls/otel-collector.crt
|
||||
key_file: /run/tls/otel-collector.key
|
||||
min_version: "1.2"
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
@@ -21,7 +27,12 @@ processors:
|
||||
|
||||
exporters:
|
||||
otlphttp/prometheus:
|
||||
endpoint: http://prometheus:9090/api/v1/otlp
|
||||
endpoint: https://prometheus:9443/api/v1/otlp
|
||||
tls: &backend-tls
|
||||
ca_file: /run/tls/ca.crt
|
||||
cert_file: /run/tls/collector.lab7.internal.crt
|
||||
key_file: /run/tls/collector.lab7.internal.key
|
||||
min_version: "1.2"
|
||||
timeout: 5s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
@@ -33,7 +44,8 @@ exporters:
|
||||
max_interval: 10s
|
||||
max_elapsed_time: 60s
|
||||
otlphttp/loki:
|
||||
endpoint: http://loki:3100/otlp
|
||||
endpoint: https://loki:9443/otlp
|
||||
tls: *backend-tls
|
||||
timeout: 5s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
@@ -45,7 +57,8 @@ exporters:
|
||||
max_interval: 10s
|
||||
max_elapsed_time: 60s
|
||||
otlphttp/tempo:
|
||||
endpoint: http://tempo:4318
|
||||
endpoint: https://tempo:9443
|
||||
tls: *backend-tls
|
||||
timeout: 5s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
@@ -58,7 +71,7 @@ exporters:
|
||||
max_elapsed_time: 60s
|
||||
|
||||
service:
|
||||
extensions: [health_check]
|
||||
extensions: [bearertokenauth]
|
||||
telemetry:
|
||||
logs:
|
||||
level: warn
|
||||
@@ -68,7 +81,7 @@ service:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 0.0.0.0
|
||||
host: 127.0.0.1
|
||||
port: 8888
|
||||
pipelines:
|
||||
metrics:
|
||||
|
||||
@@ -16,8 +16,13 @@ rule_files:
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/tls/ca.crt
|
||||
cert_file: /run/tls/scraper.lab7.internal.crt
|
||||
key_file: /run/tls/scraper.lab7.internal.key
|
||||
static_configs:
|
||||
- targets: ["otel-collector:8888"]
|
||||
- targets: ["otel-collector:9443"]
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
- targets: ["localhost:9090"]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
stream_over_http_enabled: true
|
||||
|
||||
server:
|
||||
http_listen_address: 0.0.0.0
|
||||
http_listen_address: 127.0.0.1
|
||||
grpc_listen_address: 127.0.0.1
|
||||
http_listen_port: 3200
|
||||
log_level: warn
|
||||
|
||||
@@ -10,7 +11,7 @@ distributor:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
endpoint: 127.0.0.1:4318
|
||||
|
||||
ingester:
|
||||
max_block_duration: 5m
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
"""Send a synthetic HTTPS upload and check its signals through authenticated Grafana."""
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from urllib.error import HTTPError
|
||||
from urllib.parse import urlencode, urlsplit
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--base-url", default="https://localhost:8443")
|
||||
parser.add_argument("--grafana-url", default="https://localhost:3000")
|
||||
parser.add_argument("--ca-file", default=str(ROOT / "secrets/ca.crt"))
|
||||
args = parser.parse_args()
|
||||
grafana = args.grafana_url.rstrip("/")
|
||||
origin = urlsplit(grafana)
|
||||
if origin.scheme != "https" or origin.hostname not in ("localhost", "127.0.0.1") or origin.path:
|
||||
parser.error("--grafana-url must be a local HTTPS origin")
|
||||
ssl_context = ssl.create_default_context(cafile=args.ca_file)
|
||||
password = subprocess.run(
|
||||
["docker", "compose", "exec", "-T", "grafana", "cat", "/run/tls/admin_password"],
|
||||
cwd=ROOT, capture_output=True, check=True,
|
||||
).stdout.strip()
|
||||
header = "Basic " + base64.b64encode(b"admin:" + password).decode()
|
||||
|
||||
def call(path, authenticated=True):
|
||||
req = Request(grafana + "/api/datasources/proxy/uid/" + path,
|
||||
headers={"Authorization": header} if authenticated else {})
|
||||
try:
|
||||
with urlopen(req, context=ssl_context, timeout=7) as response:
|
||||
return response.status, json.load(response)
|
||||
except HTTPError as error:
|
||||
return error.code, {}
|
||||
|
||||
assert call("prometheus/api/v1/query?query=up", authenticated=False)[0] == 401
|
||||
|
||||
client = Client(args.base_url, args.ca_file)
|
||||
owner = client.user("telemetry")
|
||||
chat = client.call("POST", "/api/v1/chats", 201, actor=owner, body={
|
||||
"title": "Telemetry check", "member_ids": [owner["id"]],
|
||||
}, schema="Chat")["json"]
|
||||
trace_id = uuid.uuid4().hex
|
||||
result = client.call("POST", f"/api/v1/chats/{chat['id']}/attachments?filename=sample.png",
|
||||
202, actor=owner, raw=(ROOT / "tests/fixtures/sample.png").read_bytes(),
|
||||
headers={"Content-Type": "image/png",
|
||||
"traceparent": f"00-{trace_id}-{uuid.uuid4().hex[:16]}-01"},
|
||||
schema="Attachment")
|
||||
client.wait_ready(owner, result["json"])
|
||||
log_query = urlencode({"query": '{service_name=~"messenger-.+"} | trace_id="' + trace_id + '"',
|
||||
"limit": 50, "since": "10m"})
|
||||
metric_query = urlencode({"query": 'http_server_requests_total or up{job="otel-collector"}'})
|
||||
required = {"messenger-api", "messenger-relay", "messenger-worker"}
|
||||
deadline = time.monotonic() + 60
|
||||
while time.monotonic() < deadline:
|
||||
_, trace = call("tempo/api/traces/" + trace_id)
|
||||
services = {
|
||||
attribute["value"]["stringValue"]
|
||||
for batch in trace.get("batches", [])
|
||||
for attribute in batch.get("resource", {}).get("attributes", [])
|
||||
if attribute["key"] == "service.name"
|
||||
}
|
||||
_, logs = call("loki/loki/api/v1/query_range?" + log_query)
|
||||
log_services = {
|
||||
stream["stream"].get("service_name") for stream in logs.get("data", {}).get("result", [])
|
||||
}
|
||||
_, metrics = call("prometheus/api/v1/query?" + metric_query)
|
||||
series = metrics.get("data", {}).get("result", [])
|
||||
api_metrics = any(row["metric"].get("__name__") == "http_server_requests_total" for row in series)
|
||||
scraped = any(row["metric"].get("job") == "otel-collector" and row["value"][1] == "1" for row in series)
|
||||
if required <= services and {"messenger-api", "messenger-worker"} <= log_services and api_metrics and scraped:
|
||||
print("PASS: authenticated Grafana queries returned API metrics, Collector scrape, "
|
||||
"API/relay/worker spans and API/worker logs for one upload")
|
||||
return
|
||||
time.sleep(2)
|
||||
raise SystemExit("Telemetry incomplete: "
|
||||
f"trace services={sorted(services)}, logs={sorted(log_services)}, "
|
||||
f"API metrics={api_metrics}, Collector scrape={scraped}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+3
-2
@@ -3,11 +3,12 @@ import { readFileSync, writeFileSync } from 'fs';
|
||||
import { Agent, request } from 'https';
|
||||
|
||||
const keys = {
|
||||
api: ['DATABASE_URL', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY'],
|
||||
api: ['DATABASE_URL', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY', 'OTEL_EXPORTER_OTLP_HEADERS'],
|
||||
worker: [
|
||||
'DATABASE_URL', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY', 'BROKER_URL',
|
||||
'OTEL_EXPORTER_OTLP_HEADERS',
|
||||
],
|
||||
relay: ['DATABASE_URL', 'BROKER_URL'],
|
||||
relay: ['DATABASE_URL', 'BROKER_URL', 'OTEL_EXPORTER_OTLP_HEADERS'],
|
||||
reconciler: ['DATABASE_URL', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY'],
|
||||
} as const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user