fix(ops): honor gitea pressure playbook paths
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled

This commit is contained in:
Your Name
2026-07-03 01:18:52 +08:00
parent 2a83ec01b8
commit 150306acc0
2 changed files with 72 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ from typing import Any
DEFAULT_HOST_METRICS_FILE = Path("/home/wooo/node_exporter_textfiles/host_runaway_process.prom")
DEFAULT_DOCKER_STATS_FILE = Path("/home/wooo/node_exporter_textfiles/docker_stats.prom")
DEFAULT_DOCKER_STATS_MAX_AGE_SECONDS = 300
DEFAULT_SCRIPT_DIR = Path("/home/wooo/scripts")
DEFAULT_GITEA_METRICS_URL = "http://192.168.0.110:3001/metrics"
DEFAULT_GITEA_HEALTH_URL = "http://192.168.0.110:3001/api/healthz"
DEFAULT_GITEA_VERSION_URL = "http://192.168.0.110:3001/api/v1/version"
@@ -42,6 +43,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--host", default="110")
parser.add_argument("--metrics-file", type=Path, default=DEFAULT_HOST_METRICS_FILE)
parser.add_argument("--docker-stats-file", type=Path, default=DEFAULT_DOCKER_STATS_FILE)
parser.add_argument("--script-dir", type=Path, default=DEFAULT_SCRIPT_DIR)
parser.add_argument(
"--docker-stats-max-age-seconds",
type=int,
@@ -459,17 +461,22 @@ def build_payload(args: argparse.Namespace) -> dict[str, Any]:
"gitea_family_cpu": args.gitea_family_cpu_threshold,
"hooktasks_warning": args.hooktasks_warning_threshold,
},
"metrics_file": str(args.metrics_file),
"docker_stats_file": str(args.docker_stats_file),
"script_dir": str(args.script_dir),
},
"commands": {
"check_mode": (
"/home/wooo/scripts/gitea-queue-hook-backlog-playbook.py "
f"--host {args.host} --metrics-file {DEFAULT_HOST_METRICS_FILE} "
f"--docker-stats-file {DEFAULT_DOCKER_STATS_FILE} --json"
f"{args.script_dir / 'gitea-queue-hook-backlog-playbook.py'} "
f"--host {args.host} --metrics-file {args.metrics_file} "
f"--docker-stats-file {args.docker_stats_file} "
f"--script-dir {args.script_dir} --json"
),
"post_apply_verifier": (
"/home/wooo/scripts/host-sustained-load-controller.py "
f"--host {args.host} --metrics-file {DEFAULT_HOST_METRICS_FILE} "
f"--docker-stats-file {DEFAULT_DOCKER_STATS_FILE} --json"
f"{args.script_dir / 'host-sustained-load-controller.py'} "
f"--host {args.host} --metrics-file {args.metrics_file} "
f"--docker-stats-file {args.docker_stats_file} "
f"--script-dir {args.script_dir} --json"
),
"controlled_apply": "",
"rollback": "no host mutation performed by this check-mode playbook",

View File

@@ -150,3 +150,62 @@ def test_gitea_playbook_rejects_stale_docker_attribution(tmp_path: Path) -> None
assert payload["readback"]["docker_stats"]["fresh"] is False
assert payload["readback"]["top_containers"] == []
assert payload["readback"]["top_containers_untrusted"][0]["container_name"] == "gitea"
def test_gitea_playbook_honors_custom_readback_paths(tmp_path: Path) -> None:
gitea_files = _write_common_gitea_files(tmp_path)
host_file = tmp_path / "host.prom"
host_file.write_text(
"\n".join(
[
'awoooi_host_gitea_actions_active_container_count{host="188"} 0',
'awoooi_host_gitea_actions_active_process_group_count{host="188"} 0',
'awoooi_host_gitea_actions_active_process_cpu_percent{host="188"} 0',
'awoooi_host_process_family_cpu_percent{host="188",family="gitea_service"} 0',
]
),
encoding="utf-8",
)
docker_file = tmp_path / "docker.prom"
docker_file.write_text(
'docker_container_cpu_cores{host="188",container_name="momo-scheduler"} 0.7\n',
encoding="utf-8",
)
script_dir = tmp_path / "deployed-scripts"
result = subprocess.run(
[
sys.executable,
str(PLAYBOOK_PATH),
"--host",
"188",
"--metrics-file",
str(host_file),
"--docker-stats-file",
str(docker_file),
"--script-dir",
str(script_dir),
"--gitea-metrics-file",
str(gitea_files["gitea_metrics"]),
"--gitea-health-file",
str(gitea_files["health"]),
"--gitea-version-file",
str(gitea_files["version"]),
"--json",
],
capture_output=True,
text=True,
)
assert result.returncode == 0
payload = json.loads(result.stdout)
assert payload["classification"] == "observing_gitea_pressure_below_threshold"
assert payload["readback"]["metrics_file"] == str(host_file)
assert payload["readback"]["docker_stats_file"] == str(docker_file)
assert payload["readback"]["script_dir"] == str(script_dir)
assert str(script_dir / "gitea-queue-hook-backlog-playbook.py") in payload["commands"]["check_mode"]
assert str(script_dir / "host-sustained-load-controller.py") in payload["commands"]["post_apply_verifier"]
assert str(host_file) in payload["commands"]["check_mode"]
assert str(docker_file) in payload["commands"]["post_apply_verifier"]
assert "/home/wooo/node_exporter_textfiles" not in payload["commands"]["check_mode"]
assert "/home/wooo/node_exporter_textfiles" not in payload["commands"]["post_apply_verifier"]