feat: add VictoriaMetrics and synthetic demo load
This commit is contained in:
+23
-2
@@ -45,7 +45,7 @@ services:
|
|||||||
cpus: 0.5
|
cpus: 0.5
|
||||||
mem_limit: 128m
|
mem_limit: 128m
|
||||||
s3:
|
s3:
|
||||||
image: quay.io/minio/minio:RELEASE.2025-09-07T16-13-09Z
|
image: ghcr.io/coollabsio/minio:RELEASE.2025-10-15T17-29-55Z
|
||||||
command: [server, /data, --console-address, '127.0.0.1:9001']
|
command: [server, /data, --console-address, '127.0.0.1:9001']
|
||||||
environment:
|
environment:
|
||||||
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
|
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
|
||||||
@@ -60,7 +60,7 @@ services:
|
|||||||
timeout: 2s
|
timeout: 2s
|
||||||
retries: 30
|
retries: 30
|
||||||
s3-init:
|
s3-init:
|
||||||
image: minio/mc:RELEASE.2025-08-13T08-35-41Z
|
image: cgr.dev/chainguard/minio-client:latest-dev
|
||||||
entrypoint: [/bin/sh, /config/s3-init.sh]
|
entrypoint: [/bin/sh, /config/s3-init.sh]
|
||||||
volumes: ['./infra:/config:ro']
|
volumes: ['./infra:/config:ro']
|
||||||
secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key]
|
secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key]
|
||||||
@@ -188,6 +188,26 @@ services:
|
|||||||
cpus: 0.5
|
cpus: 0.5
|
||||||
mem_limit: 256m
|
mem_limit: 256m
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
victoriametrics:
|
||||||
|
image: victoriametrics/victoria-metrics:v1.120.0
|
||||||
|
command: [-promscrape.config=/etc/victoria-metrics/promscrape.yaml, -retentionPeriod=24h, -storageDataPath=/victoria-metrics-data]
|
||||||
|
volumes: ['./infra/victoriametrics/promscrape.yaml:/etc/victoria-metrics/promscrape.yaml:ro', 'victoriametrics_data:/victoria-metrics-data']
|
||||||
|
ports: ['127.0.0.1:${VICTORIAMETRICS_PORT:-8428}:8428']
|
||||||
|
cpus: 0.5
|
||||||
|
mem_limit: 256m
|
||||||
|
restart: unless-stopped
|
||||||
|
mock-load:
|
||||||
|
image: python:3.13-alpine
|
||||||
|
command: [python, /opt/mock/mock_load.py]
|
||||||
|
environment:
|
||||||
|
MOCK_BASE_URL: http://lb:8080
|
||||||
|
MOCK_RATE: ${MOCK_RATE:-2}
|
||||||
|
MOCK_WORKERS: ${MOCK_WORKERS:-2}
|
||||||
|
volumes: ['./mock-load/mock_load.py:/opt/mock/mock_load.py:ro']
|
||||||
|
profiles: [demo]
|
||||||
|
depends_on:
|
||||||
|
lb: {condition: service_healthy}
|
||||||
|
restart: unless-stopped
|
||||||
prometheus:
|
prometheus:
|
||||||
image: prom/prometheus:v3.4.1
|
image: prom/prometheus:v3.4.1
|
||||||
command: [--config.file=/etc/prometheus/prometheus.yaml, --storage.tsdb.retention.time=24h, --storage.tsdb.retention.size=512MB]
|
command: [--config.file=/etc/prometheus/prometheus.yaml, --storage.tsdb.retention.time=24h, --storage.tsdb.retention.size=512MB]
|
||||||
@@ -245,6 +265,7 @@ secrets:
|
|||||||
volumes:
|
volumes:
|
||||||
go_test_cache:
|
go_test_cache:
|
||||||
prometheus_data:
|
prometheus_data:
|
||||||
|
victoriametrics_data:
|
||||||
loki_data:
|
loki_data:
|
||||||
tempo_data:
|
tempo_data:
|
||||||
grafana_data:
|
grafana_data:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -160,7 +160,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -216,7 +216,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -244,7 +244,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -272,7 +272,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -300,7 +300,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -328,7 +328,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -356,7 +356,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -384,7 +384,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -412,7 +412,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -440,7 +440,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -468,7 +468,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -496,7 +496,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -580,7 +580,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -608,7 +608,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
@@ -636,7 +636,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -664,7 +664,7 @@
|
|||||||
"type": "timeseries",
|
"type": "timeseries",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"type": "prometheus",
|
"type": "prometheus",
|
||||||
"uid": "prometheus"
|
"uid": "victoriametrics"
|
||||||
},
|
},
|
||||||
"gridPos": {
|
"gridPos": {
|
||||||
"x": 12,
|
"x": 12,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
apiVersion: 1
|
apiVersion: 1
|
||||||
datasources:
|
datasources:
|
||||||
- {name: Prometheus, uid: prometheus, type: prometheus, access: proxy, url: 'http://prometheus:9090', isDefault: true}
|
- {name: VictoriaMetrics, uid: victoriametrics, type: prometheus, access: proxy, url: 'http://victoriametrics:8428', isDefault: true}
|
||||||
|
- {name: Prometheus (alerts), uid: prometheus, type: prometheus, access: proxy, url: 'http://prometheus:9090', isDefault: false}
|
||||||
- name: Loki
|
- name: Loki
|
||||||
uid: loki
|
uid: loki
|
||||||
type: loki
|
type: loki
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
global:
|
||||||
|
scrape_interval: 2s
|
||||||
|
external_labels:
|
||||||
|
environment: lab6
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: messenger
|
||||||
|
static_configs:
|
||||||
|
- targets: ['collector:8889']
|
||||||
|
- job_name: collector
|
||||||
|
static_configs:
|
||||||
|
- targets: ['collector:8888']
|
||||||
|
- job_name: ingress
|
||||||
|
static_configs:
|
||||||
|
- targets: ['lb:8404']
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import base64, json, os, random, string, threading, time, urllib.error, urllib.request
|
||||||
|
|
||||||
|
BASE = os.getenv('MOCK_BASE_URL', 'http://lb:8080').rstrip('/')
|
||||||
|
RATE = float(os.getenv('MOCK_RATE', '2'))
|
||||||
|
WORKERS = int(os.getenv('MOCK_WORKERS', '2'))
|
||||||
|
TEXTS = ['Привет из mock-load', 'Проверка pipeline', 'Наблюдаемость работает', 'synthetic message']
|
||||||
|
|
||||||
|
def request(method, path, body=None, headers=None):
|
||||||
|
data = None if body is None else json.dumps(body, ensure_ascii=False).encode()
|
||||||
|
h = {'Content-Type': 'application/json'}
|
||||||
|
if headers: h.update(headers)
|
||||||
|
req = urllib.request.Request(BASE + path, data=data, headers=h, method=method)
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req, timeout=8) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return r.status, json.loads(raw) if raw else {}
|
||||||
|
except Exception as e:
|
||||||
|
print(f'[mock] {method} {path}: {e}', flush=True)
|
||||||
|
return 0, {}
|
||||||
|
|
||||||
|
def create_actor(prefix):
|
||||||
|
suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
||||||
|
username = f'{prefix}_{suffix}'
|
||||||
|
password = 'MockOnly-' + suffix + '-123'
|
||||||
|
status, user = request('POST', '/api/v1/users', {'username': username, 'display_name': prefix, 'password': password})
|
||||||
|
if status not in (201, 409):
|
||||||
|
return None
|
||||||
|
token_raw = base64.b64encode(f'{username}:{password}'.encode()).decode()
|
||||||
|
status, session = request('POST', '/api/v1/auth/sessions', headers={'Authorization': 'Basic ' + token_raw})
|
||||||
|
token = session.get('token') or session.get('session_token')
|
||||||
|
uid = user.get('id')
|
||||||
|
return {'id': uid, 'token': token, 'username': username} if token else None
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
a, b = create_actor('mock_a'), create_actor('mock_b')
|
||||||
|
if not a or not b: return None
|
||||||
|
status, chat = request('POST', '/api/v1/chats', {'title': 'mock activity', 'member_ids': [a['id'], b['id']]}, {'Authorization': 'Bearer ' + a['token']})
|
||||||
|
if status not in (201, 409) or not chat.get('id'): return None
|
||||||
|
return a, b, chat['id']
|
||||||
|
|
||||||
|
def worker(index, state):
|
||||||
|
a, b, chat = state
|
||||||
|
n = 0
|
||||||
|
while True:
|
||||||
|
actor = a if n % 2 == 0 else b
|
||||||
|
auth = {'Authorization': 'Bearer ' + actor['token']}
|
||||||
|
key = f'mock-{index}-{n}-{time.time_ns()}'
|
||||||
|
request('POST', f'/api/v1/chats/{chat}/messages', {'text': random.choice(TEXTS)}, {**auth, 'Idempotency-Key': key})
|
||||||
|
request('GET', f'/api/v1/chats/{chat}/messages?limit=20', headers=auth)
|
||||||
|
request('GET', '/health/ready')
|
||||||
|
n += 1
|
||||||
|
time.sleep(max(0.05, 1.0 / max(RATE, 0.1) / max(WORKERS, 1)))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
state = setup()
|
||||||
|
if state:
|
||||||
|
print(f'[mock] started base={BASE} workers={WORKERS} rate={RATE}/s', flush=True)
|
||||||
|
for i in range(WORKERS): threading.Thread(target=worker, args=(i, state), daemon=True).start()
|
||||||
|
while True: time.sleep(3600)
|
||||||
|
print('[mock] setup failed; retrying in 5s', flush=True)
|
||||||
|
time.sleep(5)
|
||||||
Reference in New Issue
Block a user