Skip to content

fix(serve): standardize access log format and trace empty-match - #129

Open
NO3623 wants to merge 1 commit into
c2j:mainfrom
NO3623:fix/serve-access-log-and-trace
Open

NO3623 wants to merge 1 commit into
c2j:mainfrom
NO3623:fix/serve-access-log-and-trace

Conversation

@NO3623

@NO3623 NO3623 commented Aug 3, 2026

Copy link
Copy Markdown

Fixes #125, fixes #126.

Changes

  • serve: HTTP 访问日志格式不标准 #126 — HTTP access log format: rewrite src/server/access_log.rs to emit the Apache Combined Log Format instead of the ad-hoc timestamp INFO "METHOD URI HTTP/1.1" status ms ip line.

    Before:

    2026-08-03 02:10:44 INFO  "GET /api/v1/trace?from=nonexistent_node HTTP/1.1" 404 0ms 127.0.0.1
    

    After:

    127.0.0.1 - - [03/Aug/2026:10:30:51 +0800] "GET /api/v1/trace?from=nonexistent_node HTTP/1.1" 200 - "-" "-" 0ms
    
    • IP first, CLF timestamp with timezone, real HTTP version, status, response bytes, Referer, User-Agent, latency (ms).
    • Replace hand-rolled date math (chrono_now() leap-year logic) with chrono::Local.
    • Add chrono as a serve-gated optional dependency.
  • serve: trace 端点空匹配返回 200 而非 404 #125 — trace empty-match: /api/v1/trace with no matching node now returns 200 with an empty result object instead of 404:

    {"target":null,"callers":[],"callees":[],"caller_count":0,"callee_count":0,"truncated":false}
  • Tests: add test_serve_trace_empty_returns_200 and test_serve_access_log_combined_format in tests/serve_api.rs.

Verification

  • cargo build (default) and cargo build --features full pass.
  • cargo test --features serve --test serve_api: 9/9 pass.
  • cargo fmt -- --check passes.
  • New code is clippy-clean; remaining cargo clippy --features full -- -D warnings errors are pre-existing in untouched files.

Pre-existing failures (unrelated, verified identical on base)

  • cargo clippy --features full -- -D warnings: 8 errors in untouched files (src/graph/builder.rs, src/graph/inspect.rs, src/graph/query/traversal.rs, src/mark.rs, src/parser/jsp_loader.rs, src/server/handlers.rs:613, src/main.rs).
  • cargo test --features full: import::parser::tests::test_path_mapping_applied fails on Windows (asserts forward-slash path /prefix/sql/a.sql).

Note: building on Windows GNU target requires dlltool on PATH (chrono's windows-link build script).

- c2j#126: write access logs in Apache Combined Log Format (IP first, CLF
  timestamp with timezone, real HTTP version, status, bytes, Referer,
  User-Agent, latency) using chrono instead of hand-rolled date math
- c2j#125: /api/v1/trace with no matching node returns 200 with an empty
  result object instead of 404
- add chrono as a serve-gated optional dependency
- add serve_api integration tests for both behaviors

Pre-existing, unrelated failures on this toolchain (verified identical
on the base commit):
- clippy --features full -- -D warnings: 8 errors in untouched files
- cargo test --features full: test_path_mapping_applied fails on Windows
  (forward-slash path assertion)

@c2j c2j left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #129 Review — fix(serve): standardize access log format and trace empty-match

总结:将 access log 改为 Apache Combined Log Format(新增 chrono 可选依赖),并包含 trace 空匹配改动(与 PR#127 重叠),新增集成测试验证行为。

需要作者处理:

  1. PR 与其它分支(例如 #127)存在重叠改动并显示 CONFLICTING。请解决冲突并去重(保留最终实现),并在 PR 描述说明与 #127 的关系;若两个 PR 意图合并为同一行为,建议合并为单一 PR。
  2. 依赖变更:新增 chrono(serve 可选依赖),请在 PR 描述或 CHANGELOG 补充说明,并在 CI 中验证 cargo build --features full 成功。
  3. middleware 使用 response.headers() 等 API 时,请确认没有引入 move/borrow 的错误(建议在 CI 做一次 serve 的端到端 smoke 测试)。
  4. 测试稳定性:access log 测试写入 .codeweb/http.log,测试前应清理或使用唯一路径,避免竞争或残留影响结果。
  5. 请确保本 PR 不引入新的 clippy/fmt 问题(运行 cargo fmt -- --check 与 cargo clippy --features serve -- -D warnings 并在 PR 中附上输出)。

结论建议:功能方向合理,待解决冲突、补充说明并保证 CI 干净后合并。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve: trace 端点空匹配返回 200 而非 404 serve: HTTP 访问日志格式不标准

2 participants