feat: add image traffic and broker observability
This commit is contained in:
@@ -32,4 +32,5 @@ OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=lab
|
|||||||
# Local observability demo load (enabled with --profile demo)
|
# Local observability demo load (enabled with --profile demo)
|
||||||
MOCK_RATE=2
|
MOCK_RATE=2
|
||||||
MOCK_WORKERS=2
|
MOCK_WORKERS=2
|
||||||
|
SEND_IMAGES=false
|
||||||
VICTORIAMETRICS_PORT=8428
|
VICTORIAMETRICS_PORT=8428
|
||||||
|
|||||||
+13
-1
@@ -188,6 +188,16 @@ services:
|
|||||||
cpus: 0.5
|
cpus: 0.5
|
||||||
mem_limit: 256m
|
mem_limit: 256m
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
redis-exporter:
|
||||||
|
image: oliver006/redis_exporter:v1.67.0
|
||||||
|
command: ['/bin/sh', '-ec', 'exec redis_exporter --redis.addr=redis://broker:6379 --redis.password="$$(awk '$$1=="requirepass" {print $$2}' /run/secrets/broker_config)"']
|
||||||
|
secrets: [broker_config]
|
||||||
|
ports: ['127.0.0.1:9121:9121']
|
||||||
|
depends_on:
|
||||||
|
broker: {condition: service_started}
|
||||||
|
cpus: 0.25
|
||||||
|
mem_limit: 128m
|
||||||
|
restart: unless-stopped
|
||||||
victoriametrics:
|
victoriametrics:
|
||||||
image: victoriametrics/victoria-metrics:v1.120.0
|
image: victoriametrics/victoria-metrics:v1.120.0
|
||||||
command: [-promscrape.config=/etc/victoria-metrics/promscrape.yaml, -retentionPeriod=24h, -storageDataPath=/victoria-metrics-data]
|
command: [-promscrape.config=/etc/victoria-metrics/promscrape.yaml, -retentionPeriod=24h, -storageDataPath=/victoria-metrics-data]
|
||||||
@@ -203,7 +213,9 @@ services:
|
|||||||
MOCK_BASE_URL: http://lb:8080
|
MOCK_BASE_URL: http://lb:8080
|
||||||
MOCK_RATE: ${MOCK_RATE:-2}
|
MOCK_RATE: ${MOCK_RATE:-2}
|
||||||
MOCK_WORKERS: ${MOCK_WORKERS:-2}
|
MOCK_WORKERS: ${MOCK_WORKERS:-2}
|
||||||
volumes: ['./mock-load/mock_load.py:/opt/mock/mock_load.py:ro']
|
SEND_IMAGES: ${SEND_IMAGES:-false}
|
||||||
|
MOCK_IMAGE_PATH: /opt/mock/sample.png
|
||||||
|
volumes: ['./mock-load/mock_load.py:/opt/mock/mock_load.py:ro', './tests/fixtures/sample.png:/opt/mock/sample.png:ro']
|
||||||
profiles: [demo]
|
profiles: [demo]
|
||||||
depends_on:
|
depends_on:
|
||||||
lb: {condition: service_healthy}
|
lb: {condition: service_healthy}
|
||||||
|
|||||||
@@ -685,6 +685,141 @@
|
|||||||
},
|
},
|
||||||
"overrides": []
|
"overrides": []
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 25,
|
||||||
|
"title": "Broker up",
|
||||||
|
"type": "timeseries",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "victoriametrics"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 48,
|
||||||
|
"w": 12,
|
||||||
|
"h": 8
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"refId": "A",
|
||||||
|
"expr": "redis_up"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "none"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 26,
|
||||||
|
"title": "Broker stream length",
|
||||||
|
"type": "timeseries",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "victoriametrics"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"x": 12,
|
||||||
|
"y": 48,
|
||||||
|
"w": 12,
|
||||||
|
"h": 8
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"refId": "A",
|
||||||
|
"expr": "redis_stream_length{key=\"attachment.jobs.v1\"}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "short"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 27,
|
||||||
|
"title": "Broker pending messages",
|
||||||
|
"type": "timeseries",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "victoriametrics"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 56,
|
||||||
|
"w": 12,
|
||||||
|
"h": 8
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"refId": "A",
|
||||||
|
"expr": "redis_stream_groups_consumer_pending_messages{key=\"attachment.jobs.v1\"}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "short"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 28,
|
||||||
|
"title": "Broker memory used",
|
||||||
|
"type": "timeseries",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "victoriametrics"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"x": 12,
|
||||||
|
"y": 56,
|
||||||
|
"w": 12,
|
||||||
|
"h": 8
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"refId": "A",
|
||||||
|
"expr": "redis_memory_used_bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "bytes"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 29,
|
||||||
|
"title": "Broker connected clients",
|
||||||
|
"type": "timeseries",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "victoriametrics"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 64,
|
||||||
|
"w": 12,
|
||||||
|
"h": 8
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"refId": "A",
|
||||||
|
"expr": "redis_connected_clients"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "short"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [
|
"links": [
|
||||||
|
|||||||
@@ -10,3 +10,6 @@ scrape_configs:
|
|||||||
|
|
||||||
- job_name: ingress
|
- job_name: ingress
|
||||||
static_configs: [{targets: ['lb:8404']}]
|
static_configs: [{targets: ['lb:8404']}]
|
||||||
|
|
||||||
|
- job_name: broker
|
||||||
|
static_configs: [{targets: ['redis-exporter:9121']}]
|
||||||
|
|||||||
@@ -12,3 +12,7 @@ scrape_configs:
|
|||||||
- job_name: ingress
|
- job_name: ingress
|
||||||
static_configs:
|
static_configs:
|
||||||
- targets: ['lb:8404']
|
- targets: ['lb:8404']
|
||||||
|
|
||||||
|
- job_name: broker
|
||||||
|
static_configs:
|
||||||
|
- targets: ['redis-exporter:9121']
|
||||||
|
|||||||
+37
-2
@@ -3,6 +3,8 @@ import base64, json, os, random, string, threading, time, urllib.error, urllib.r
|
|||||||
BASE = os.getenv('MOCK_BASE_URL', 'http://lb:8080').rstrip('/')
|
BASE = os.getenv('MOCK_BASE_URL', 'http://lb:8080').rstrip('/')
|
||||||
RATE = float(os.getenv('MOCK_RATE', '2'))
|
RATE = float(os.getenv('MOCK_RATE', '2'))
|
||||||
WORKERS = int(os.getenv('MOCK_WORKERS', '2'))
|
WORKERS = int(os.getenv('MOCK_WORKERS', '2'))
|
||||||
|
SEND_IMAGES = os.getenv('SEND_IMAGES', 'false').lower() in ('1', 'true', 'yes', 'on')
|
||||||
|
IMAGE_PATH = os.getenv('MOCK_IMAGE_PATH', '/opt/mock/sample.png')
|
||||||
TEXTS = ['Привет из mock-load', 'Проверка pipeline', 'Наблюдаемость работает', 'synthetic message']
|
TEXTS = ['Привет из mock-load', 'Проверка pipeline', 'Наблюдаемость работает', 'synthetic message']
|
||||||
|
|
||||||
def request(method, path, body=None, headers=None):
|
def request(method, path, body=None, headers=None):
|
||||||
@@ -38,6 +40,34 @@ def setup():
|
|||||||
if status not in (201, 409) or not chat.get('id'): return None
|
if status not in (201, 409) or not chat.get('id'): return None
|
||||||
return a, b, chat['id']
|
return a, b, chat['id']
|
||||||
|
|
||||||
|
def upload_image(actor, chat, index):
|
||||||
|
try:
|
||||||
|
with open(IMAGE_PATH, 'rb') as f:
|
||||||
|
data = f.read()
|
||||||
|
req = urllib.request.Request(
|
||||||
|
BASE + f'/api/v1/chats/{chat}/attachments?filename=mock-{index}.png',
|
||||||
|
data=data,
|
||||||
|
headers={'Authorization': 'Bearer ' + actor['token'], 'Content-Type': 'image/png'},
|
||||||
|
method='POST',
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(req, timeout=15) as r:
|
||||||
|
attachment = json.loads(r.read())
|
||||||
|
aid = attachment.get('id')
|
||||||
|
if not aid:
|
||||||
|
return None
|
||||||
|
for _ in range(30):
|
||||||
|
status, current = request('GET', f'/api/v1/attachments/{aid}', headers={'Authorization': 'Bearer ' + actor['token']})
|
||||||
|
if status == 200 and current.get('status') == 'ready':
|
||||||
|
print(f'[mock] image ready attachment={aid}', flush=True)
|
||||||
|
return aid
|
||||||
|
if status == 200 and current.get('status') == 'failed':
|
||||||
|
print(f'[mock] image failed attachment={aid}', flush=True)
|
||||||
|
return None
|
||||||
|
time.sleep(0.2)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'[mock] image upload failed: {e}', flush=True)
|
||||||
|
return None
|
||||||
|
|
||||||
def worker(index, state):
|
def worker(index, state):
|
||||||
a, b, chat = state
|
a, b, chat = state
|
||||||
n = 0
|
n = 0
|
||||||
@@ -45,7 +75,12 @@ def worker(index, state):
|
|||||||
actor = a if n % 2 == 0 else b
|
actor = a if n % 2 == 0 else b
|
||||||
auth = {'Authorization': 'Bearer ' + actor['token']}
|
auth = {'Authorization': 'Bearer ' + actor['token']}
|
||||||
key = f'mock-{index}-{n}-{time.time_ns()}'
|
key = f'mock-{index}-{n}-{time.time_ns()}'
|
||||||
request('POST', f'/api/v1/chats/{chat}/messages', {'text': random.choice(TEXTS)}, {**auth, 'Idempotency-Key': key})
|
attachment_ids = []
|
||||||
|
if SEND_IMAGES and n % 3 == 2:
|
||||||
|
aid = upload_image(actor, chat, n)
|
||||||
|
if aid:
|
||||||
|
attachment_ids = [aid]
|
||||||
|
request('POST', f'/api/v1/chats/{chat}/messages', {'text': random.choice(TEXTS), 'attachment_ids': attachment_ids}, {**auth, 'Idempotency-Key': key})
|
||||||
request('GET', f'/api/v1/chats/{chat}/messages?limit=20', headers=auth)
|
request('GET', f'/api/v1/chats/{chat}/messages?limit=20', headers=auth)
|
||||||
request('GET', '/health/ready')
|
request('GET', '/health/ready')
|
||||||
n += 1
|
n += 1
|
||||||
@@ -54,7 +89,7 @@ def worker(index, state):
|
|||||||
while True:
|
while True:
|
||||||
state = setup()
|
state = setup()
|
||||||
if state:
|
if state:
|
||||||
print(f'[mock] started base={BASE} workers={WORKERS} rate={RATE}/s', flush=True)
|
print(f'[mock] started base={BASE} workers={WORKERS} rate={RATE}/s send_images={SEND_IMAGES}', flush=True)
|
||||||
for i in range(WORKERS): threading.Thread(target=worker, args=(i, state), daemon=True).start()
|
for i in range(WORKERS): threading.Thread(target=worker, args=(i, state), daemon=True).start()
|
||||||
while True: time.sleep(3600)
|
while True: time.sleep(3600)
|
||||||
print('[mock] setup failed; retrying in 5s', flush=True)
|
print('[mock] setup failed; retrying in 5s', flush=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user