完成a6000测试系统构建、部署、测试整合 (#35)
测试方案: - lm2机器端口映射到本机:18080, 18081, 8082-8085 - 访问URL: http://localhost:18080/dashboard       端到端测试通过:  Co-authored-by: sundapeng.sdp <sundapeng@hashdata.cn> Reviewed-on: #35 Reviewed-by: xuxt <xuxt@zgclab.edu.cn> Reviewed-by: sundapeng <sundp@mail.zgclab.edu.cn> Reviewed-by: huhy <husteryezi@163.com>
This commit was merged in pull request #35.
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
- 一键执行
|
||||
- `cd src/sys/tests`
|
||||
- `./scripts/00_e2e_test.sh`
|
||||
- `./scripts/00_e2e_test.sh`(CPU-only)或 `./scripts/00_e2e_test.sh --enable-gpu`(启用 GPU 流程)
|
||||
|
||||
- 分步执行(推荐用于排查)
|
||||
- `./scripts/01_bootstrap.sh` 生成目录/拷贝 `update-dns.sh`/构建 agent 二进制/写 `.env`
|
||||
@@ -42,7 +42,12 @@
|
||||
- `./scripts/05_agent_register.sh` 获取两个节点的 `node_id` 与初始 IP,检查本地 `node.json`
|
||||
- `./scripts/06_write_health_and_assert.sh` 写健康文件并断言 `nodes.json` 仅包含 2 个在线节点
|
||||
- `./scripts/07_logs_send_and_assert.sh` 向两个节点写日志,断言 ES `train-*`/`infer-*` 计数增长
|
||||
- `./scripts/08_restart_agent_reregister.sh` `node-b` 改为固定 IP `172.29.0.200`,验证保持同一节点 ID 且 IP/时间戳更新
|
||||
- `./scripts/08_restart_agent_reregister.sh` `node-b` 改为固定 IP `172.31.0.200`,验证保持同一节点 ID 且 IP/时间戳更新
|
||||
- `./scripts/10_metric_publish.sh` 发布 metric 客户端包到 FTP
|
||||
- `./scripts/11_metric_node_install.sh` 在 CPU 节点安装并验证端点
|
||||
- `./scripts/12_metric_gpu_install.sh` 在 GPU 节点安装并等待 9100/9400 就绪(仅启用 GPU 时)
|
||||
- `./scripts/13_metric_verify.sh` 对 master/Prometheus/数据面/Grafana 做综合校验(含 GPU 时校验 dcgm 指标)
|
||||
- `./scripts/14_metric_cleanup.sh` 清理 FTP 产物
|
||||
- `./scripts/09_down.sh` 回收容器、网络并清理 `private*/`、`tmp/`
|
||||
|
||||
- 重置环境
|
||||
@@ -53,16 +58,17 @@
|
||||
## 二、测试部署架构(docker-compose)
|
||||
|
||||
- 网络
|
||||
- 自定义 bridge:`argus-sys-net`,子网 `172.29.0.0/16`
|
||||
- 固定地址:bind=`172.29.0.2`,master=`172.29.0.10`
|
||||
- 自定义 bridge:`argus-sys-net`,子网 `172.31.0.0/16`
|
||||
- 固定地址:bind=`172.31.0.2`,master=`172.31.0.10`
|
||||
|
||||
- 服务与端口
|
||||
- 服务与端口(宿主机映射端口由 `01_bootstrap.sh` 自动分配并写入 `.env`)
|
||||
- 关键变量:`MASTER_PORT`、`ES_HTTP_PORT`、`KIBANA_PORT`、`NODE_A_PORT`、`NODE_B_PORT`、`PROMETHEUS_PORT`、`GRAFANA_PORT`、`ALERTMANAGER_PORT`、`WEB_PROXY_PORT_8080..8085`、`FTP_PORT`、`FTP_DATA_PORT`、`FTP_PASSIVE_HOST_RANGE`
|
||||
- `bind`(`argus-bind9:latest`):监听 53/tcp+udp;负责同步 `*.argus.com` 记录
|
||||
- `master`(`argus-master:latest`):对外 `32300→3000`;API `http://localhost:32300`
|
||||
- `es`(`argus-elasticsearch:latest`):`9200→9200`;单节点,无安全
|
||||
- `kibana`(`argus-kibana:latest`):`5601→5601`;通过 `ELASTICSEARCH_HOSTS=http://es:9200` 访问 ES
|
||||
- `node-a`(`ubuntu:22.04`):同时运行 Fluent Bit + argus-agent,`hostname=dev-yyrshare-nbnyx10-cp2f-pod-0`,`2020→2020`
|
||||
- `node-b`(`ubuntu:22.04`):同时运行 Fluent Bit + argus-agent,`hostname=dev-yyrshare-uuuu10-ep2f-pod-0`,`2021→2020`
|
||||
- `master`(`argus-master:latest`):对外 `${MASTER_PORT}→3000`;API `http://localhost:${MASTER_PORT}`
|
||||
- `es`(`argus-elasticsearch:latest`):`${ES_HTTP_PORT}→9200`;单节点,无安全
|
||||
- `kibana`(`argus-kibana:latest`):`${KIBANA_PORT}→5601`;通过 `ELASTICSEARCH_HOSTS=http://es:9200` 访问 ES
|
||||
- `node-a`(`ubuntu:22.04`):同时运行 Fluent Bit + argus-agent,`hostname=dev-yyrshare-nbnyx10-cp2f-pod-0`,`${NODE_A_PORT}→2020`
|
||||
- `node-b`(`ubuntu:22.04`):同时运行 Fluent Bit + argus-agent,`hostname=dev-yyrshare-uuuu10-ep2f-pod-0`,`${NODE_B_PORT}→2020`
|
||||
|
||||
- 卷与目录
|
||||
- 核心服务(bind/master/es/kibana)共享宿主 `./private` 挂载到容器 `/private`
|
||||
@@ -72,7 +78,7 @@
|
||||
- 节点容器的 Fluent Bit/agent 资产以只读方式挂载到 `/assets`/`/usr/local/bin/argus-agent`
|
||||
|
||||
- DNS 配置
|
||||
- 节点容器通过 compose 配置 `dns: [172.29.0.2]` 指向 bind,不挂载 `/etc/resolv.conf`,也不依赖 `update-dns.sh`
|
||||
- 节点容器通过 compose 配置 `dns: [172.31.0.2]` 指向 bind,不挂载 `/etc/resolv.conf`,也不依赖 `update-dns.sh`
|
||||
- master/es/kibana 仍共享 `./private`,master 启动会写 `/private/argus/etc/master.argus.com` 供 bind 同步 A 记录
|
||||
|
||||
- 节点入口
|
||||
@@ -106,6 +112,7 @@
|
||||
- 判定:
|
||||
- `private/argus/etc/master.argus.com` 存在且为 master IP
|
||||
- 在 node-a/node-b 内 `getent hosts master.argus.com` 成功解析到 master IP
|
||||
- 在 metric CPU/GPU 节点内可解析 `master.argus.com` 与 `prom.metric.argus.com`
|
||||
|
||||
- `05_agent_register.sh`
|
||||
- 目的:确认两个节点注册到 master 并持久化 `node.json`
|
||||
@@ -136,3 +143,16 @@
|
||||
---
|
||||
|
||||
如需更严格的断言(例如 Kibana 载入具体插件、ES 文档字段校验),可在 `07_*.sh` 中追加查询与校验逻辑。
|
||||
|
||||
---
|
||||
|
||||
## 可选:GPU 流程说明
|
||||
- 前置条件:宿主安装 NVIDIA 驱动与 `nvidia-container-toolkit`,`nvidia-smi` 在宿主可用。
|
||||
- 启用方式:
|
||||
- 一键:`./scripts/00_e2e_test.sh --enable-gpu`
|
||||
- 分步:设置 `ARGUS_SYS_ENABLE_GPU=true` 后执行 `01_bootstrap.sh`、`02_up.sh`;或直接在 `.env` 中将 `ENABLE_GPU=true` 后单独运行 `02_up.sh`。
|
||||
- `01_bootstrap.sh` 会写入:
|
||||
- `METRIC_TEST_HOSTNAME_GPU=test-metric-gpu-node-001`
|
||||
- `METRIC_TEST_INSTANCE_GPU=172.31.0.51:9100`
|
||||
- `METRIC_TEST_DCGM_GPU=172.31.0.51:9400`
|
||||
- 验证点:`04_verify_dns_routing.sh` 增加对 metric 节点的域名解析;`12_metric_gpu_install.sh` 等待 9100/9400;`13_metric_verify_*` 校验 dcgm 指标与 Grafana 面板。
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
version: "3.8"
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: argus-sys-net
|
||||
sysnet:
|
||||
driver: bridge
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: 172.29.0.0/16
|
||||
- subnet: 172.31.0.0/16
|
||||
|
||||
services:
|
||||
bind:
|
||||
image: ${BIND_IMAGE_TAG:-argus-bind9:latest}
|
||||
container_name: argus-bind-sys
|
||||
networks:
|
||||
default:
|
||||
ipv4_address: 172.29.0.2
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.2
|
||||
volumes:
|
||||
- ./private:/private
|
||||
restart: unless-stopped
|
||||
@@ -32,14 +29,14 @@ services:
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
ports:
|
||||
- "32300:3000"
|
||||
- "${MASTER_PORT:-32300}:3000"
|
||||
volumes:
|
||||
- ./private/argus/master:/private/argus/master
|
||||
- ./private/argus/metric/prometheus:/private/argus/metric/prometheus
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
networks:
|
||||
default:
|
||||
ipv4_address: 172.29.0.10
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.10
|
||||
restart: unless-stopped
|
||||
|
||||
es:
|
||||
@@ -55,8 +52,11 @@ services:
|
||||
- ./private/argus/log/elasticsearch:/private/argus/log/elasticsearch
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
ports:
|
||||
- "9200:9200"
|
||||
- "${ES_HTTP_PORT:-9200}:9200"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.3
|
||||
|
||||
kibana:
|
||||
image: argus-kibana:latest
|
||||
@@ -71,11 +71,14 @@ services:
|
||||
depends_on:
|
||||
- es
|
||||
ports:
|
||||
- "5601:5601"
|
||||
- "${KIBANA_PORT:-5601}:5601"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.4
|
||||
|
||||
node-a:
|
||||
image: ubuntu:22.04
|
||||
image: argus-sys-node:latest
|
||||
container_name: argus-node-a
|
||||
hostname: dev-yyrshare-nbnyx10-cp2f-pod-0
|
||||
depends_on:
|
||||
@@ -101,13 +104,16 @@ services:
|
||||
entrypoint:
|
||||
- /usr/local/bin/node-entrypoint.sh
|
||||
dns:
|
||||
- 172.29.0.2
|
||||
- 172.31.0.2 # internal bind for *.argus.com
|
||||
- 8.8.8.8 # external fallback for apt/external domains
|
||||
ports:
|
||||
- "2020:2020"
|
||||
- "${NODE_A_PORT:-2020}:2020"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- sysnet
|
||||
|
||||
node-b:
|
||||
image: ubuntu:22.04
|
||||
image: argus-sys-node:latest
|
||||
container_name: argus-node-b
|
||||
hostname: dev-yyrshare-uuuu10-ep2f-pod-0
|
||||
depends_on:
|
||||
@@ -133,7 +139,269 @@ services:
|
||||
entrypoint:
|
||||
- /usr/local/bin/node-entrypoint.sh
|
||||
dns:
|
||||
- 172.29.0.2
|
||||
- 172.31.0.2
|
||||
- 8.8.8.8
|
||||
ports:
|
||||
- "2021:2020"
|
||||
- "${NODE_B_PORT:-2021}:2020"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- sysnet
|
||||
|
||||
ftp:
|
||||
image: argus-metric-ftp:latest
|
||||
container_name: argus-ftp
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- FTP_BASE_PATH=/private/argus/ftp
|
||||
- FTP_PASSWORD=${FTP_PASSWORD:-ZGClab1234!}
|
||||
- DOMAIN=${FTP_DOMAIN:-ftp.metric.argus.com}
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
ports:
|
||||
- "${FTP_PORT:-21}:21"
|
||||
- "${FTP_DATA_PORT:-20}:20"
|
||||
- "${FTP_PASSIVE_HOST_RANGE:-21100-21110}:21100-21110"
|
||||
volumes:
|
||||
- ./private/argus/metric/ftp:/private/argus/ftp
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.40
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
prometheus:
|
||||
image: argus-metric-prometheus:latest
|
||||
container_name: argus-prometheus
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- PROMETHEUS_BASE_PATH=/private/argus/metric/prometheus
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
ports:
|
||||
- "${PROMETHEUS_PORT:-9090}:9090"
|
||||
volumes:
|
||||
- ./private/argus/metric/prometheus:/private/argus/metric/prometheus
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.41
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
grafana:
|
||||
image: argus-metric-grafana:latest
|
||||
container_name: argus-grafana
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- GRAFANA_BASE_PATH=/private/argus/metric/grafana
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
- GF_SERVER_HTTP_PORT=3000
|
||||
- GF_LOG_LEVEL=warn
|
||||
- GF_LOG_MODE=console
|
||||
- GF_PATHS_PROVISIONING=/private/argus/metric/grafana/provisioning
|
||||
- GF_AUTH_ANONYMOUS_ENABLED=true
|
||||
- GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
|
||||
ports:
|
||||
- "${GRAFANA_PORT:-3000}:3000"
|
||||
volumes:
|
||||
- ./private/argus/metric/grafana:/private/argus/metric/grafana
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.42
|
||||
depends_on:
|
||||
- prometheus
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
# --- Added: Web Frontend (no host port; resolved by DNS as web.argus.com) ---
|
||||
web-frontend:
|
||||
image: argus-web-frontend:latest
|
||||
container_name: argus-web-frontend
|
||||
environment:
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
# Frontend runtime-injected external ports (used to render hyperlinks)
|
||||
- EXTERNAL_MASTER_PORT=${WEB_PROXY_PORT_8085:-8085}
|
||||
- EXTERNAL_ALERTMANAGER_PORT=${WEB_PROXY_PORT_8084:-8084}
|
||||
- EXTERNAL_GRAFANA_PORT=${WEB_PROXY_PORT_8081:-8081}
|
||||
- EXTERNAL_PROMETHEUS_PORT=${WEB_PROXY_PORT_8082:-8082}
|
||||
- EXTERNAL_KIBANA_PORT=${WEB_PROXY_PORT_8083:-8083}
|
||||
volumes:
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.80
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
test-node:
|
||||
image: argus-sys-metric-test-node:latest
|
||||
container_name: argus-metric-test-node
|
||||
hostname: test-metric-node-001
|
||||
restart: unless-stopped
|
||||
privileged: true
|
||||
depends_on:
|
||||
- ftp
|
||||
- prometheus
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- DEBIAN_FRONTEND=noninteractive
|
||||
- FTP_DOMAIN=${FTP_DOMAIN:-ftp.metric.argus.com}
|
||||
- FTP_SERVER=${FTP_SERVER:-172.31.0.40}
|
||||
- FTP_USER=${FTP_USER:-ftpuser}
|
||||
- FTP_PASSWORD=${FTP_PASSWORD:-ZGClab1234!}
|
||||
- FTP_PORT=${FTP_PORT:-21}
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
- METRIC_NODE_ROLE=cpu
|
||||
volumes:
|
||||
- ./private/argus/agent:/private/argus/agent
|
||||
- ./scripts/metric/test-node-entrypoint.sh:/usr/local/bin/metric-test-node-entrypoint.sh:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
entrypoint:
|
||||
- /usr/local/bin/metric-test-node-entrypoint.sh
|
||||
command:
|
||||
- sleep
|
||||
- infinity
|
||||
dns:
|
||||
- 172.31.0.2
|
||||
- 8.8.8.8
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.50
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
test-gpu-node:
|
||||
profiles: ["gpu"]
|
||||
image: argus-sys-metric-test-gpu-node:latest
|
||||
container_name: argus-metric-test-gpu-node
|
||||
hostname: test-metric-gpu-node-001
|
||||
restart: unless-stopped
|
||||
privileged: true
|
||||
runtime: nvidia
|
||||
deploy:
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
count: all
|
||||
capabilities:
|
||||
- gpu
|
||||
depends_on:
|
||||
- ftp
|
||||
- prometheus
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- DEBIAN_FRONTEND=noninteractive
|
||||
- NVIDIA_VISIBLE_DEVICES=all
|
||||
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
|
||||
- GPU_MODE=gpu
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
- METRIC_NODE_ROLE=gpu
|
||||
volumes:
|
||||
- ./private/argus/agent:/private/argus/agent
|
||||
- ./scripts/metric/test-node-entrypoint.sh:/usr/local/bin/metric-test-node-entrypoint.sh:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
entrypoint:
|
||||
- /usr/local/bin/metric-test-node-entrypoint.sh
|
||||
command:
|
||||
- sleep
|
||||
- infinity
|
||||
dns:
|
||||
- 172.31.0.2
|
||||
- 8.8.8.8
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.51
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
# --- Added: Alertmanager ---
|
||||
alertmanager:
|
||||
image: argus-alertmanager:latest
|
||||
container_name: argus-alertmanager
|
||||
environment:
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
volumes:
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
- ./private/argus/alert/alertmanager:/private/argus/alert/alertmanager
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.82
|
||||
ports:
|
||||
- "${ALERTMANAGER_PORT:-9093}:9093"
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
# --- Added: Web Proxy (multi-port gateway) ---
|
||||
web-proxy:
|
||||
image: argus-web-proxy:latest
|
||||
container_name: argus-web-proxy
|
||||
depends_on:
|
||||
- bind
|
||||
- master
|
||||
- grafana
|
||||
- prometheus
|
||||
- kibana
|
||||
- alertmanager
|
||||
environment:
|
||||
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
volumes:
|
||||
- ./private/argus/etc:/private/argus/etc
|
||||
networks:
|
||||
sysnet:
|
||||
ipv4_address: 172.31.0.81
|
||||
ports:
|
||||
- "${WEB_PROXY_PORT_8080:-8080}:8080"
|
||||
- "${WEB_PROXY_PORT_8081:-8081}:8081"
|
||||
- "${WEB_PROXY_PORT_8082:-8082}:8082"
|
||||
- "${WEB_PROXY_PORT_8083:-8083}:8083"
|
||||
- "${WEB_PROXY_PORT_8084:-8084}:8084"
|
||||
- "${WEB_PROXY_PORT_8085:-8085}:8085"
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
@@ -3,6 +3,45 @@ set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
ENABLE_GPU=false
|
||||
CLEANUP=true
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: 00_e2e_test.sh [options]
|
||||
|
||||
Options:
|
||||
--enable-gpu 启用 GPU 相关拓扑与测试流程
|
||||
--no-clean 跳过清理流程(不执行 14 和 09)
|
||||
-h, --help 显示帮助信息
|
||||
EOF
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--enable-gpu)
|
||||
ENABLE_GPU=true
|
||||
shift
|
||||
;;
|
||||
--no-clean)
|
||||
CLEANUP=false
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $1" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
export ARGUS_SYS_ENABLE_GPU=$ENABLE_GPU
|
||||
|
||||
# 基础步骤(不包含清理与下线)
|
||||
SCRIPTS=(
|
||||
"01_bootstrap.sh"
|
||||
"02_up.sh"
|
||||
@@ -12,9 +51,20 @@ SCRIPTS=(
|
||||
"06_write_health_and_assert.sh"
|
||||
"07_logs_send_and_assert.sh"
|
||||
"08_restart_agent_reregister.sh"
|
||||
"09_down.sh"
|
||||
"10_metric_publish.sh"
|
||||
"11_metric_node_install.sh"
|
||||
"12_metric_gpu_install.sh"
|
||||
"13_metric_verify.sh"
|
||||
)
|
||||
|
||||
# 如未禁用清理,则追加清理与下线步骤(保持原有顺序)
|
||||
if [[ "$CLEANUP" == "true" ]]; then
|
||||
SCRIPTS+=(
|
||||
"14_metric_cleanup.sh"
|
||||
"09_down.sh"
|
||||
)
|
||||
fi
|
||||
|
||||
for script in "${SCRIPTS[@]}"; do
|
||||
echo "[SYS-E2E] Running $script"
|
||||
"$SCRIPT_DIR/$script"
|
||||
@@ -22,5 +72,8 @@ for script in "${SCRIPTS[@]}"; do
|
||||
echo
|
||||
done
|
||||
|
||||
echo "[SYS-E2E] All tests completed"
|
||||
|
||||
if [[ "$CLEANUP" == "true" ]]; then
|
||||
echo "[SYS-E2E] All tests completed"
|
||||
else
|
||||
echo "[SYS-E2E] All tests completed (cleanup skipped)"
|
||||
fi
|
||||
|
||||
@@ -22,24 +22,66 @@ ensure_image() {
|
||||
}
|
||||
|
||||
echo "[INFO] Preparing directories..."
|
||||
ensure_writable_dir() {
|
||||
local path="$1"
|
||||
local parent
|
||||
parent="$(dirname "$path")"
|
||||
mkdir -p "$parent" 2>/dev/null || true
|
||||
mkdir -p "$path" 2>/dev/null || true
|
||||
if [[ ! -w "$path" ]]; then
|
||||
docker run --rm -v "$parent:/target" ubuntu:24.04 bash -lc "chown -R $(id -u):$(id -g) /target" >/dev/null 2>&1 || true
|
||||
fi
|
||||
mkdir -p "$path"
|
||||
}
|
||||
|
||||
# preflight: make base dirs writable if inherited from root-owned mounts
|
||||
ensure_writable_dir "$PRIVATE_CORE/argus"
|
||||
ensure_writable_dir "$PRIVATE_CORE/argus/metric"
|
||||
ensure_writable_dir "$PRIVATE_CORE/argus/metric/grafana"
|
||||
ensure_writable_dir "$PRIVATE_CORE/argus/metric/prometheus"
|
||||
|
||||
mkdir -p \
|
||||
"$PRIVATE_CORE/argus/etc" \
|
||||
"$PRIVATE_CORE/argus/bind" \
|
||||
"$PRIVATE_CORE/argus/master" \
|
||||
"$PRIVATE_CORE/argus/metric/prometheus" \
|
||||
"$PRIVATE_CORE/argus/alert/alertmanager" \
|
||||
"$PRIVATE_CORE/argus/metric/ftp/share" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/data" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/logs" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/plugins" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/provisioning/datasources" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/provisioning/dashboards" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/data/sessions" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/data/dashboards" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana/config" \
|
||||
"$PRIVATE_CORE/argus/metric/prometheus/data" \
|
||||
"$PRIVATE_CORE/argus/metric/prometheus/rules" \
|
||||
"$PRIVATE_CORE/argus/metric/prometheus/targets" \
|
||||
"$PRIVATE_CORE/argus/agent" \
|
||||
"$PRIVATE_CORE/argus/log/elasticsearch" \
|
||||
"$PRIVATE_CORE/argus/log/kibana" \
|
||||
"$PRIVATE_NODEA/argus/agent/dev-yyrshare-nbnyx10-cp2f-pod-0/health" \
|
||||
"$PRIVATE_NODEB/argus/agent/dev-yyrshare-uuuu10-ep2f-pod-0/health" \
|
||||
"$TMP_DIR"
|
||||
|
||||
# Align ownership for supervisor-managed services (ES/Kibana expect UID/GID inside container)
|
||||
# Align ownership for supervisor-managed services (ES/Kibana/Grafana expect UID/GID inside container)
|
||||
echo "[INFO] Fixing ownership for core private directories..."
|
||||
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" \
|
||||
"$PRIVATE_CORE/argus/log/elasticsearch" \
|
||||
"$PRIVATE_CORE/argus/log/kibana" \
|
||||
"$PRIVATE_CORE/argus/metric/grafana" \
|
||||
"$PRIVATE_CORE/argus/metric/prometheus" \
|
||||
"$PRIVATE_CORE/argus/alert" \
|
||||
"$PRIVATE_CORE/argus/metric/ftp" \
|
||||
"$PRIVATE_CORE/argus/agent" \
|
||||
"$PRIVATE_CORE/argus/etc" 2>/dev/null || true
|
||||
|
||||
# 确保 alert 与 etc 目录组可写,便于非 root 且仅匹配 GID 的服务写入运行文件
|
||||
chmod -R g+w "$PRIVATE_CORE/argus/alert" "$PRIVATE_CORE/argus/etc" 2>/dev/null || true
|
||||
|
||||
echo "[INFO] Using compose-managed network (auto-created by docker compose)"
|
||||
|
||||
echo "[INFO] Distributing update-dns.sh for core services (bind/master/es/kibana)"
|
||||
BIND_UPDATE_SRC="$REPO_ROOT/src/bind/build/update-dns.sh"
|
||||
BIND_UPDATE_DEST="$PRIVATE_CORE/argus/etc/update-dns.sh"
|
||||
@@ -55,6 +97,51 @@ ensure_image "argus-elasticsearch:latest"
|
||||
ensure_image "argus-kibana:latest"
|
||||
ensure_image "argus-bind9:latest"
|
||||
ensure_image "argus-master:latest"
|
||||
ensure_image "argus-metric-ftp:latest"
|
||||
ensure_image "argus-metric-prometheus:latest"
|
||||
ensure_image "argus-metric-grafana:latest"
|
||||
ensure_image "argus-web-frontend:latest"
|
||||
ensure_image "argus-web-proxy:latest"
|
||||
ensure_image "argus-alertmanager:latest"
|
||||
|
||||
echo "[INFO] Preparing Fluent Bit local dependency packages..."
|
||||
FLB_BUILD_PACKAGES_DIR="$REPO_ROOT/src/log/fluent-bit/build/packages"
|
||||
mkdir -p "$FLB_BUILD_PACKAGES_DIR"
|
||||
for deb in \
|
||||
"$REPO_ROOT/src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/bin/libyaml-0-2_"*_amd64.deb \
|
||||
"$REPO_ROOT/src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/bin/libpq5_"*_amd64.deb ; do
|
||||
if ls $deb >/dev/null 2>&1; then
|
||||
for f in $deb; do
|
||||
base="$(basename "$f")"
|
||||
if [[ ! -f "$FLB_BUILD_PACKAGES_DIR/$base" ]]; then
|
||||
cp "$f" "$FLB_BUILD_PACKAGES_DIR/"
|
||||
echo " [+] copied $base"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
# 额外:从 all-in-one-full 的 ubuntu22/curl.tar.gz 解包必要依赖(libsasl2/ldap),便于离线安装
|
||||
CURLOPT_TAR="$REPO_ROOT/src/metric/client-plugins/all-in-one-full/deps/ubuntu22/curl.tar.gz"
|
||||
if [[ -f "$CURLOPT_TAR" ]]; then
|
||||
tmpdir=$(mktemp -d)
|
||||
if tar -xzf "$CURLOPT_TAR" -C "$tmpdir" 2>/dev/null; then
|
||||
for p in \
|
||||
libsasl2-2_*_amd64.deb \
|
||||
libsasl2-modules-db_*_amd64.deb \
|
||||
libldap-2.5-0_*_amd64.deb \
|
||||
libidn2-0_*_amd64.deb \
|
||||
libbrotli1_*_amd64.deb \
|
||||
libssl3_*_amd64.deb ; do
|
||||
src=$(ls "$tmpdir"/curl/$p 2>/dev/null | head -n1 || true)
|
||||
if [[ -n "$src" ]]; then
|
||||
base="$(basename "$src")"
|
||||
[[ -f "$FLB_BUILD_PACKAGES_DIR/$base" ]] || cp "$src" "$FLB_BUILD_PACKAGES_DIR/" && echo " [+] staged $base"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
rm -rf "$tmpdir"
|
||||
fi
|
||||
|
||||
echo "[INFO] Building agent binary..."
|
||||
pushd "$REPO_ROOT/src/agent" >/dev/null
|
||||
@@ -68,10 +155,139 @@ if [[ ! -x "$AGENT_BIN" ]]; then
|
||||
fi
|
||||
echo "$AGENT_BIN" > "$TMP_DIR/agent_binary_path"
|
||||
|
||||
echo "[INFO] Writing .env with UID/GID"
|
||||
# 检测GPU环境
|
||||
REQUEST_GPU=${ARGUS_SYS_ENABLE_GPU:-false}
|
||||
GPU_CHECK_SCRIPT="$REPO_ROOT/src/metric/tests/scripts/common/check-gpu.sh"
|
||||
if [[ "$REQUEST_GPU" == "true" ]]; then
|
||||
echo "[INFO] --enable-gpu 已启用,开始检测GPU环境..."
|
||||
if [[ -f "$GPU_CHECK_SCRIPT" ]]; then
|
||||
if bash "$GPU_CHECK_SCRIPT" >/dev/null 2>&1; then
|
||||
echo "[INFO] GPU环境可用,将在 compose 中启用 test-gpu-node"
|
||||
GPU_AVAILABLE=true
|
||||
else
|
||||
echo "[ERROR] 未检测到可用 GPU,但指定了 --enable-gpu" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "[ERROR] 未找到 GPU 检测脚本: $GPU_CHECK_SCRIPT" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
GPU_AVAILABLE=false
|
||||
echo "[INFO] GPU 支持未启用,跳过 GPU 检测"
|
||||
fi
|
||||
|
||||
echo "[INFO] Writing .env with UID/GID and metric configuration"
|
||||
#############################################
|
||||
# 动态分配宿主机端口并写入 .env
|
||||
#############################################
|
||||
|
||||
# 读取现有 .env(若存在),用于保留密码/域名等
|
||||
EXIST_DOTENV="$TEST_ROOT/.env"
|
||||
if [[ -f "$EXIST_DOTENV" ]]; then
|
||||
EXISTING_FTP_PASSWORD="$(grep -E '^FTP_PASSWORD=' "$EXIST_DOTENV" | tail -n1 | sed 's/^FTP_PASSWORD=//')"
|
||||
EXISTING_FTP_DOMAIN="$(grep -E '^FTP_DOMAIN=' "$EXIST_DOTENV" | tail -n1 | sed 's/^FTP_DOMAIN=//')"
|
||||
EXISTING_USE_INTRANET="$(grep -E '^USE_INTRANET=' "$EXIST_DOTENV" | tail -n1 | sed 's/^USE_INTRANET=//')"
|
||||
else
|
||||
EXISTING_FTP_PASSWORD=""
|
||||
EXISTING_FTP_DOMAIN=""
|
||||
EXISTING_USE_INTRANET=""
|
||||
fi
|
||||
|
||||
is_port_free() {
|
||||
local p="$1"
|
||||
ss -ltnH 2>/dev/null | awk -v pat=":${p}$" '$4 ~ pat{f=1} END{exit f?1:0}'
|
||||
}
|
||||
|
||||
find_free_port() {
|
||||
local prefer="$1"; local start_scan="${2:-20000}"; local max="${3:-65000}"
|
||||
if is_port_free "$prefer"; then echo "$prefer"; return 0; fi
|
||||
local p
|
||||
for (( p=start_scan; p<=max; p++ )); do
|
||||
if is_port_free "$p"; then echo "$p"; return 0; fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
find_free_range() {
|
||||
local begin="$1"; local end="$2"; local need_count=$((end-begin+1))
|
||||
local try_start="$begin"
|
||||
while (( try_start + need_count - 1 <= 65000 )); do
|
||||
local ok=1
|
||||
for (( p=try_start; p<try_start+need_count; p++ )); do
|
||||
if ! is_port_free "$p"; then ok=0; break; fi
|
||||
done
|
||||
if (( ok==1 )); then
|
||||
echo "${try_start}-$((try_start+need_count-1))"; return 0
|
||||
fi
|
||||
((try_start++))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# 优先端口(若占用则回退到 20000+ 的空闲)
|
||||
MASTER_PORT_VAL=$(find_free_port 32300)
|
||||
ES_HTTP_PORT_VAL=$(find_free_port 9200)
|
||||
KIBANA_PORT_VAL=$(find_free_port 5601)
|
||||
NODE_A_PORT_VAL=$(find_free_port 2020)
|
||||
NODE_B_PORT_VAL=$(find_free_port 2021)
|
||||
PROMETHEUS_PORT_VAL=$(find_free_port 9090)
|
||||
GRAFANA_PORT_VAL=$(find_free_port 3000)
|
||||
ALERTMANAGER_PORT_VAL=$(find_free_port 9093)
|
||||
WEB_PROXY_PORT_8080_VAL=$(find_free_port 8080 18080 65000)
|
||||
WEB_PROXY_PORT_8081_VAL=$(find_free_port 8081 18081 65000)
|
||||
WEB_PROXY_PORT_8082_VAL=$(find_free_port 8082 18082 65000)
|
||||
WEB_PROXY_PORT_8083_VAL=$(find_free_port 8083 18083 65000)
|
||||
WEB_PROXY_PORT_8084_VAL=$(find_free_port 8084 18084 65000)
|
||||
WEB_PROXY_PORT_8085_VAL=$(find_free_port 8085 18085 65000)
|
||||
|
||||
# FTP 控制/数据端口:若 21/20 被占用则回退到空闲
|
||||
FTP_PORT_VAL=$(find_free_port 21 2121 65000)
|
||||
FTP_DATA_PORT_VAL=$(find_free_port 20 2120 65000)
|
||||
|
||||
# FTP 被动端口范围:优先 21100-21110,若被占用则向后平移
|
||||
FTP_PASV_RANGE_VAL="$(find_free_range 21100 21110 || echo 22100-22110)"
|
||||
|
||||
# 变量持久化到 .env
|
||||
cat > "$TEST_ROOT/.env" <<EOF
|
||||
ARGUS_BUILD_UID=$ARGUS_BUILD_UID
|
||||
ARGUS_BUILD_GID=$ARGUS_BUILD_GID
|
||||
|
||||
# GPU 配置
|
||||
ENABLE_GPU=$GPU_AVAILABLE
|
||||
|
||||
# 测试节点(CPU/GPU)默认标识与实例
|
||||
METRIC_TEST_HOSTNAME_CPU=test-metric-node-001
|
||||
METRIC_TEST_INSTANCE_CPU=172.31.0.50:9100
|
||||
METRIC_TEST_HOSTNAME_GPU=test-metric-gpu-node-001
|
||||
METRIC_TEST_INSTANCE_GPU=172.31.0.51:9100
|
||||
METRIC_TEST_DCGM_GPU=172.31.0.51:9400
|
||||
|
||||
# Master/日志/监控等服务的宿主机端口(自动分配)
|
||||
MASTER_PORT=$MASTER_PORT_VAL
|
||||
ES_HTTP_PORT=$ES_HTTP_PORT_VAL
|
||||
KIBANA_PORT=$KIBANA_PORT_VAL
|
||||
NODE_A_PORT=$NODE_A_PORT_VAL
|
||||
NODE_B_PORT=$NODE_B_PORT_VAL
|
||||
PROMETHEUS_PORT=$PROMETHEUS_PORT_VAL
|
||||
GRAFANA_PORT=$GRAFANA_PORT_VAL
|
||||
ALERTMANAGER_PORT=$ALERTMANAGER_PORT_VAL
|
||||
WEB_PROXY_PORT_8080=$WEB_PROXY_PORT_8080_VAL
|
||||
WEB_PROXY_PORT_8081=$WEB_PROXY_PORT_8081_VAL
|
||||
WEB_PROXY_PORT_8082=$WEB_PROXY_PORT_8082_VAL
|
||||
WEB_PROXY_PORT_8083=$WEB_PROXY_PORT_8083_VAL
|
||||
WEB_PROXY_PORT_8084=$WEB_PROXY_PORT_8084_VAL
|
||||
WEB_PROXY_PORT_8085=$WEB_PROXY_PORT_8085_VAL
|
||||
|
||||
# FTP 配置(自动分配:若21/20占用则使用高位端口)
|
||||
FTP_PORT=$FTP_PORT_VAL
|
||||
FTP_DATA_PORT=$FTP_DATA_PORT_VAL
|
||||
FTP_PASSIVE_HOST_RANGE=$FTP_PASV_RANGE_VAL
|
||||
FTP_PASSWORD=${EXISTING_FTP_PASSWORD:-ZGClab1234!}
|
||||
FTP_DOMAIN=${EXISTING_FTP_DOMAIN:-ftp.metric.argus.com}
|
||||
|
||||
# 网络配置
|
||||
USE_INTRANET=${EXISTING_USE_INTRANET:-false}
|
||||
EOF
|
||||
|
||||
echo "[OK] Bootstrap completed"
|
||||
echo "[OK] Bootstrap completed. Ports written to $TEST_ROOT/.env"
|
||||
|
||||
@@ -3,6 +3,7 @@ set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
REPO_ROOT="$(cd "$TEST_ROOT/../../.." && pwd)"
|
||||
|
||||
compose() {
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
@@ -13,10 +14,92 @@ compose() {
|
||||
}
|
||||
|
||||
echo "[INFO] Bringing up system stack..."
|
||||
|
||||
# 加载 .env 以获取端口(由 01_bootstrap 生成)
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
# GPU 开关优先级:显式环境变量 > .env 中的 ENABLE_GPU > 默认 false
|
||||
if [[ "${ARGUS_SYS_ENABLE_GPU:-}" == "true" ]]; then
|
||||
REQUEST_GPU=true
|
||||
elif [[ "${ARGUS_SYS_ENABLE_GPU:-}" == "false" ]]; then
|
||||
REQUEST_GPU=false
|
||||
else
|
||||
REQUEST_GPU=${ENABLE_GPU:-false}
|
||||
fi
|
||||
|
||||
GPU_AVAILABLE=false
|
||||
GPU_CHECK_SCRIPT="$REPO_ROOT/src/metric/tests/scripts/common/check-gpu.sh"
|
||||
|
||||
if [[ "$REQUEST_GPU" == "true" ]]; then
|
||||
echo "[INFO] --enable-gpu 生效,验证主机 GPU..."
|
||||
if [[ -f "$GPU_CHECK_SCRIPT" ]]; then
|
||||
if bash "$GPU_CHECK_SCRIPT" >/dev/null 2>&1; then
|
||||
GPU_AVAILABLE=true
|
||||
echo "[INFO] GPU 检测通过,将启动 gpu profile"
|
||||
else
|
||||
echo "[ERROR] 主机缺少可用 GPU,无法继续 --enable-gpu 流程" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "[ERROR] 未找到 GPU 检测脚本: $GPU_CHECK_SCRIPT" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "[INFO] 未启用 GPU 流程"
|
||||
fi
|
||||
|
||||
pushd "$TEST_ROOT" >/dev/null
|
||||
compose -p argus-sys down --remove-orphans || true
|
||||
compose -p argus-sys up -d
|
||||
|
||||
# 清理可能由 08 脚本创建的同名容器,避免 compose up 冲突
|
||||
for name in argus-node-b; do
|
||||
if docker ps -aqf "name=^${name}$" >/dev/null 2>&1 && [[ -n "$(docker ps -aqf "name=^${name}$")" ]]; then
|
||||
docker rm -f "$name" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
|
||||
# 预检:检查多端口网关所需宿主端口是否空闲
|
||||
check_port_free() {
|
||||
local p="$1"
|
||||
if ss -ltnp 2>/dev/null | grep -q ":${p} "; then
|
||||
echo "[ERR] Host port ${p} is already in use. Please free it before running 02_up.sh" >&2
|
||||
ss -ltnp | awk -v p=":${p} " '$0 ~ p {print " " $0}' || true
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
for port in \
|
||||
"${WEB_PROXY_PORT_8080:-8080}" \
|
||||
"${WEB_PROXY_PORT_8081:-8081}" \
|
||||
"${WEB_PROXY_PORT_8082:-8082}" \
|
||||
"${WEB_PROXY_PORT_8083:-8083}" \
|
||||
"${WEB_PROXY_PORT_8084:-8084}" \
|
||||
"${WEB_PROXY_PORT_8085:-8085}"; do
|
||||
check_port_free "$port" || { echo "[ERR] Required port busy: $port"; exit 1; }
|
||||
done
|
||||
|
||||
# 根据GPU可用性决定启动的服务
|
||||
if [[ "$GPU_AVAILABLE" == true ]]; then
|
||||
echo "[INFO] 启动所有服务(包含 gpu profile)..."
|
||||
compose -p argus-sys --profile gpu up -d || true
|
||||
else
|
||||
echo "[INFO] 启动基础服务(不含 gpu profile)..."
|
||||
compose -p argus-sys up -d || true
|
||||
fi
|
||||
|
||||
# 若 web-proxy 处于 Created 状态,尝试单独启动一次(处理偶发 Address already in use 后端已释放的场景)
|
||||
if docker ps -a --format '{{.Names}}\t{{.Status}}' | grep -q '^argus-web-proxy\s\+Created'; then
|
||||
echo "[WARN] web-proxy in Created state; retry starting it..."
|
||||
docker start argus-web-proxy || true
|
||||
fi
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021"
|
||||
|
||||
if [[ "$GPU_AVAILABLE" == true ]]; then
|
||||
echo "[OK] Services started: master:${MASTER_PORT:-32300} es:${ES_HTTP_PORT:-9200} kibana:${KIBANA_PORT:-5601} node-a:${NODE_A_PORT:-2020} node-b:${NODE_B_PORT:-2021} test-gpu-node:172.31.0.51"
|
||||
else
|
||||
echo "[OK] Services started: master:${MASTER_PORT:-32300} es:${ES_HTTP_PORT:-9200} kibana:${KIBANA_PORT:-5601} node-a:${NODE_A_PORT:-2020} node-b:${NODE_B_PORT:-2021} (gpu skipped)"
|
||||
fi
|
||||
|
||||
@@ -27,25 +27,34 @@ wait_http() {
|
||||
|
||||
echo "[INFO] Waiting for ES/Kibana/Master/Fluent Bit/Bind..."
|
||||
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
# ES (>= yellow)
|
||||
attempt=1; max=120
|
||||
ES_T0=$(date +%s)
|
||||
while (( attempt <= max )); do
|
||||
if curl -fsS "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=1s" >/dev/null 2>&1; then
|
||||
if curl -fsS "http://localhost:${ES_HTTP_PORT:-9200}/_cluster/health?wait_for_status=yellow&timeout=1s" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
echo "[..] waiting ES ($attempt/$max)"; sleep 5; ((attempt++))
|
||||
done
|
||||
[[ $attempt -le $max ]] || { echo "[ERR] ES not ready" >&2; exit 1; }
|
||||
ES_T1=$(date +%s); echo "[TIME] ES ready in $((ES_T1-ES_T0))s"
|
||||
|
||||
# Kibana: must be HTTP 200 and overall.level=available
|
||||
echo "[INFO] Waiting for Kibana to be available (HTTP 200)..."
|
||||
kb_attempt=1; kb_max=180
|
||||
KB_T0=$(date +%s)
|
||||
while (( kb_attempt <= kb_max )); do
|
||||
body=$(curl -sS "http://localhost:5601/api/status" 2>/dev/null || true)
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:5601/api/status" || echo 000)
|
||||
body=$(curl -sS "http://localhost:${KIBANA_PORT:-5601}/api/status" 2>/dev/null || true)
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${KIBANA_PORT:-5601}/api/status" || echo 000)
|
||||
if [[ "$code" == "200" ]]; then
|
||||
if echo "$body" | grep -q '"level":"available"'; then
|
||||
echo "[OK] Kibana available (HTTP 200)"
|
||||
KB_T1=$(date +%s)
|
||||
echo "[OK] Kibana available (HTTP 200) in $((KB_T1-KB_T0))s"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
@@ -58,11 +67,13 @@ if (( kb_attempt > kb_max )); then
|
||||
fi
|
||||
|
||||
# Master
|
||||
wait_http "http://localhost:32300/readyz" 120
|
||||
MASTER_T0=$(date +%s)
|
||||
wait_http "http://localhost:${MASTER_PORT:-32300}/readyz" 120
|
||||
MASTER_T1=$(date +%s); echo "[TIME] Master readyz in $((MASTER_T1-MASTER_T0))s"
|
||||
|
||||
# Fluent Bit (host metrics on host ports)
|
||||
wait_http "http://localhost:2020/api/v2/metrics" 120
|
||||
wait_http "http://localhost:2021/api/v2/metrics" 120
|
||||
FB1_T0=$(date +%s); wait_http "http://localhost:${NODE_A_PORT:-2020}/api/v2/metrics" 120; FB1_T1=$(date +%s); echo "[TIME] FluentBit:${NODE_A_PORT:-2020} in $((FB1_T1-FB1_T0))s"
|
||||
FB2_T0=$(date +%s); wait_http "http://localhost:${NODE_B_PORT:-2021}/api/v2/metrics" 120; FB2_T1=$(date +%s); echo "[TIME] FluentBit:${NODE_B_PORT:-2021} in $((FB2_T1-FB2_T0))s"
|
||||
|
||||
# Bind config check
|
||||
BIND_ID="$(service_id bind)"
|
||||
@@ -72,4 +83,63 @@ else
|
||||
echo "[WARN] bind container id not found"
|
||||
fi
|
||||
|
||||
# ========== Additional module readiness checks ==========
|
||||
|
||||
# Prometheus
|
||||
PROM_T0=$(date +%s); wait_http "http://localhost:${PROMETHEUS_PORT:-9090}/-/ready" 120; PROM_T1=$(date +%s); echo "[TIME] Prometheus ready in $((PROM_T1-PROM_T0))s"
|
||||
|
||||
# Grafana health (database: ok)
|
||||
echo "[INFO] Waiting for Grafana health..."
|
||||
gf_attempt=1; gf_max=120
|
||||
while (( gf_attempt <= gf_max )); do
|
||||
gf_body=$(curl -sS "http://localhost:${GRAFANA_PORT:-3000}/api/health" 2>/dev/null || true)
|
||||
gf_code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${GRAFANA_PORT:-3000}/api/health" || echo 000)
|
||||
if [[ "$gf_code" == "200" ]] && echo "$gf_body" | grep -q '"database"\s*:\s*"ok"'; then
|
||||
echo "[OK] Grafana health database=ok"
|
||||
break
|
||||
fi
|
||||
echo "[..] waiting grafana health ($gf_attempt/$gf_max), last_code=$gf_code"
|
||||
sleep 3; ((gf_attempt++))
|
||||
done
|
||||
if (( gf_attempt > gf_max )); then
|
||||
echo "[ERR] Grafana /api/health not ready" >&2; exit 1
|
||||
fi
|
||||
|
||||
# Alertmanager
|
||||
wait_http "http://localhost:${ALERTMANAGER_PORT:-9093}/api/v2/status" 120
|
||||
|
||||
# Web proxy checks(按端口细化)
|
||||
code_for() { curl -s -o /dev/null -w "%{http_code}" "$1" || echo 000; }
|
||||
header_val() { curl -s -D - -o /dev/null "$@" | awk -F': ' 'BEGIN{IGNORECASE=1}$1=="Access-Control-Allow-Origin"{gsub("\r","",$2);print $2}'; }
|
||||
|
||||
echo "[INFO] Checking web-proxy ports..."
|
||||
|
||||
# 8080 首页必须 200
|
||||
tries=1; max=60; P8080_T0=$(date +%s)
|
||||
while (( tries <= max )); do
|
||||
c=$(code_for "http://localhost:${WEB_PROXY_PORT_8080:-8080}/")
|
||||
if [[ "$c" == "200" ]]; then P8080_T1=$(date +%s); echo "[OK] 8080 / ($c) in $((P8080_T1-P8080_T0))s"; break; fi
|
||||
echo "[..] waiting 8080/ ($tries/$max), code=$c"; sleep 3; ((tries++))
|
||||
done
|
||||
(( tries <= max )) || { echo "[ERR] 8080/ not ready" >&2; exit 1; }
|
||||
|
||||
# 8083 Kibana 允许 200/302(上面已就绪,端口侧再快速确认)
|
||||
tries=1; max=40; P8083_T0=$(date +%s)
|
||||
while (( tries <= max )); do
|
||||
c=$(code_for "http://localhost:${WEB_PROXY_PORT_8083:-8083}/")
|
||||
if [[ "$c" == "200" || "$c" == "302" ]]; then P8083_T1=$(date +%s); echo "[OK] 8083 / ($c) in $((P8083_T1-P8083_T0))s"; break; fi
|
||||
echo "[..] waiting 8083/ ($tries/$max), code=$c"; sleep 3; ((tries++))
|
||||
done
|
||||
(( tries <= max )) || { echo "[ERR] 8083/ not ready" >&2; exit 1; }
|
||||
|
||||
# 8084 Alertmanager + CORS
|
||||
P8084_T0=$(date +%s); wait_http "http://localhost:${WEB_PROXY_PORT_8084:-8084}/api/v2/status" 60; P8084_T1=$(date +%s)
|
||||
cors=$(header_val -H "Origin: http://localhost:${WEB_PROXY_PORT_8080:-8080}" "http://localhost:${WEB_PROXY_PORT_8084:-8084}/api/v2/status" || true)
|
||||
if [[ -z "$cors" ]]; then echo "[ERR] 8084 CORS missing" >&2; exit 1; else echo "[OK] 8084 CORS: $cors in $((P8084_T1-P8084_T0))s"; fi
|
||||
|
||||
# 8085 Master /readyz + CORS(API 走 8085 才需跨域)
|
||||
P8085_T0=$(date +%s); wait_http "http://localhost:${WEB_PROXY_PORT_8085:-8085}/readyz" 60; P8085_T1=$(date +%s)
|
||||
cors=$(header_val -H "Origin: http://localhost:${WEB_PROXY_PORT_8080:-8080}" "http://localhost:${WEB_PROXY_PORT_8085:-8085}/api/v1/master/nodes" || true)
|
||||
if [[ -z "$cors" ]]; then echo "[ERR] 8085 CORS missing" >&2; exit 1; else echo "[OK] 8085 CORS: $cors in $((P8085_T1-P8085_T0))s"; fi
|
||||
|
||||
echo "[OK] All services are ready"
|
||||
|
||||
@@ -4,20 +4,15 @@ set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
compose() {
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
docker compose "$@"
|
||||
else
|
||||
docker-compose "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
service_id() {
|
||||
compose -p argus-sys ps -q "$1"
|
||||
# 直接根据 container_name 获取容器ID,避免 compose project 名称不一致导致查找失败
|
||||
cid_by_name() {
|
||||
docker ps -aqf "name=^$1$"
|
||||
}
|
||||
|
||||
echo "[INFO] Verifying DNS routing via bind..."
|
||||
|
||||
pushd "$TEST_ROOT" >/dev/null
|
||||
|
||||
# Check master IP file exists in shared private
|
||||
MASTER_FILE="$TEST_ROOT/private/argus/etc/master.argus.com"
|
||||
if [[ ! -f "$MASTER_FILE" ]]; then
|
||||
@@ -28,7 +23,7 @@ MASTER_IP_HOST="$(cat "$MASTER_FILE" | tr -d '\r\n' || true)"
|
||||
echo "[INFO] master.argus.com file content: ${MASTER_IP_HOST}"
|
||||
|
||||
# dig inside bind container
|
||||
BIN_ID="$(service_id bind)"
|
||||
BIN_ID="$(cid_by_name argus-bind-sys)"
|
||||
if [[ -n "$BIN_ID" ]]; then
|
||||
DIG_IP="$(docker exec "$BIN_ID" dig +short master.argus.com A | tail -n1 || true)"
|
||||
echo "[INFO] dig(master.argus.com) from bind container -> $DIG_IP"
|
||||
@@ -39,8 +34,27 @@ else
|
||||
echo "[WARN] bind container not found; skip dig"
|
||||
fi
|
||||
|
||||
for node in node-a node-b; do
|
||||
CID="$(service_id "$node")"
|
||||
check_inside() {
|
||||
local cname="$1"; shift
|
||||
local domains=("$@")
|
||||
CID="$(cid_by_name "$cname")"
|
||||
if [[ -z "$CID" ]]; then
|
||||
echo "[WARN] container $cname not found; skip"
|
||||
return 0
|
||||
fi
|
||||
for d in "${domains[@]}"; do
|
||||
echo "[INFO] Checking resolution inside $cname for $d..."
|
||||
if ! docker exec "$CID" getent hosts "$d" >/dev/null 2>&1; then
|
||||
echo "[ERR] $cname cannot resolve $d" >&2
|
||||
return 1
|
||||
fi
|
||||
RES="$(docker exec "$CID" getent hosts "$d" | awk '{print $1}' | head -n1)"
|
||||
echo "[OK] $cname resolved $d -> $RES"
|
||||
done
|
||||
}
|
||||
|
||||
for node in argus-node-a argus-node-b; do
|
||||
CID="$(cid_by_name "$node")"
|
||||
echo "[INFO] Checking resolution inside $node..."
|
||||
if ! docker exec "$CID" getent hosts master.argus.com >/dev/null 2>&1; then
|
||||
echo "[ERR] $node cannot resolve master.argus.com" >&2
|
||||
@@ -50,5 +64,10 @@ for node in node-a node-b; do
|
||||
echo "[OK] $node resolved master.argus.com -> $RES"
|
||||
done
|
||||
|
||||
echo "[OK] DNS routing verified"
|
||||
popd >/dev/null
|
||||
|
||||
# 追加:在 metric 节点中验证 master 与 prom 域名解析
|
||||
check_inside argus-metric-test-node master.argus.com prom.metric.argus.com || exit 1
|
||||
check_inside argus-metric-test-gpu-node master.argus.com prom.metric.argus.com || exit 1
|
||||
|
||||
echo "[OK] DNS routing verified"
|
||||
|
||||
@@ -5,7 +5,12 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
TMP_DIR="$TEST_ROOT/tmp"
|
||||
|
||||
API_BASE="http://localhost:32300/api/v1/master"
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
API_BASE="http://localhost:${MASTER_PORT:-32300}/api/v1/master"
|
||||
|
||||
HOST_A="dev-yyrshare-nbnyx10-cp2f-pod-0"
|
||||
HOST_B="dev-yyrshare-uuuu10-ep2f-pod-0"
|
||||
@@ -49,8 +54,35 @@ for _ in {1..60}; do
|
||||
fi
|
||||
done
|
||||
|
||||
# 若仍未全部注册,尝试重启 node-b 并再等待一轮(兼容 DNS/启动时序抖动)
|
||||
if [[ ! -s "$TMP_DIR/node_id_a" || ! -s "$TMP_DIR/node_id_b" ]]; then
|
||||
echo "[ERR] Agents did not register in time" >&2
|
||||
echo "[WARN] node-a or node-b not registered in first window; restarting node-b and retrying..." >&2
|
||||
# 仅重启 node-b,避免影响 es/kibana/master
|
||||
if docker ps --format '{{.Names}}' | grep -q '^argus-node-b$'; then
|
||||
docker restart argus-node-b >/dev/null 2>&1 || true
|
||||
fi
|
||||
# 再等待一轮(最多 120 秒)
|
||||
> "$TMP_DIR/node_id_b"
|
||||
for _ in {1..60}; do
|
||||
sleep 2
|
||||
resp=$(curl -fsS "$API_BASE/nodes" 2>/dev/null || true)
|
||||
[[ -z "$resp" ]] && continue
|
||||
if ! echo "$resp" | head -c1 | grep -q '\['; then
|
||||
continue
|
||||
fi
|
||||
echo "$resp" > "$TMP_DIR/nodes_list.json"
|
||||
ID_A=$(extract_node "$HOST_A" "$TMP_DIR/node_id_a" "$TMP_DIR/nodes_list.json" 2>/dev/null || true)
|
||||
ID_B=$(extract_node "$HOST_B" "$TMP_DIR/node_id_b" "$TMP_DIR/nodes_list.json" 2>/dev/null || true)
|
||||
if [[ -s "$TMP_DIR/node_id_a" && -s "$TMP_DIR/node_id_b" ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ! -s "$TMP_DIR/node_id_a" || ! -s "$TMP_DIR/node_id_b" ]]; then
|
||||
echo "[ERR] Agents did not register in time (after retry)" >&2
|
||||
echo "[HINT] Current /nodes response:" >&2
|
||||
sed -n '1,200p' "$TMP_DIR/nodes_list.json" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -5,7 +5,12 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
TMP_DIR="$TEST_ROOT/tmp"
|
||||
|
||||
API_BASE="http://localhost:32300/api/v1/master"
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
API_BASE="http://localhost:${MASTER_PORT:-32300}/api/v1/master"
|
||||
|
||||
HOST_A="dev-yyrshare-nbnyx10-cp2f-pod-0"
|
||||
HOST_B="dev-yyrshare-uuuu10-ep2f-pod-0"
|
||||
|
||||
@@ -3,9 +3,25 @@ set -euo pipefail
|
||||
|
||||
echo "[INFO] Sending logs via node-a/node-b and asserting ES counts..."
|
||||
|
||||
# 载入端口变量
|
||||
TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
# Robust count helper: tolerates 404/503 and non-JSON responses, returns integer >=0
|
||||
get_count() {
|
||||
local idx="$1"
|
||||
curl -s "http://localhost:9200/${idx}/_count?ignore_unavailable=true&allow_no_indices=true" | sed -E 's/.*"count":([0-9]+).*/\1/' | awk 'NF{print $0;exit} END{if(NR==0)print 0}'
|
||||
local idx="$1"; local tmp; tmp=$(mktemp)
|
||||
local code
|
||||
code=$(curl -s -o "$tmp" -w "%{http_code}" "http://localhost:${ES_HTTP_PORT:-9200}/${idx}/_count?ignore_unavailable=true&allow_no_indices=true" || true)
|
||||
if [[ "$code" == "200" ]]; then
|
||||
local val
|
||||
val=$(jq -r '(.count // 0) | tonumber? // 0' "$tmp" 2>/dev/null || echo 0)
|
||||
echo "$val"
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
}
|
||||
|
||||
train0=$(get_count "train-*")
|
||||
@@ -32,11 +48,26 @@ send_logs "$node_a" "host01"
|
||||
send_logs "$node_b" "host02"
|
||||
|
||||
echo "[INFO] Waiting for ES to ingest..."
|
||||
sleep 10
|
||||
# Proactively refresh indices (ignore errors if not created yet)
|
||||
curl -s -X POST "http://localhost:${ES_HTTP_PORT:-9200}/train-*/_refresh" >/dev/null 2>&1 || true
|
||||
curl -s -X POST "http://localhost:${ES_HTTP_PORT:-9200}/infer-*/_refresh" >/dev/null 2>&1 || true
|
||||
|
||||
train1=$(get_count "train-*")
|
||||
infer1=$(get_count "infer-*")
|
||||
final=$((train1 + infer1))
|
||||
# Retry up to 120s for counts to increase and reach threshold (>=4)
|
||||
final=0
|
||||
threshold=4
|
||||
for attempt in {1..60}; do
|
||||
train1=$(get_count "train-*")
|
||||
infer1=$(get_count "infer-*")
|
||||
final=$((train1 + infer1))
|
||||
if (( final > base && final >= threshold )); then
|
||||
break
|
||||
fi
|
||||
echo "[..] waiting ES counts increase to >=${threshold} ($attempt/60) current=${final} base=${base}"
|
||||
# refresh indices again to speed up visibility
|
||||
curl -s -X POST "http://localhost:${ES_HTTP_PORT:-9200}/train-*/_refresh" >/dev/null 2>&1 || true
|
||||
curl -s -X POST "http://localhost:${ES_HTTP_PORT:-9200}/infer-*/_refresh" >/dev/null 2>&1 || true
|
||||
sleep 2
|
||||
done
|
||||
echo "[INFO] final counts: train=${train1} infer=${infer1} total=${final}"
|
||||
|
||||
if (( final <= base )); then
|
||||
@@ -44,19 +75,20 @@ if (( final <= base )); then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Minimal threshold to be tolerant: expect at least 4 documents (2 train + 1 infer per node)
|
||||
if (( final < 4 )); then
|
||||
echo "[ERR] ES total below expected threshold: ${final} < 4" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Health endpoints
|
||||
es_health=$(curl -s "http://localhost:9200/_cluster/health" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
|
||||
es_health=$(curl -s "http://localhost:${ES_HTTP_PORT:-9200}/_cluster/health" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
|
||||
if [[ "$es_health" != "green" && "$es_health" != "yellow" ]]; then
|
||||
echo "[ERR] ES health not green/yellow: $es_health" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! curl -fs "http://localhost:5601/api/status" >/dev/null 2>&1; then
|
||||
if ! curl -fs "http://localhost:${KIBANA_PORT:-5601}/api/status" >/dev/null 2>&1; then
|
||||
echo "[WARN] Kibana status endpoint not available"
|
||||
fi
|
||||
|
||||
|
||||
@@ -6,7 +6,12 @@ TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
TMP_DIR="$TEST_ROOT/tmp"
|
||||
REPO_ROOT="$(cd "$TEST_ROOT/../../.." && pwd)"
|
||||
|
||||
API_BASE="http://localhost:32300/api/v1/master"
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
API_BASE="http://localhost:${MASTER_PORT:-32300}/api/v1/master"
|
||||
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a
|
||||
@@ -49,7 +54,7 @@ compose() {
|
||||
fi
|
||||
}
|
||||
|
||||
echo "[INFO] Recreating node-b with static IP 172.29.0.200..."
|
||||
echo "[INFO] Recreating node-b with static IP 172.31.0.200..."
|
||||
pushd "$TEST_ROOT" >/dev/null
|
||||
compose -p argus-sys rm -sf node-b || true
|
||||
popd >/dev/null
|
||||
@@ -58,19 +63,34 @@ docker rm -f argus-node-b >/dev/null 2>&1 || true
|
||||
|
||||
AGENT_BIN_PATH="$(cat "$TMP_DIR/agent_binary_path")"
|
||||
|
||||
# 选择 compose 管理的网络名(默认 argus-sys_sysnet)。
|
||||
detect_sysnet() {
|
||||
if docker network inspect argus-sys_sysnet >/dev/null 2>&1; then
|
||||
echo argus-sys_sysnet; return
|
||||
fi
|
||||
# 回退:从 master 容器推断所连网络(取第一个)
|
||||
local n
|
||||
n=$(docker inspect -f '{{range $k, $_ := .NetworkSettings.Networks}}{{println $k}}{{end}}' argus-master-sys 2>/dev/null | head -n1 || true)
|
||||
if [[ -n "$n" ]]; then echo "$n"; return; fi
|
||||
# 最后兜底:尝试项目默认网络(不保证有 IPAM)
|
||||
echo argus-sys_default
|
||||
}
|
||||
SYSNET_NAME=$(detect_sysnet)
|
||||
echo "[INFO] Using docker network: $SYSNET_NAME"
|
||||
|
||||
docker run -d \
|
||||
--name argus-node-b \
|
||||
--hostname dev-yyrshare-uuuu10-ep2f-pod-0 \
|
||||
--network argus-sys-net \
|
||||
--ip 172.29.0.200 \
|
||||
--dns 172.29.0.2 \
|
||||
--network "$SYSNET_NAME" \
|
||||
--ip 172.31.0.200 \
|
||||
--dns 172.31.0.2 \
|
||||
-e MASTER_ENDPOINT=http://master.argus.com:3000 \
|
||||
-e REPORT_INTERVAL_SECONDS=2 \
|
||||
-e ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133} \
|
||||
-e ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015} \
|
||||
-e ES_HOST=es \
|
||||
-e ES_PORT=9200 \
|
||||
-p 2021:2020 \
|
||||
-p ${NODE_B_PORT:-2021}:2020 \
|
||||
-v "$TEST_ROOT/private-nodeb/argus/agent/dev-yyrshare-uuuu10-ep2f-pod-0:/private/argus/agent/dev-yyrshare-uuuu10-ep2f-pod-0" \
|
||||
-v "$AGENT_BIN_PATH:/usr/local/bin/argus-agent:ro" \
|
||||
-v "$SCRIPT_DIR/node_entrypoint.sh:/usr/local/bin/node-entrypoint.sh:ro" \
|
||||
@@ -90,15 +110,15 @@ node=json.load(open(sys.argv[1]))
|
||||
last0=sys.argv[2]
|
||||
ip=node.get("meta_data",{}).get("ip")
|
||||
lu=node.get("last_updated")
|
||||
assert ip=="172.29.0.200"
|
||||
assert ip=="172.31.0.200"
|
||||
assert lu and lu!=last0
|
||||
PY
|
||||
then
|
||||
echo "[OK] node-b re-registered with new IP 172.29.0.200"
|
||||
echo "[OK] node-b re-registered with new IP 172.31.0.200"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[ERR] node-b did not update to IP 172.29.0.200 in time" >&2
|
||||
echo "[ERR] node-b did not update to IP 172.31.0.200 in time" >&2
|
||||
exit 1
|
||||
|
||||
@@ -12,12 +12,33 @@ compose() {
|
||||
fi
|
||||
}
|
||||
|
||||
docker rm -f argus-node-b >/dev/null 2>&1 || true
|
||||
|
||||
pushd "$TEST_ROOT" >/dev/null
|
||||
compose -p argus-sys down --remove-orphans || true
|
||||
compose down --remove-orphans || true
|
||||
popd >/dev/null
|
||||
|
||||
echo "[INFO] Force removing containers by name (if any)..."
|
||||
containers=(
|
||||
argus-node-a
|
||||
argus-node-b
|
||||
argus-metric-test-node
|
||||
argus-grafana
|
||||
argus-kibana-sys
|
||||
argus-master-sys
|
||||
argus-bind-sys
|
||||
argus-ftp
|
||||
argus-es-sys
|
||||
argus-prometheus
|
||||
)
|
||||
for c in "${containers[@]}"; do
|
||||
id=$(docker ps -aqf "name=^${c}$" || true)
|
||||
if [[ -n "$id" ]]; then
|
||||
docker rm -f "$id" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[INFO] Removing compose networks (handled by compose down)"
|
||||
|
||||
echo "[INFO] Cleaning private directories..."
|
||||
if [[ -d "$TEST_ROOT/private" ]]; then
|
||||
docker run --rm -v "$TEST_ROOT/private:/target" ubuntu:24.04 chown -R "$(id -u):$(id -g)" /target >/dev/null 2>&1 || true
|
||||
|
||||
89
src/sys/tests/scripts/10_metric_publish.sh
Executable file
89
src/sys/tests/scripts/10_metric_publish.sh
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
REPO_ROOT="$(cd "$TEST_ROOT/../../.." && pwd)"
|
||||
|
||||
PLUGIN_DIR="$REPO_ROOT/src/metric/client-plugins/all-in-one-full"
|
||||
FTP_CONTAINER="argus-ftp"
|
||||
|
||||
if [[ ! -d "$PLUGIN_DIR" ]]; then
|
||||
echo "[SYS-METRIC] Metric client plugin directory not found: $PLUGIN_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$TEST_ROOT/.env"
|
||||
fi
|
||||
|
||||
OWNER="${ARGUS_BUILD_UID:-2133}:${ARGUS_BUILD_GID:-2015}"
|
||||
|
||||
resolve_output_dir() {
|
||||
local host_mount
|
||||
if docker ps --format '{{.Names}}' | grep -q "^${FTP_CONTAINER}$"; then
|
||||
host_mount=$(docker inspect "$FTP_CONTAINER" --format '{{range .Mounts}}{{if eq .Destination "/private/argus/ftp"}}{{.Source}}{{end}}{{end}}' 2>/dev/null || true)
|
||||
if [[ -n "$host_mount" ]]; then
|
||||
echo "$host_mount/share"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
echo "$TEST_ROOT/private/argus/metric/ftp/share"
|
||||
}
|
||||
|
||||
OUTPUT_DIR="$(resolve_output_dir)"
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
if [[ ! -w "$OUTPUT_DIR" ]]; then
|
||||
echo "[SYS-METRIC] 无法写入 FTP 输出目录: $OUTPUT_DIR" >&2
|
||||
echo " 请确认目录权限与 ARGUS_BUILD_UID/GID 一致" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pushd "$PLUGIN_DIR" >/dev/null
|
||||
|
||||
# --- Inject agent binary built in 01_bootstrap (if present) ---
|
||||
AGENT_PATH_FILE="$TEST_ROOT/tmp/agent_binary_path"
|
||||
AGENT_BIN_CANDIDATE="$REPO_ROOT/src/agent/dist/argus-agent"
|
||||
if [[ -f "$AGENT_PATH_FILE" ]]; then
|
||||
AGENT_BIN="$(tr -d '\n' < "$AGENT_PATH_FILE")"
|
||||
else
|
||||
AGENT_BIN="$AGENT_BIN_CANDIDATE"
|
||||
fi
|
||||
|
||||
if [[ -x "$AGENT_BIN" ]]; then
|
||||
echo "[SYS-METRIC] 使用 01 阶段构建的 agent: $AGENT_BIN"
|
||||
TARGET_BIN="plugins/argus-agent/bin/argus-agent"
|
||||
if [[ -f "$TARGET_BIN" ]]; then
|
||||
cp -f "$AGENT_BIN" "$TARGET_BIN"
|
||||
else
|
||||
mkdir -p "$(dirname "$TARGET_BIN")"
|
||||
cp "$AGENT_BIN" "$TARGET_BIN"
|
||||
fi
|
||||
chmod +x "$TARGET_BIN"
|
||||
else
|
||||
echo "[SYS-METRIC] 未找到可执行的 agent 二进制(预期: $AGENT_BIN),继续使用插件目录内置版本"
|
||||
fi
|
||||
|
||||
echo "[SYS-METRIC] Bumping metric artifact version..."
|
||||
bash scripts/version-manager.sh bump minor
|
||||
|
||||
VERSION_FILE="config/VERSION"
|
||||
if [[ ! -f "$VERSION_FILE" ]]; then
|
||||
echo "[SYS-METRIC] VERSION 文件缺失: $VERSION_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION=$(tr -d '\n' < "$VERSION_FILE")
|
||||
echo "[SYS-METRIC] 当前版本: $VERSION"
|
||||
|
||||
echo "[SYS-METRIC] Packaging metric artifact..."
|
||||
bash scripts/package_artifact.sh --force
|
||||
|
||||
echo "[SYS-METRIC] Publishing artifact to FTP share..."
|
||||
bash scripts/publish_artifact.sh "$VERSION" --output-dir "$OUTPUT_DIR" --owner "$OWNER"
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
echo "[SYS-METRIC] Metric artifact published to $OUTPUT_DIR"
|
||||
50
src/sys/tests/scripts/11_metric_node_install.sh
Executable file
50
src/sys/tests/scripts/11_metric_node_install.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$TEST_ROOT/.env"
|
||||
fi
|
||||
|
||||
CONTAINER="argus-metric-test-node"
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
||||
echo "[SYS-METRIC] 容器 ${CONTAINER} 未运行,无法执行安装" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FTP_HOST="${FTP_SERVER:-172.31.0.40}"
|
||||
FTP_USER="${FTP_USER:-ftpuser}"
|
||||
FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}"
|
||||
FTP_PORT="${FTP_PORT:-21}"
|
||||
|
||||
echo "[SYS-METRIC] 在 ${CONTAINER} 内执行安装 (FTP: ${FTP_HOST}:${FTP_PORT})"
|
||||
|
||||
docker exec \
|
||||
-e FTP_HOST="$FTP_HOST" \
|
||||
-e FTP_USER="$FTP_USER" \
|
||||
-e FTP_PASSWORD="$FTP_PASSWORD" \
|
||||
-e FTP_PORT="$FTP_PORT" \
|
||||
"$CONTAINER" bash -c '
|
||||
set -e
|
||||
|
||||
if ! command -v curl &>/dev/null; then
|
||||
echo "[SYS-METRIC] curl 未安装,开始安装依赖..."
|
||||
apt-get update >/dev/null && apt-get install -y curl >/dev/null
|
||||
fi
|
||||
|
||||
cd /tmp
|
||||
echo "[SYS-METRIC] 下载 setup.sh..."
|
||||
curl -u "${FTP_USER}:${FTP_PASSWORD}" "ftp://${FTP_HOST}:${FTP_PORT}/setup.sh" -o setup.sh
|
||||
|
||||
echo "[SYS-METRIC] 执行安装..."
|
||||
chmod +x setup.sh
|
||||
bash setup.sh --server "${FTP_HOST}" --user "${FTP_USER}" --password "${FTP_PASSWORD}" --port "${FTP_PORT}"
|
||||
|
||||
echo "[SYS-METRIC] 安装完成"
|
||||
'
|
||||
|
||||
echo "[SYS-METRIC] Metric test node 安装流程完成"
|
||||
82
src/sys/tests/scripts/12_metric_gpu_install.sh
Executable file
82
src/sys/tests/scripts/12_metric_gpu_install.sh
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
ENABLE_GPU=${ARGUS_SYS_ENABLE_GPU:-false}
|
||||
|
||||
if [[ "$ENABLE_GPU" != "true" ]]; then
|
||||
echo "[SYS-METRIC] 未启用 GPU 流程,跳过 GPU 节点安装"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$TEST_ROOT/.env"
|
||||
fi
|
||||
|
||||
CONTAINER="argus-metric-test-gpu-node"
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
||||
echo "[SYS-METRIC] 预期启动的 ${CONTAINER} 未运行" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FTP_HOST="${FTP_SERVER:-172.31.0.40}"
|
||||
FTP_USER="${FTP_USER:-ftpuser}"
|
||||
FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}"
|
||||
FTP_PORT="${FTP_PORT:-21}"
|
||||
|
||||
echo "[SYS-METRIC] 在 GPU 节点执行安装 (FTP: ${FTP_HOST}:${FTP_PORT})"
|
||||
|
||||
docker exec \
|
||||
-e FTP_HOST="$FTP_HOST" \
|
||||
-e FTP_USER="$FTP_USER" \
|
||||
-e FTP_PASSWORD="$FTP_PASSWORD" \
|
||||
-e FTP_PORT="$FTP_PORT" \
|
||||
"$CONTAINER" bash -c '
|
||||
set -e
|
||||
|
||||
if ! command -v nvidia-smi &>/dev/null; then
|
||||
echo "[SYS-METRIC] GPU 节点缺少 nvidia-smi" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nvidia-smi >/dev/null || true
|
||||
|
||||
if ! command -v curl &>/dev/null; then
|
||||
echo "[SYS-METRIC] curl 未安装,开始安装依赖..."
|
||||
apt-get update >/dev/null && apt-get install -y curl >/dev/null
|
||||
fi
|
||||
|
||||
cd /tmp
|
||||
echo "[SYS-METRIC] 下载 setup.sh..."
|
||||
curl -u "${FTP_USER}:${FTP_PASSWORD}" "ftp://${FTP_HOST}:${FTP_PORT}/setup.sh" -o setup.sh
|
||||
|
||||
echo "[SYS-METRIC] 执行安装..."
|
||||
chmod +x setup.sh
|
||||
bash setup.sh --server "${FTP_HOST}" --user "${FTP_USER}" --password "${FTP_PASSWORD}" --port "${FTP_PORT}"
|
||||
|
||||
echo "[SYS-METRIC] GPU 节点安装完成"
|
||||
'
|
||||
|
||||
echo "[SYS-METRIC] Metric GPU 节点安装流程完成"
|
||||
|
||||
# 就绪性检测:9400(dcgm) 与 9100(node) 端口
|
||||
echo "[SYS-METRIC] 等待 dcgm-exporter(9400) 与 node-exporter(9100) 就绪..."
|
||||
retries=30
|
||||
until docker exec "$CONTAINER" bash -lc "curl -fsS --max-time 2 http://localhost:9400/metrics >/dev/null"; do
|
||||
((retries--)) || { echo "[ERR] dcgm-exporter 9400 未就绪" >&2; exit 1; }
|
||||
sleep 2
|
||||
done
|
||||
echo "[OK] dcgm-exporter 端点可访问"
|
||||
|
||||
retries=30
|
||||
until docker exec "$CONTAINER" bash -lc "curl -fsS --max-time 2 http://localhost:9100/metrics >/dev/null"; do
|
||||
((retries--)) || { echo "[ERR] node-exporter 9100 未就绪" >&2; exit 1; }
|
||||
sleep 2
|
||||
done
|
||||
echo "[OK] node-exporter 端点可访问"
|
||||
|
||||
mkdir -p "$TEST_ROOT/tmp" && touch "$TEST_ROOT/tmp/gpu_install_ready"
|
||||
40
src/sys/tests/scripts/13_metric_verify.sh
Executable file
40
src/sys/tests/scripts/13_metric_verify.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
echo "[SYS-METRIC] Verify: master"
|
||||
"$SCRIPT_DIR/13_metric_verify_master.sh"
|
||||
echo
|
||||
|
||||
echo "[SYS-METRIC] Verify: prometheus"
|
||||
PROM_RETRIES=${PROM_VERIFY_RETRIES:-2}
|
||||
PROM_BACKOFF=${PROM_VERIFY_BACKOFF_SECONDS:-30}
|
||||
attempt=0
|
||||
while true; do
|
||||
if "$SCRIPT_DIR/13_metric_verify_prometheus.sh"; then
|
||||
break
|
||||
fi
|
||||
attempt=$((attempt+1))
|
||||
if (( attempt > PROM_RETRIES )); then
|
||||
echo "[ERR] prometheus verify failed after $PROM_RETRIES retries" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[WARN] prometheus verify failed; retry $attempt/$PROM_RETRIES after ${PROM_BACKOFF}s"
|
||||
sleep "$PROM_BACKOFF"
|
||||
done
|
||||
echo
|
||||
|
||||
echo "[SYS-METRIC] Verify: dataplane"
|
||||
"$SCRIPT_DIR/13_metric_verify_dataplane.sh"
|
||||
echo
|
||||
|
||||
echo "[SYS-METRIC] Verify: grafana"
|
||||
"$SCRIPT_DIR/13_metric_verify_grafana.sh"
|
||||
echo
|
||||
|
||||
echo "[SYS-METRIC] Verify: grafana panels"
|
||||
"$SCRIPT_DIR/13_metric_verify_grafana_panels.sh"
|
||||
echo
|
||||
|
||||
echo "[SYS-METRIC] Metric verification completed"
|
||||
66
src/sys/tests/scripts/13_metric_verify_dataplane.sh
Executable file
66
src/sys/tests/scripts/13_metric_verify_dataplane.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TMP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)/tmp/metric-verify"
|
||||
mkdir -p "$TMP_DIR"
|
||||
|
||||
# 载入端口变量(由 .env 提供)
|
||||
TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
PROM_BASE="http://localhost:${PROMETHEUS_PORT:-9090}/api/v1"
|
||||
INSTANCE="${METRIC_TEST_INSTANCE:-172.31.0.50:9100}"
|
||||
IP_ONLY="${INSTANCE%%:*}"
|
||||
|
||||
echo "[VERIFY:DATA] node exporter metrics present in container"
|
||||
docker exec argus-metric-test-node bash -lc "curl -fsS --max-time 5 http://localhost:9100/metrics | head -n 5" > "$TMP_DIR/node_metrics_head.txt" || { echo "[ERR] cannot fetch node exporter metrics" >&2; exit 1; }
|
||||
if ! grep -E "node_(exporter_build_info|time_seconds)" -q "$TMP_DIR/node_metrics_head.txt"; then
|
||||
echo "[WARN] head did not show expected lines; continuing (exporter may output later lines)"
|
||||
fi
|
||||
echo "[OK] node exporter endpoint reachable"
|
||||
|
||||
echo "[VERIFY:DATA] Prometheus has recent sample for build_info"
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=node_exporter_build_info{job=\"node\",ip=\"$IP_ONLY\"}" > "$TMP_DIR/prom_ne_build_info_1.json"
|
||||
|
||||
python3 - "$TMP_DIR/prom_ne_build_info_1.json" <<'PY'
|
||||
import json,sys,time
|
||||
j=json.load(open(sys.argv[1]))
|
||||
res=j.get('data',{}).get('result',[])
|
||||
assert res, 'no result for node_exporter_build_info'
|
||||
ts=float(res[0]['value'][0])
|
||||
now=time.time()
|
||||
assert now-ts<180, f"sample too old: now={now} ts={ts}"
|
||||
print(int(ts))
|
||||
PY
|
||||
T1=$?
|
||||
sleep 30
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=node_exporter_build_info{job=\"node\",ip=\"$IP_ONLY\"}" > "$TMP_DIR/prom_ne_build_info_2.json"
|
||||
|
||||
TS1=$(python3 - "$TMP_DIR/prom_ne_build_info_1.json" <<'PY'
|
||||
import json,sys
|
||||
print(float(json.load(open(sys.argv[1]))['data']['result'][0]['value'][0]))
|
||||
PY
|
||||
)
|
||||
TS2=$(python3 - "$TMP_DIR/prom_ne_build_info_2.json" <<'PY'
|
||||
import json,sys
|
||||
print(float(json.load(open(sys.argv[1]))['data']['result'][0]['value'][0]))
|
||||
PY
|
||||
)
|
||||
awk -v a="$TS1" -v b="$TS2" 'BEGIN{ if (b>=a) exit 0; else exit 1 }' || { echo "[ERR] sample timestamp did not advance" >&2; exit 1; }
|
||||
echo "[OK] sample timestamp advanced"
|
||||
echo "[DONE] dataplane verify"
|
||||
|
||||
# 追加:GPU 节点端点连通性检查(启用 GPU 时)
|
||||
if [[ "${ENABLE_GPU:-false}" == "true" ]]; then
|
||||
echo
|
||||
echo "[VERIFY:DATA][GPU] curl endpoints on gpu node"
|
||||
if ! docker exec argus-metric-test-gpu-node bash -lc 'curl -fsS --max-time 5 http://localhost:9100/metrics >/dev/null'; then
|
||||
echo "[ERR] gpu node 9100 not reachable" >&2; exit 1
|
||||
fi
|
||||
if ! docker exec argus-metric-test-gpu-node bash -lc 'curl -fsS --max-time 5 http://localhost:9400/metrics >/dev/null'; then
|
||||
echo "[ERR] gpu node 9400 not reachable" >&2; exit 1
|
||||
fi
|
||||
echo "[OK] gpu node endpoints reachable"
|
||||
fi
|
||||
44
src/sys/tests/scripts/13_metric_verify_grafana.sh
Executable file
44
src/sys/tests/scripts/13_metric_verify_grafana.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
PROM_DOMAIN="prom.metric.argus.com:${PROMETHEUS_PORT:-9090}"
|
||||
GRAF="http://localhost:${GRAFANA_PORT:-3000}"
|
||||
|
||||
echo "[VERIFY:GRAFANA] /api/health"
|
||||
TMP_FILE="$(cd "$(dirname "$0")"/.. && pwd)/tmp/metric-verify/graf_health.json"
|
||||
mkdir -p "$(dirname "$TMP_FILE")"
|
||||
curl -fsS --max-time 10 "$GRAF/api/health" -o "$TMP_FILE" || { echo "[ERR] failed to GET /api/health" >&2; exit 1; }
|
||||
python3 - "$TMP_FILE" <<'PY'
|
||||
import sys,json
|
||||
with open(sys.argv[1],'r',encoding='utf-8') as f:
|
||||
j=json.load(f)
|
||||
assert j.get('database')=='ok', f"health not ok: {j}"
|
||||
print('OK')
|
||||
PY
|
||||
|
||||
echo "[VERIFY:GRAFANA] datasource URL uses domain: $PROM_DOMAIN"
|
||||
DS_FILE="/private/argus/metric/grafana/provisioning/datasources/datasources.yml"
|
||||
if ! docker exec argus-grafana sh -lc "test -f $DS_FILE"; then
|
||||
DS_FILE="/etc/grafana/provisioning/datasources/datasources.yml"
|
||||
fi
|
||||
docker exec argus-grafana sh -lc "grep -E 'url:\s*http://$PROM_DOMAIN' '$DS_FILE'" >/dev/null 2>&1 || { echo "[ERR] datasource not pointing to $PROM_DOMAIN" >&2; exit 1; }
|
||||
echo "[OK] datasource points to domain"
|
||||
|
||||
echo "[VERIFY:GRAFANA] bind resolution inside grafana"
|
||||
tries=0
|
||||
until docker exec argus-grafana getent hosts prom.metric.argus.com >/dev/null 2>&1; do
|
||||
tries=$((tries+1))
|
||||
if (( tries > 24 )); then
|
||||
echo "[ERR] grafana cannot resolve prom.metric.argus.com" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[..] waiting DNS propagation in grafana ($tries/24)"; sleep 5
|
||||
done
|
||||
echo "[OK] domain resolves"
|
||||
|
||||
echo "[DONE] grafana verify"
|
||||
87
src/sys/tests/scripts/13_metric_verify_grafana_panels.sh
Executable file
87
src/sys/tests/scripts/13_metric_verify_grafana_panels.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
TMP_DIR="$TEST_ROOT/tmp/metric-verify"
|
||||
mkdir -p "$TMP_DIR"
|
||||
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
GRAF="http://localhost:${GRAFANA_PORT:-3000}"
|
||||
HOSTNAME="${METRIC_TEST_HOSTNAME:-test-metric-node-001}"
|
||||
|
||||
echo "[VERIFY:GRAF-PANELS] resolve Prometheus datasource UID via Grafana"
|
||||
DS_JSON="$TMP_DIR/graf_ds.json"
|
||||
curl -fsS --max-time 10 "$GRAF/api/datasources" >"$DS_JSON"
|
||||
DS_UID=$(python3 - "$DS_JSON" <<'PY'
|
||||
import json,sys
|
||||
arr=json.load(open(sys.argv[1]))
|
||||
for ds in arr:
|
||||
if (ds.get('type')=='prometheus'):
|
||||
print(ds.get('uid',''))
|
||||
break
|
||||
PY
|
||||
)
|
||||
if [[ -z "$DS_UID" ]]; then echo "[ERR] no prometheus datasource found in grafana" >&2; exit 1; fi
|
||||
echo "[OK] Prometheus DS UID=$DS_UID"
|
||||
|
||||
proxy_query() {
|
||||
local q="$1"; local out="$2"
|
||||
curl -fsS --max-time 10 --get "$GRAF/api/datasources/proxy/uid/$DS_UID/api/v1/query" \
|
||||
--data-urlencode "query=$q" >"$out"
|
||||
}
|
||||
|
||||
assert_vector_recent_nonempty() {
|
||||
local json="$1"; local max_age_sec="${2:-180}"
|
||||
python3 - <<'PY' "$json" "$max_age_sec"
|
||||
import json,sys,time
|
||||
doc=json.load(open(sys.argv[1]))
|
||||
if doc.get('status')!='success':
|
||||
raise SystemExit('prom status != success')
|
||||
res=doc.get('data',{}).get('result',[])
|
||||
assert res, 'empty result'
|
||||
ts=float(res[0]['value'][0])
|
||||
assert time.time()-ts < float(sys.argv[2]), f'timestamp too old: {ts}'
|
||||
print(int(ts))
|
||||
PY
|
||||
}
|
||||
|
||||
echo "[VERIFY:GRAF-PANELS] Dashboard: Node and GPU Metrics — System Load"
|
||||
Q_NODE_LOAD="node_load1{hostname=\"$HOSTNAME\"}"
|
||||
proxy_query "$Q_NODE_LOAD" "$TMP_DIR/graf_panel_node_load.json"
|
||||
assert_vector_recent_nonempty "$TMP_DIR/graf_panel_node_load.json" 300 >/dev/null
|
||||
echo "[OK] node_load1 has recent sample via Grafana proxy"
|
||||
|
||||
echo "[VERIFY:GRAF-PANELS] Dashboard: Cluster Dashboard — Node online count"
|
||||
Q_NODE_ONLINE='count(count by(hostname) (up{job="node"} == 1))'
|
||||
proxy_query "$Q_NODE_ONLINE" "$TMP_DIR/graf_panel_node_online.json"
|
||||
python3 - "$TMP_DIR/graf_panel_node_online.json" <<'PY'
|
||||
import json,sys
|
||||
doc=json.load(open(sys.argv[1]))
|
||||
assert doc.get('status')=='success', 'prom status not success'
|
||||
res=doc.get('data',{}).get('result',[])
|
||||
assert res, 'no series for node online count'
|
||||
val=float(res[0]['value'][1])
|
||||
assert val>=1, f'node online < 1: {val}'
|
||||
print('OK',val)
|
||||
PY
|
||||
echo "[OK] cluster node online count >= 1 via Grafana proxy"
|
||||
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
# 可选:GPU 面板查询(当启用 GPU 时)
|
||||
if [[ "${ENABLE_GPU:-false}" == "true" ]]; then
|
||||
echo "[VERIFY:GRAF-PANELS] GPU Panels — DCGM GPU UTIL"
|
||||
Q_GPU_UTIL='DCGM_FI_DEV_GPU_UTIL'
|
||||
proxy_query "$Q_GPU_UTIL" "$TMP_DIR/graf_panel_dcgm_util.json"
|
||||
assert_vector_recent_nonempty "$TMP_DIR/graf_panel_dcgm_util.json" 300 >/dev/null || { echo "[ERR] dcgm gpu util no recent sample via Grafana proxy" >&2; exit 1; }
|
||||
echo "[OK] dcgm gpu util has recent samples via Grafana proxy"
|
||||
fi
|
||||
|
||||
echo "[DONE] grafana panels verify"
|
||||
110
src/sys/tests/scripts/13_metric_verify_master.sh
Executable file
110
src/sys/tests/scripts/13_metric_verify_master.sh
Executable file
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
TMP_DIR="$TEST_ROOT/tmp/metric-verify"
|
||||
mkdir -p "$TMP_DIR"
|
||||
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
MASTER_BASE="http://localhost:${MASTER_PORT:-32300}/api/v1/master"
|
||||
HOSTNAME="${METRIC_TEST_HOSTNAME:-test-metric-node-001}"
|
||||
|
||||
curl_json() { curl -fsS --max-time 5 "$1"; }
|
||||
|
||||
echo "[VERIFY:MASTER] list nodes and locate target hostname=$HOSTNAME"
|
||||
ALL_NODES_JSON="$TMP_DIR/master_nodes.json"
|
||||
|
||||
# 重试等待节点出现在 /nodes 列表(最多 120s)
|
||||
NODE_ID=""
|
||||
for attempt in {1..24}; do
|
||||
curl_json "$MASTER_BASE/nodes" > "$ALL_NODES_JSON" || true
|
||||
NODE_ID=$(python3 - "$ALL_NODES_JSON" "$HOSTNAME" <<'PY'
|
||||
import json,sys
|
||||
try:
|
||||
nodes=json.load(open(sys.argv[1]))
|
||||
except Exception:
|
||||
nodes=[]
|
||||
name=sys.argv[2]
|
||||
for n in nodes:
|
||||
if n.get('name')==name:
|
||||
print(n.get('id',''))
|
||||
break
|
||||
PY
|
||||
)
|
||||
if [[ -n "$NODE_ID" ]]; then break; fi
|
||||
echo "[..] waiting node to appear in /nodes ($attempt/24)"; sleep 5
|
||||
done
|
||||
|
||||
if [[ -z "$NODE_ID" ]]; then
|
||||
echo "[ERR] master /nodes 中未找到 $HOSTNAME(等待超时)" >&2
|
||||
echo "[HINT] 当前 /nodes 列表如下:" >&2
|
||||
sed -n '1,160p' "$ALL_NODES_JSON" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
echo "[OK] node id=$NODE_ID"
|
||||
|
||||
echo "[VERIFY:MASTER] get node detail and assert fields"
|
||||
DETAIL1_JSON="$TMP_DIR/master_node_${NODE_ID}_detail_1.json"
|
||||
curl_json "$MASTER_BASE/nodes/$NODE_ID" > "$DETAIL1_JSON"
|
||||
|
||||
# 基础字段与健康项检查(不强制立即 online)
|
||||
python3 - "$DETAIL1_JSON" "$HOSTNAME" <<'PY'
|
||||
import json,sys,datetime
|
||||
j=json.load(open(sys.argv[1]))
|
||||
host=sys.argv[2]
|
||||
assert j.get('name')==host, f"name mismatch: {j.get('name')} != {host}"
|
||||
status=j.get('status')
|
||||
assert status in ('initialized','online','offline'), f"unexpected status: {status}"
|
||||
md=j.get('meta_data',{})
|
||||
assert md.get('hostname',j.get('name'))==host, 'meta_data.hostname mismatch'
|
||||
assert 'last_report' in j and j['last_report'], 'last_report missing'
|
||||
h=j.get('health',{})
|
||||
for key in ('metric-node-exporter','metric-fluent-bit','metric-argus-agent'):
|
||||
if key in h:
|
||||
assert h[key].get('status')=='healthy', f"{key} not healthy: {h[key]}"
|
||||
print('OK')
|
||||
PY
|
||||
|
||||
# 轮询等待 last_report 前进并最终转为 online(最多 90s),容忍短暂 5xx/网络错误
|
||||
attempt=0
|
||||
T_PRE=0
|
||||
until [[ $attempt -ge 18 ]]; do
|
||||
sleep 5
|
||||
DETAIL_CUR="$TMP_DIR/master_node_${NODE_ID}_detail_cur.json"
|
||||
if ! curl_json "$MASTER_BASE/nodes/$NODE_ID" > "$DETAIL_CUR" 2>/dev/null; then
|
||||
echo "[..] retrying node detail fetch ($attempt/18)"; ((attempt++)); continue
|
||||
fi
|
||||
read -r STATUS_CUR T_CUR < <(python3 - "$DETAIL_CUR" <<'PY'
|
||||
import json,sys,datetime
|
||||
j=json.load(open(sys.argv[1]))
|
||||
st=j.get('status','')
|
||||
ts=j.get('last_report','')
|
||||
if ts.endswith('Z'): ts=ts.replace('Z','+00:00')
|
||||
try:
|
||||
t=float(datetime.datetime.fromisoformat(ts).timestamp())
|
||||
except Exception:
|
||||
t=0.0
|
||||
print(st)
|
||||
print(t)
|
||||
PY
|
||||
)
|
||||
if awk -v a="$T_PRE" -v b="$T_CUR" 'BEGIN{exit !(b>a)}'; then
|
||||
T_PRE="$T_CUR"
|
||||
fi
|
||||
if [[ "$STATUS_CUR" == "online" ]]; then
|
||||
echo "[OK] status online and last_report progressed"
|
||||
break
|
||||
fi
|
||||
((attempt++))
|
||||
done
|
||||
if (( attempt >= 18 )) && [[ "$STATUS_CUR" != "online" ]]; then
|
||||
echo "[WARN] status did not reach online within timeout; continuing"
|
||||
fi
|
||||
|
||||
echo "$NODE_ID" > "$TMP_DIR/node_id_metric"
|
||||
echo "[DONE] master verify"
|
||||
198
src/sys/tests/scripts/13_metric_verify_prometheus.sh
Executable file
198
src/sys/tests/scripts/13_metric_verify_prometheus.sh
Executable file
@@ -0,0 +1,198 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
TMP_DIR="$TEST_ROOT/tmp/metric-verify"
|
||||
mkdir -p "$TMP_DIR"
|
||||
|
||||
# 载入端口变量
|
||||
if [[ -f "$TEST_ROOT/.env" ]]; then
|
||||
set -a; source "$TEST_ROOT/.env"; set +a
|
||||
fi
|
||||
|
||||
PROM_BASE="http://localhost:${PROMETHEUS_PORT:-9090}/api/v1"
|
||||
HOSTNAME="${METRIC_TEST_HOSTNAME:-${METRIC_TEST_HOSTNAME_CPU:-test-metric-node-001}}"
|
||||
|
||||
nodes_json="$TEST_ROOT/private/argus/metric/prometheus/nodes.json"
|
||||
targets_json="$TEST_ROOT/private/argus/metric/prometheus/targets/node_exporter.json"
|
||||
|
||||
echo "[VERIFY:PROM] nodes.json present and contains hostname=$HOSTNAME"
|
||||
[[ -f "$nodes_json" ]] || { echo "[ERR] $nodes_json missing" >&2; exit 1; }
|
||||
python3 - "$nodes_json" "$HOSTNAME" <<'PY'
|
||||
import json,sys
|
||||
arr=json.load(open(sys.argv[1]))
|
||||
host=sys.argv[2]
|
||||
assert any((i.get('hostname')==host) for i in arr), f"{host} not found in nodes.json"
|
||||
PY
|
||||
echo "[OK] nodes.json contains target"
|
||||
|
||||
echo "[VERIFY:PROM] file_sd targets exist for nodes.json entries"
|
||||
[[ -f "$targets_json" ]] || { echo "[ERR] $targets_json missing" >&2; exit 1; }
|
||||
python3 - "$nodes_json" "$targets_json" "$HOSTNAME" >"$TMP_DIR/prom_targets_ip_inst.txt" <<'PY'
|
||||
import json,sys
|
||||
nodes=json.load(open(sys.argv[1]))
|
||||
file_sd=json.load(open(sys.argv[2]))
|
||||
host=sys.argv[3]
|
||||
targets=set()
|
||||
for item in file_sd:
|
||||
for t in item.get('targets',[]): targets.add(t)
|
||||
# choose node matching hostname; fallback to first metric user node; otherwise first
|
||||
sel = None
|
||||
for n in nodes:
|
||||
if n.get('hostname') == host:
|
||||
sel = n
|
||||
break
|
||||
if not sel:
|
||||
for n in nodes:
|
||||
if n.get('user_id') == 'metric':
|
||||
sel = n
|
||||
break
|
||||
if not sel and nodes:
|
||||
sel = nodes[0]
|
||||
if not sel:
|
||||
raise SystemExit('nodes.json empty or no suitable node found')
|
||||
ip = sel['ip']
|
||||
inst = f"{ip}:9100"
|
||||
print(ip)
|
||||
print(inst)
|
||||
PY
|
||||
IP_FIRST=$(sed -n '1p' "$TMP_DIR/prom_targets_ip_inst.txt")
|
||||
INSTANCE=$(sed -n '2p' "$TMP_DIR/prom_targets_ip_inst.txt")
|
||||
echo "[INFO] expecting instance in file_sd: $INSTANCE"
|
||||
|
||||
# 尝试在 Prometheus 容器内主动刷新 targets(可选加速)
|
||||
if docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
|
||||
echo "[..] triggering update_targets inside argus-prometheus"
|
||||
docker exec argus-prometheus bash -lc \
|
||||
'python3 /usr/local/bin/update_targets.py --config /private/argus/metric/prometheus/nodes.json --targets-dir /private/argus/metric/prometheus/targets >/dev/null 2>&1 || true'
|
||||
fi
|
||||
|
||||
# 给 Prometheus 一次初始 scrape 周期
|
||||
sleep 10
|
||||
|
||||
# 若短暂未生成,进行重试(最多 180s),期间多次触发刷新
|
||||
retry=0
|
||||
until jq -r '.[].targets[]' "$targets_json" 2>/dev/null | grep -q "^${IP_FIRST}:9100$"; do
|
||||
if (( retry >= 36 )); then
|
||||
echo "[ERR] ${IP_FIRST}:9100 not present in file_sd after timeout" >&2
|
||||
echo "[HINT] current targets file content:" >&2
|
||||
sed -n '1,200p' "$targets_json" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
if (( retry % 3 == 0 )) && docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
|
||||
docker exec argus-prometheus bash -lc \
|
||||
'python3 /usr/local/bin/update_targets.py --config /private/argus/metric/prometheus/nodes.json --targets-dir /private/argus/metric/prometheus/targets >/dev/null 2>&1 || true'
|
||||
fi
|
||||
echo "[..] waiting file_sd refresh ($retry/36)"; sleep 5; ((retry++))
|
||||
done
|
||||
|
||||
# 改为以 PromQL up 指标作为健康依据,避免 targets 页面状态抖动
|
||||
echo "[VERIFY:PROM] up{job=\"node\",ip=\"$IP_FIRST\"} > 0"
|
||||
attempt=0
|
||||
until (( attempt >= 60 )); do
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=up{job=\"node\",ip=\"$IP_FIRST\"}" > "$TMP_DIR/prom_up_inst_active.json" || true
|
||||
if python3 - "$TMP_DIR/prom_up_inst_active.json" <<'PY'
|
||||
import json,sys
|
||||
try:
|
||||
j=json.load(open(sys.argv[1]))
|
||||
except Exception:
|
||||
raise SystemExit(1)
|
||||
res=j.get('data',{}).get('result',[])
|
||||
if res:
|
||||
try:
|
||||
val=float(res[0]['value'][1])
|
||||
if val>0: raise SystemExit(0)
|
||||
except Exception:
|
||||
pass
|
||||
raise SystemExit(1)
|
||||
PY
|
||||
then
|
||||
echo "[OK] up > 0 (control-plane scrape works)"; break
|
||||
fi
|
||||
if (( attempt % 6 == 0 )) && docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
|
||||
docker exec argus-prometheus bash -lc \
|
||||
'python3 /usr/local/bin/update_targets.py --config /private/argus/metric/prometheus/nodes.json --targets-dir /private/argus/metric/prometheus/targets >/dev/null 2>&1 || true'
|
||||
fi
|
||||
echo "[..] waiting up{job=\"node\",ip=\"$IP_FIRST\"} > 0 ($attempt/60)"; sleep 5; ((attempt++))
|
||||
done
|
||||
if (( attempt >= 60 )); then
|
||||
echo "[ERR] up{job=\"node\",ip=\"$IP_FIRST\"} did not become > 0" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[VERIFY:PROM] instant up query > 0"
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=up{job=\"node\",ip=\"$IP_FIRST\"}" > "$TMP_DIR/prom_up_inst.json"
|
||||
python3 - "$TMP_DIR/prom_up_inst.json" <<'PY'
|
||||
import json,sys
|
||||
j=json.load(open(sys.argv[1]))
|
||||
res=j.get('data',{}).get('result',[])
|
||||
assert res, 'empty result for up{job="node",instance=...}'
|
||||
val=float(res[0]['value'][1])
|
||||
assert val>0, f"up value not > 0: {val}"
|
||||
PY
|
||||
echo "[OK] up > 0"
|
||||
|
||||
echo "[VERIFY:PROM] count(up{job=\"node\"}==1) >= 1"
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=count(up{job=\"node\"}==1)" > "$TMP_DIR/prom_up_count.json"
|
||||
python3 - "$TMP_DIR/prom_up_count.json" <<'PY'
|
||||
import json,sys
|
||||
j=json.load(open(sys.argv[1]))
|
||||
res=j.get('data',{}).get('result',[])
|
||||
assert res, 'empty result for count(up{job="node"}==1)'
|
||||
val=float(res[0]['value'][1])
|
||||
assert val>=1, f"count < 1: {val}"
|
||||
PY
|
||||
echo "[OK] up count satisfied"
|
||||
echo "[DONE] prometheus verify"
|
||||
|
||||
# ========== GPU 验证(可选) ==========
|
||||
if [[ "${ENABLE_GPU:-false}" == "true" ]]; then
|
||||
echo
|
||||
echo "[VERIFY:PROM][GPU] dcgm targets & up metric"
|
||||
GPU_IP_PORT="${METRIC_TEST_DCGM_GPU:-172.31.0.51:9400}"
|
||||
GPU_IP="${GPU_IP_PORT%%:*}"
|
||||
|
||||
# 1) file_sd 目标存在(在 Prometheus 容器内生成的 targets 文件)
|
||||
TARGETS_FILE="$TEST_ROOT/private/argus/metric/prometheus/targets/dcgm_exporter.json"
|
||||
if [[ ! -f "$TARGETS_FILE" ]]; then
|
||||
echo "[ERR] $TARGETS_FILE missing" >&2; exit 1
|
||||
fi
|
||||
if ! jq -r '.[].targets[]' "$TARGETS_FILE" 2>/dev/null | grep -q "^${GPU_IP}:9400$"; then
|
||||
echo "[ERR] dcgm target not found for ${GPU_IP}:9400" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[OK] dcgm target present in file_sd"
|
||||
|
||||
# 2) up{job="dcgm", ip=GPU_IP} == 1
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=up{job=\"dcgm\",ip=\"$GPU_IP\"}==1" > "$TMP_DIR/prom_dcgm_up.json"
|
||||
python3 - "$TMP_DIR/prom_dcgm_up.json" <<'PY'
|
||||
import json,sys
|
||||
j=json.load(open(sys.argv[1]))
|
||||
res=j.get('data',{}).get('result',[])
|
||||
assert res, 'up==1 empty for dcgm'
|
||||
val=float(res[0]['value'][1])
|
||||
assert val==1.0, f'up not 1: {val}'
|
||||
print('OK')
|
||||
PY
|
||||
echo "[OK] up{job=dcgm,ip=$GPU_IP} == 1"
|
||||
|
||||
# 3) 至少一个 GPU 指标存在(优先 DCGM_FI_DEV_GPU_UTIL,若无则尝试 DCGM_FI_DEV_FB_USED)
|
||||
query_one() {
|
||||
local q="$1"; local out="$2"
|
||||
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=$q" > "$out"
|
||||
python3 - "$out" <<'PY'
|
||||
import json,sys
|
||||
j=json.load(open(sys.argv[1]))
|
||||
ok=(j.get('status')=='success' and len(j.get('data',{}).get('result',[]))>0)
|
||||
raise SystemExit(0 if ok else 1)
|
||||
PY
|
||||
}
|
||||
if query_one 'DCGM_FI_DEV_GPU_UTIL' "$TMP_DIR/prom_dcgm_util.json" || query_one 'DCGM_FI_DEV_FB_USED' "$TMP_DIR/prom_dcgm_fb.json"; then
|
||||
echo "[OK] dcgm metrics present"
|
||||
else
|
||||
echo "[ERR] no dcgm metrics found" >&2; exit 1
|
||||
fi
|
||||
|
||||
echo "[DONE] prometheus gpu verify"
|
||||
fi
|
||||
18
src/sys/tests/scripts/14_metric_cleanup.sh
Executable file
18
src/sys/tests/scripts/14_metric_cleanup.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
FTP_SHARE="$TEST_ROOT/private/argus/metric/ftp/share"
|
||||
|
||||
if [[ -d "$FTP_SHARE" ]]; then
|
||||
echo "[SYS-METRIC] 清理 FTP 发布产物..."
|
||||
rm -f "$FTP_SHARE"/argus-metric_*.tar.gz 2>/dev/null || true
|
||||
rm -f "$FTP_SHARE"/LATEST_VERSION 2>/dev/null || true
|
||||
rm -f "$FTP_SHARE"/dns.conf "$FTP_SHARE"/setup.sh 2>/dev/null || true
|
||||
else
|
||||
echo "[SYS-METRIC] FTP 目录不存在,跳过清理"
|
||||
fi
|
||||
|
||||
echo "[SYS-METRIC] Metric 清理完成"
|
||||
45
src/sys/tests/scripts/metric/test-node-entrypoint.sh
Executable file
45
src/sys/tests/scripts/metric/test-node-entrypoint.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||
ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||
AGENT_ROOT=${AGENT_ROOT:-/private/argus/agent}
|
||||
PREPARED_FLAG="/tmp/.metric_node_prepared"
|
||||
|
||||
export DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-noninteractive}
|
||||
|
||||
if [[ ! -f "$PREPARED_FLAG" ]]; then
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq \
|
||||
curl \
|
||||
net-tools \
|
||||
iproute2 \
|
||||
lsof \
|
||||
procps \
|
||||
ca-certificates \
|
||||
gnupg2 || {
|
||||
echo "[metric-node] Failed to install base packages" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdir -p "$(dirname "$PREPARED_FLAG")"
|
||||
touch "$PREPARED_FLAG"
|
||||
fi
|
||||
|
||||
if [[ -n "${TZ:-}" ]]; then
|
||||
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime 2>/dev/null || true
|
||||
echo "$TZ" > /etc/timezone 2>/dev/null || true
|
||||
fi
|
||||
|
||||
mkdir -p "$AGENT_ROOT"
|
||||
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" "$AGENT_ROOT" 2>/dev/null || true
|
||||
|
||||
if [[ "${METRIC_NODE_ROLE:-cpu}" == "gpu" ]]; then
|
||||
if ! command -v nvidia-smi >/dev/null 2>&1; then
|
||||
echo "[metric-node] nvidia-smi not available but GPU role requested" >&2
|
||||
exit 1
|
||||
fi
|
||||
nvidia-smi || true
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -46,7 +46,9 @@ fi
|
||||
# Start Fluent Bit in background (will block, so run via bash -lc &)
|
||||
if [[ -x /private/start-fluent-bit.sh ]]; then
|
||||
log "starting fluent-bit"
|
||||
bash -lc '/private/start-fluent-bit.sh' &
|
||||
sysctl -w fs.inotify.max_user_instances=512 >/dev/null 2>&1 || true
|
||||
sysctl -w fs.inotify.max_user_watches=524288 >/dev/null 2>&1 || true
|
||||
bash -lc 'ulimit -n 65536 || true; exec /private/start-fluent-bit.sh' &
|
||||
else
|
||||
log "missing /private/start-fluent-bit.sh; fluent-bit will not start"
|
||||
fi
|
||||
@@ -54,4 +56,3 @@ fi
|
||||
# Start agent in foreground as runtime user
|
||||
log "starting argus-agent"
|
||||
exec su -s /bin/bash -c /usr/local/bin/argus-agent "$RUNTIME_USER"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user