[#37] 增加sys/swarm_tests(cpu) ;单独构建的node bundle镜像
This commit is contained in:
98
deployment/build/build_images.sh
Executable file
98
deployment/build/build_images.sh
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
. "$ROOT_DIR/deployment/build/common.sh"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Build Argus images (optional node-bundle)
|
||||
|
||||
Usage: build_images.sh [--with-node-bundle] [--client-version YYYYMMDD] [--base-image NAME[:TAG]]
|
||||
|
||||
Examples:
|
||||
./deployment/build/build_images.sh --with-node-bundle --client-version 20251106
|
||||
EOF
|
||||
}
|
||||
|
||||
WITH_BUNDLE=false
|
||||
CLIENT_VERSION=""
|
||||
BASE_IMAGE="argus-sys-metric-test-node:latest"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--with-node-bundle) WITH_BUNDLE=true; shift;;
|
||||
--client-version) CLIENT_VERSION="$2"; shift 2;;
|
||||
--base-image) BASE_IMAGE="$2"; shift 2;;
|
||||
-h|--help) usage; exit 0;;
|
||||
*) err "unknown arg: $1"; usage; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$WITH_BUNDLE" == true ]]; then
|
||||
require_cmd docker tar gzip
|
||||
BUNDLE_DIR="$ROOT_DIR/src/sys/build/node-bundle"
|
||||
CTX_DIR="$BUNDLE_DIR"
|
||||
TMP_BUNDLE="$BUNDLE_DIR/bundle"
|
||||
rm -rf "$TMP_BUNDLE"; mkdir -p "$TMP_BUNDLE"
|
||||
|
||||
# Build or locate client artifact
|
||||
PLUGIN_DIR="$ROOT_DIR/src/metric/client-plugins/all-in-one-full"
|
||||
# CLIENT_VERSION 支持两种形式:
|
||||
# - 形如 1.42.0 的 artifact 版本(默认)
|
||||
# - 形如 YYYYMMDD 的打包日期,将从 deployment/artifact/client/ 下解析出内部 artifact 版本
|
||||
if [[ -z "$CLIENT_VERSION" ]]; then
|
||||
pushd "$PLUGIN_DIR" >/dev/null
|
||||
bash scripts/package_artifact.sh --force
|
||||
CLIENT_VERSION=$(cat artifact/*/version.json 2>/dev/null | sed -n 's/.*"version"\s*:\s*"\([^"]\+\)".*/\1/p' | tail -n1)
|
||||
popd >/dev/null
|
||||
[[ -n "$CLIENT_VERSION" ]] || { err "failed to detect client version"; exit 1; }
|
||||
else
|
||||
if [[ "$CLIENT_VERSION" =~ ^[0-9]{8}$ ]]; then
|
||||
PKG_DIR="$ROOT_DIR/deployment/artifact/client/$CLIENT_VERSION"
|
||||
TAR_PKG="$PKG_DIR/argus-metric_${CLIENT_VERSION}.tar.gz"
|
||||
[[ -f "$TAR_PKG" ]] || { err "client date package not found: $TAR_PKG"; exit 1; }
|
||||
# 解包读取内部 version.json
|
||||
tmpd=$(mktemp -d); trap 'rm -rf "$tmpd"' EXIT
|
||||
tar -xzf "$TAR_PKG" -C "$tmpd"
|
||||
if [[ -f "$tmpd/version.json" ]]; then
|
||||
ART_VER=$(sed -n 's/.*"version"\s*:\s*"\([^"]\+\)".*/\1/p' "$tmpd/version.json" | head -n1)
|
||||
[[ -n "$ART_VER" ]] || { err "failed to parse artifact version from date package"; exit 1; }
|
||||
CLIENT_VERSION="$ART_VER"
|
||||
# 直接使用该 tar 作为 bundle 源
|
||||
cp "$TAR_PKG" "$TMP_BUNDLE/argus-metric_$(echo "$ART_VER" | tr '.' '_').tar.gz"
|
||||
# 同时尝试复制 setup.sh(若存在)
|
||||
[[ -f "$PKG_DIR/setup.sh" ]] && cp "$PKG_DIR/setup.sh" "$TMP_BUNDLE/" || true
|
||||
else
|
||||
err "version.json missing in client date package"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# 假定为 artifact 版本目录
|
||||
pushd "$PLUGIN_DIR" >/dev/null
|
||||
[[ -d "artifact/$CLIENT_VERSION" ]] || bash scripts/package_artifact.sh --force
|
||||
popd >/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# 若未通过日期包预置 tar,则从插件 artifact 目录取
|
||||
TAR_NAME="argus-metric_$(echo "$CLIENT_VERSION" | tr '.' '_').tar.gz"
|
||||
if [[ ! -f "$TMP_BUNDLE/$TAR_NAME" ]]; then
|
||||
SRC_TAR="$PLUGIN_DIR/artifact/$CLIENT_VERSION/$TAR_NAME"
|
||||
[[ -f "$SRC_TAR" ]] || { err "missing client tar: $SRC_TAR"; exit 1; }
|
||||
cp "$SRC_TAR" "$TMP_BUNDLE/"
|
||||
# also include setup.sh for fallback
|
||||
if [[ -f "$ROOT_DIR/deployment/artifact/client/$(today_version)/setup.sh" ]]; then
|
||||
cp "$ROOT_DIR/deployment/artifact/client/$(today_version)/setup.sh" "$TMP_BUNDLE/" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
log "Building node-bundle image with client version: $CLIENT_VERSION"
|
||||
DOCKER_BUILDKIT=0 docker build \
|
||||
--build-arg CLIENT_VER="$CLIENT_VERSION" \
|
||||
--build-arg BASE_IMAGE="$BASE_IMAGE" \
|
||||
-t argus-sys-metric-test-node-bundle:latest \
|
||||
-f "$BUNDLE_DIR/Dockerfile" "$BUNDLE_DIR"
|
||||
log "Built image: argus-sys-metric-test-node-bundle:latest"
|
||||
fi
|
||||
|
||||
log "Done."
|
||||
103
deployment/build/templates/scripts/fix-prom-targets-overlay.sh
Normal file
103
deployment/build/templates/scripts/fix-prom-targets-overlay.sh
Normal file
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Quick fix tool: replace 172.22/16 targets in nodes.json with overlay IPs resolved from hostname.
|
||||
# Usage: run on server package host: scripts/fix-prom-targets-overlay.sh
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
NODES_JSON="$ROOT/private/argus/metric/prometheus/nodes.json"
|
||||
|
||||
require_cmd() { command -v "$1" >/dev/null 2>&1 || { echo "[ERROR] missing command: $1" >&2; exit 1; }; }
|
||||
|
||||
backup() {
|
||||
local src="$1"; local ts; ts=$(date -u +%Y%m%d-%H%M%SZ)
|
||||
cp "$src" "${src%.json}_bak_${ts}.json"
|
||||
}
|
||||
|
||||
prefer_overlay_ip() {
|
||||
local host="$1"
|
||||
# prefer 10.0/8 then 172.31/16
|
||||
getent hosts "$host" | awk '{print $1}' | while read -r ip; do
|
||||
if [[ "$ip" =~ ^10\. ]]; then echo "$ip"; return; fi
|
||||
done
|
||||
getent hosts "$host" | awk '{print $1}' | while read -r ip; do
|
||||
if [[ "$ip" =~ ^172\.31\. ]]; then echo "$ip"; return; fi
|
||||
done
|
||||
# fallback: first A record
|
||||
getent hosts "$host" | awk '{print $1; exit}'
|
||||
}
|
||||
|
||||
require_cmd awk
|
||||
require_cmd sed
|
||||
|
||||
if [[ ! -f "$NODES_JSON" ]]; then
|
||||
echo "[WARN] nodes.json not found: $NODES_JSON" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
backup "$NODES_JSON"
|
||||
|
||||
tmp=$(mktemp)
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
|
||||
changed=0
|
||||
python3 - "$NODES_JSON" <<'PY' > "$tmp" || {
|
||||
import ipaddress, json, sys, socket
|
||||
path=sys.argv[1]
|
||||
data=json.load(open(path)) if path else []
|
||||
def resolve(host):
|
||||
try:
|
||||
infos=socket.getaddrinfo(host,None,family=socket.AF_INET)
|
||||
ips=[i[4][0] for i in infos]
|
||||
# prefer 10. over 172.31.
|
||||
for ip in ips:
|
||||
if ip.startswith('10.'): return ip
|
||||
for ip in ips:
|
||||
if ip.startswith('172.31.'): return ip
|
||||
return ips[0] if ips else None
|
||||
except OSError:
|
||||
return None
|
||||
gw=ipaddress.ip_network('172.22.0.0/16')
|
||||
out=[]
|
||||
changed=False
|
||||
for item in data:
|
||||
ip=item.get('ip')
|
||||
host=item.get('hostname') or ''
|
||||
try:
|
||||
bad = ip and ipaddress.ip_address(ip) in gw
|
||||
except Exception:
|
||||
bad = False
|
||||
if bad and host:
|
||||
new=resolve(host)
|
||||
if new:
|
||||
item=dict(item)
|
||||
item['ip']=new
|
||||
changed=True
|
||||
out.append(item)
|
||||
json.dump(out, sys.stdout, ensure_ascii=False)
|
||||
sys.stderr.write('CHANGED' if changed else 'UNCHANGED')
|
||||
PY
|
||||
|
||||
status=$?
|
||||
marker=$(tail -n1 /dev/stderr 2>/dev/null || true)
|
||||
if [[ "$status" -ne 0 ]]; then
|
||||
echo "[ERROR] failed to rewrite nodes.json" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if grep -q '"ip"\s*:\s*"172\.22\.' "$tmp"; then
|
||||
echo "[WARN] some gwbridge targets remain; manual fix may be required" >&2
|
||||
fi
|
||||
|
||||
mv "$tmp" "$NODES_JSON"
|
||||
echo "[OK] nodes.json updated"
|
||||
|
||||
# try to reload Prometheus
|
||||
if docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
|
||||
docker exec argus-prometheus sh -lc 'pidof prometheus >/dev/null 2>&1 && kill -HUP $(pidof prometheus) || supervisorctl restart prometheus' >/dev/null 2>&1 || true
|
||||
echo "[INFO] Prometheus reloaded"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -155,6 +155,34 @@ gfcode=$(http_code "http://localhost:${GRAFANA_PORT:-3000}/api/health"); [[ "$gf
|
||||
# Deduplicate errors
|
||||
sort -u -o "$ERRORS" "$ERRORS"
|
||||
|
||||
# --- Prometheus targets & nodes.json checks ---
|
||||
section PROMETHEUS-TARGETS
|
||||
nodes_json_path="$ROOT/private/argus/metric/prometheus/nodes.json"
|
||||
if [[ -f "$nodes_json_path" ]]; then
|
||||
logd "nodes.json present: $nodes_json_path"
|
||||
# detect gwbridge addresses (172.22/16)
|
||||
if grep -E '"ip"\s*:\s*"172\.22\.' "$nodes_json_path" >/dev/null 2>&1; then
|
||||
append_err "[prometheus][targets] contains gwbridge (172.22/16) addresses; prefer overlay (10.0/8)."
|
||||
echo "HINT: nodes.json has 172.22.x.x targets. Ensure agent publishes overlay_ip and master prefers it." >&2
|
||||
fi
|
||||
else
|
||||
logd "nodes.json missing at $nodes_json_path"
|
||||
fi
|
||||
|
||||
# Query Prometheus activeTargets and list down items when possible
|
||||
pt_json=$(curl -s --max-time 3 "http://localhost:${PROMETHEUS_PORT:-9090}/api/v1/targets" || true)
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
downs=$(printf '%s' "$pt_json" | jq -r '.data.activeTargets[] | select(.health=="down") | "[prometheus][activeTargets] down url=\(.scrapeUrl) lastError=\(.lastError)"' 2>/dev/null || true)
|
||||
if [[ -n "$downs" ]]; then
|
||||
printf '%s\n' "$downs" >> "$ERRORS"
|
||||
fi
|
||||
else
|
||||
# best-effort grep when jq is unavailable
|
||||
if printf '%s' "$pt_json" | grep -q '"health":"down"'; then
|
||||
append_err "[prometheus][activeTargets] some targets are down (enable jq for detailed reasons)"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Diagnostic details -> $DETAILS"
|
||||
echo "Detected errors -> $ERRORS"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user