Skip to content

feat(volo-http): add CommonStats and ServerStats struct to record lifecycle timings#649

Open
Joshuahoky wants to merge 7 commits intocloudwego:mainfrom
Joshuahoky:feat/http_stats
Open

feat(volo-http): add CommonStats and ServerStats struct to record lifecycle timings#649
Joshuahoky wants to merge 7 commits intocloudwego:mainfrom
Joshuahoky:feat/http_stats

Conversation

@Joshuahoky
Copy link
Copy Markdown
Collaborator

@Joshuahoky Joshuahoky commented Mar 23, 2026

Motivation

Volo-http currently lacks visibility into key HTTP lifecycle timings, such as:

  • Time to read request headers and body
  • Time spent handling the request
  • Time to write the response body

Solution

Added ServerStats in volo-http/src/context/server.rs to store timestamps for:

  • request header read start/finish
  • request body read start/finish
  • handler execution start/finish
  • response body write start/finish

Also instrumented the request handling flow to populate the ServerHandleStart / Finish fields of ServerStats

@Joshuahoky Joshuahoky requested review from a team as code owners March 23, 2026 05:44
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.85%. Comparing base (c971091) to head (7ca20c8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #649      +/-   ##
==========================================
+ Coverage   44.84%   44.85%   +0.01%     
==========================================
  Files         162      162              
  Lines       20078    20081       +3     
==========================================
+ Hits         9003     9007       +4     
+ Misses      11075    11074       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

shenyj3
shenyj3 previously approved these changes Mar 23, 2026
@Joshuahoky Joshuahoky changed the title feat(volo-http): add CommonStats struct feat(volo-http): add CommonStats and ServerStats struct to record lifecycle timings Mar 30, 2026
cx.rpc_info_mut().set_config(service.config);
let span = service.span_provider.on_serve(&cx);
let resp = service
cx.stats.record_handle_start();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里应该不是 handle start,更像是 recv end,http request 已经收完了。

service.inner.call() 只是会走到 service 里,但是不代表已经开始进入业务逻辑了,中间还有 middleware、route、param extract 等。

真正的 handler start 要到 volo-http/src/server/handler.rs#L77 这里了。

.instrument(span)
.await
.into_response();
cx.stats.record_handle_finish();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

同上,这里是 send start 而不是 handle finish。

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants