Skip to content

Commit c86cdea

Browse files
sypharJoshua Nelson
authored andcommitted
add rendering time metrics to rustdoc-redirector-handler
1 parent 7d987b3 commit c86cdea

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/metrics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ metrics! {
4747
pub(crate) response_time: HistogramVec["route"],
4848
/// The time it takes to render a rustdoc page
4949
pub(crate) rustdoc_rendering_times: HistogramVec["step"],
50+
/// The time it takes to render a rustdoc redirect page
51+
pub(crate) rustdoc_redirect_rendering_times: HistogramVec["step"],
5052

5153
/// Count of recently accessed crates
5254
pub(crate) recent_crates: IntGaugeVec["duration"],

src/web/rustdoc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
8787
Ok(resp)
8888
}
8989

90+
let metrics = extension!(req, Metrics).clone();
91+
let mut rendering_time = RenderingTimesRecorder::new(&metrics.rustdoc_redirect_rendering_times);
92+
9093
// this unwrap is safe because iron urls are always able to use `path_segments`
9194
// i'm using this instead of `req.url.path()` to avoid allocating the Vec, and also to avoid
9295
// keeping the borrow alive into the return statement
@@ -102,8 +105,10 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
102105
// redirecting to the crate root page
103106
if req.url.as_ref().path_segments().unwrap().count() > 2 {
104107
// this URL is actually from a crate-internal path, serve it there instead
108+
rendering_time.step("serve JS for crate");
105109
return rustdoc_html_server_handler(req);
106110
} else {
111+
rendering_time.step("serve JS");
107112
let storage = extension!(req, Storage);
108113
let config = extension!(req, Config);
109114

@@ -124,6 +129,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
124129
{
125130
// route .ico files into their dedicated handler so that docs.rs's favicon is always
126131
// displayed
132+
rendering_time.step("serve ICO");
127133
return super::statics::ico_handler(req);
128134
}
129135

@@ -141,6 +147,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
141147

142148
// it doesn't matter if the version that was given was exact or not, since we're redirecting
143149
// anyway
150+
rendering_time.step("match version");
144151
let v = match_version(&mut conn, &crate_name, req_version)?;
145152
if let Some(new_name) = v.corrected_name {
146153
// `match_version` checked against -/_ typos, so if we have a name here we should
@@ -151,6 +158,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
151158

152159
// get target name and whether it has docs
153160
// FIXME: This is a bit inefficient but allowing us to use less code in general
161+
rendering_time.step("fetch release doc status");
154162
let (target_name, has_docs): (String, bool) = {
155163
let rows = ctry!(
156164
req,
@@ -170,8 +178,10 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
170178
}
171179

172180
if has_docs {
181+
rendering_time.step("redirect to doc");
173182
redirect_to_doc(req, &crate_name, &version, target, &target_name)
174183
} else {
184+
rendering_time.step("redirect to crate");
175185
redirect_to_crate(req, &crate_name, &version)
176186
}
177187
}

0 commit comments

Comments
 (0)