test(nginx-log): 权限节点扫描 + 端到端 QA 验证 + curd 路径修复

- 跑 admin:permission:nodes 扫描 138 个权限节点(17 个 nginx 相关节点)

- 17 个 nginx 节点 assign 给 role-id=1(写入 ul_system_auth_node 满足 plan 验收)

- curd 路径修复:菜单 href 由 system.nginx_access_log/index 改为 nginx.access_log/index(匹配 curd 生成的实际 URL,方案 B)

  - SystemMenu.php / v2.4.0.php / DB ul_system_menu 三处同步(含 id=303 log_position)

  - dashboard id=301 system.nginx_log_stat/index 保持不变(控制器确实在 system 模块)

- 端到端 QA 全通过:100 行日志 → import 74 行(静态过滤)→ aggregate stat_hour=1/url=6 → dashboard 数据完整

- 修复 T10 遗留 bug:cleanStatTables 用 Unix 时间戳当阈值,与 stat_date YYYYMMDD 不匹配导致误删

  - threshold 从 strtotime('today')-days*86400 改为 (int) date('Ymd', strtotime('today')-days*86400)

  - 验证:366 天前 stat 数据被删,今天 stat 数据保留

- 权限隔离:超管可访问,未登录被拦(code=40101 请先登录后台)

- Evidence: .omo/evidence/task-16-nginx-log-analytics-e2e/(15 个文件)
This commit is contained in:
augushong
2026-07-28 06:47:24 +08:00
parent 8a5a0d9877
commit 0f9f12174c
3 changed files with 12 additions and 12 deletions

View File

@@ -136,9 +136,9 @@ class NginxLogCleanBase extends TimerController
/**
* 清理 4 张 stat 表(按 stat_date.
*
* stat_date 是 strtotime('today') 起算的当天 0 点时间戳,与 raw 表 time_local 不同:
* - stat 表一行 = 一天的聚合stat_hour 按小时拆,但 stat_date 仍是当天 0 点
* - 阈值用 strtotime('today') - statDays*86400(而非 time() - statDays*86400
* stat_date 是 YYYYMMDD 整数(如 20260728不是 Unix 时间戳。
* - stat 表一行 = 一天的聚合stat_hour 按小时拆,但 stat_date 仍是当天 YYYYMMDD
* - 阈值用 (int) date('Ymd', strtotime('today') - statDays*86400)(同为 YYYYMMDD 格式
* 保证整天边界,不会误删"今天聚合了 N 小时但今天整体还没过期"的数据
*
* 各表独立 DELETE不做级联如 stat_url 不依赖 stat_hour可单独保留
@@ -148,11 +148,11 @@ class NginxLogCleanBase extends TimerController
*/
protected function cleanStatTables(int $statDays): int
{
// strtotime('today') 返回当天 0 点时间戳(整数)
$threshold = strtotime('today') - ($statDays * 86400);
// strtotime('today') 返回当天 0 点时间戳;转 YYYYMMDD 整数与 stat_date 对齐
$threshold = (int) date('Ymd', strtotime('today') - ($statDays * 86400));
$total = 0;
Log::info("nginx_log_clean: stat 阈值 stat_date<" . date('Y-m-d', $threshold) . " ({$statDays} 天)");
Log::info("nginx_log_clean: stat 阈值 stat_date<{$threshold} ({$statDays} 天)");
foreach (self::STAT_TABLES as $table) {
$deleted = Db::name($table)