Skip to content

Commit a1928f7

Browse files
committed
drop rendering times recording in favor of sentry performance tracing
1 parent 80a7894 commit a1928f7

File tree

4 files changed

+6
-112
lines changed

4 files changed

+6
-112
lines changed

src/metrics/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ metrics! {
8787
pub(crate) routes_visited: IntCounterVec["route"],
8888
/// The response times of various docs.rs routes
8989
pub(crate) response_time: HistogramVec["route"],
90-
/// The time it takes to render a rustdoc page
91-
pub(crate) rustdoc_rendering_times: HistogramVec["step"],
92-
/// The time it takes to render a rustdoc redirect page
93-
pub(crate) rustdoc_redirect_rendering_times: HistogramVec["step"],
9490

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

src/storage/mod.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ mod s3;
66
pub use self::compression::{compress, decompress, CompressionAlgorithm, CompressionAlgorithms};
77
use self::database::DatabaseBackend;
88
use self::s3::S3Backend;
9-
use crate::{
10-
db::Pool, error::Result, utils::spawn_blocking, web::metrics::RenderingTimesRecorder, Config,
11-
InstanceMetrics,
12-
};
9+
use crate::{db::Pool, error::Result, utils::spawn_blocking, Config, InstanceMetrics};
1310
use anyhow::{anyhow, ensure};
1411
use chrono::{DateTime, Utc};
1512
use fn_error_context::context;
@@ -175,16 +172,14 @@ impl AsyncStorage {
175172
/// * `path` - the wanted path inside the documentation.
176173
/// * `archive_storage` - if `true`, we will assume we have a remove ZIP archive and an index
177174
/// where we can fetch the requested path from inside the ZIP file.
178-
/// * `fetch_time` - used to collect metrics when using the storage inside web server handlers.
179-
#[instrument(skip(fetch_time))]
175+
#[instrument]
180176
pub(crate) async fn fetch_rustdoc_file(
181177
&self,
182178
name: &str,
183179
version: &str,
184180
latest_build_id: i32,
185181
path: &str,
186182
archive_storage: bool,
187-
fetch_time: Option<&mut RenderingTimesRecorder<'_>>,
188183
) -> Result<Blob> {
189184
trace!("fetch rustdoc file");
190185
Ok(if archive_storage {
@@ -193,13 +188,9 @@ impl AsyncStorage {
193188
latest_build_id,
194189
path,
195190
self.max_file_size_for(path),
196-
fetch_time,
197191
)
198192
.await?
199193
} else {
200-
if let Some(fetch_time) = fetch_time {
201-
fetch_time.step("fetch from storage");
202-
}
203194
// Add rustdoc prefix, name and version to the path for accessing the file stored in the database
204195
let remote_path = format!("rustdoc/{name}/{version}/{path}");
205196
self.get(&remote_path, self.max_file_size_for(path)).await?
@@ -221,7 +212,6 @@ impl AsyncStorage {
221212
latest_build_id,
222213
path,
223214
self.max_file_size_for(path),
224-
None,
225215
)
226216
.await?
227217
} else {
@@ -349,18 +339,14 @@ impl AsyncStorage {
349339
Ok(local_index_path)
350340
}
351341

352-
#[instrument(skip(fetch_time))]
342+
#[instrument]
353343
pub(crate) async fn get_from_archive(
354344
&self,
355345
archive_path: &str,
356346
latest_build_id: i32,
357347
path: &str,
358348
max_size: usize,
359-
mut fetch_time: Option<&mut RenderingTimesRecorder<'_>>,
360349
) -> Result<Blob> {
361-
if let Some(ref mut t) = fetch_time {
362-
t.step("find path in index");
363-
}
364350
let index_filename = self
365351
.download_archive_index(archive_path, latest_build_id)
366352
.await?;
@@ -371,9 +357,6 @@ impl AsyncStorage {
371357
}?
372358
.ok_or(PathNotFoundError)?;
373359

374-
if let Some(t) = fetch_time {
375-
t.step("range request");
376-
}
377360
let blob = self
378361
.get_range(
379362
archive_path,
@@ -640,15 +623,13 @@ impl Storage {
640623
latest_build_id: i32,
641624
path: &str,
642625
archive_storage: bool,
643-
fetch_time: Option<&mut RenderingTimesRecorder<'_>>,
644626
) -> Result<Blob> {
645627
self.runtime.block_on(self.inner.fetch_rustdoc_file(
646628
name,
647629
version,
648630
latest_build_id,
649631
path,
650632
archive_storage,
651-
fetch_time,
652633
))
653634
}
654635

@@ -730,14 +711,12 @@ impl Storage {
730711
latest_build_id: i32,
731712
path: &str,
732713
max_size: usize,
733-
fetch_time: Option<&mut RenderingTimesRecorder<'_>>,
734714
) -> Result<Blob> {
735715
self.runtime.block_on(self.inner.get_from_archive(
736716
archive_path,
737717
latest_build_id,
738718
path,
739719
max_size,
740-
fetch_time,
741720
))
742721
}
743722

@@ -1172,14 +1151,13 @@ mod backend_tests {
11721151
assert!(local_index_location.exists());
11731152
assert!(storage.exists_in_archive("folder/test.zip", 0, "src/main.rs",)?);
11741153

1175-
let file =
1176-
storage.get_from_archive("folder/test.zip", 0, "Cargo.toml", std::usize::MAX, None)?;
1154+
let file = storage.get_from_archive("folder/test.zip", 0, "Cargo.toml", std::usize::MAX)?;
11771155
assert_eq!(file.content, b"data");
11781156
assert_eq!(file.mime, "text/toml");
11791157
assert_eq!(file.path, "folder/test.zip/Cargo.toml");
11801158

11811159
let file =
1182-
storage.get_from_archive("folder/test.zip", 0, "src/main.rs", std::usize::MAX, None)?;
1160+
storage.get_from_archive("folder/test.zip", 0, "src/main.rs", std::usize::MAX)?;
11831161
assert_eq!(file.content, b"data");
11841162
assert_eq!(file.mime, "text/rust");
11851163
assert_eq!(file.path, "folder/test.zip/src/main.rs");

src/web/metrics.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use axum::{
99
middleware::Next,
1010
response::IntoResponse,
1111
};
12-
use prometheus::{proto::MetricFamily, Encoder, HistogramVec, TextEncoder};
12+
use prometheus::{proto::MetricFamily, Encoder, TextEncoder};
1313
use std::{borrow::Cow, sync::Arc, time::Instant};
14-
#[cfg(test)]
15-
use tracing::debug;
1614

1715
async fn fetch_and_render_metrics(
1816
fetch_metrics: impl Fn() -> Result<Vec<MetricFamily>> + Send + 'static,
@@ -112,53 +110,6 @@ pub(crate) async fn request_recorder(
112110
result
113111
}
114112

115-
struct RenderingTime {
116-
start: Instant,
117-
step: &'static str,
118-
}
119-
120-
pub(crate) struct RenderingTimesRecorder<'a> {
121-
metric: &'a HistogramVec,
122-
current: Option<RenderingTime>,
123-
}
124-
125-
impl<'a> RenderingTimesRecorder<'a> {
126-
pub(crate) fn new(metric: &'a HistogramVec) -> Self {
127-
Self {
128-
metric,
129-
current: None,
130-
}
131-
}
132-
133-
pub(crate) fn step(&mut self, step: &'static str) {
134-
self.record_current();
135-
self.current = Some(RenderingTime {
136-
start: Instant::now(),
137-
step,
138-
});
139-
}
140-
141-
fn record_current(&mut self) {
142-
if let Some(current) = self.current.take() {
143-
#[cfg(test)]
144-
debug!(
145-
"rendering time - {}: {:?}",
146-
current.step,
147-
current.start.elapsed()
148-
);
149-
self.metric
150-
.with_label_values(&[current.step])
151-
.observe(duration_to_seconds(current.start.elapsed()));
152-
}
153-
}
154-
}
155-
156-
impl Drop for RenderingTimesRecorder<'_> {
157-
fn drop(&mut self) {
158-
self.record_current();
159-
}
160-
}
161-
162113
#[cfg(test)]
163114
mod tests {
164115
use crate::test::wrapper;

src/web/rustdoc.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::{
1414
extractors::{DbConnection, Path},
1515
file::File,
1616
match_version,
17-
metrics::RenderingTimesRecorder,
1817
page::TemplateData,
1918
MetaData, ReqVersion,
2019
},
@@ -90,7 +89,6 @@ async fn try_serve_legacy_toolchain_asset(
9089
#[instrument(skip_all)]
9190
pub(crate) async fn rustdoc_redirector_handler(
9291
Path(params): Path<RustdocRedirectorParams>,
93-
Extension(metrics): Extension<Arc<InstanceMetrics>>,
9492
Extension(storage): Extension<Arc<AsyncStorage>>,
9593
Extension(config): Extension<Arc<Config>>,
9694
mut conn: DbConnection,
@@ -116,16 +114,13 @@ pub(crate) async fn rustdoc_redirector_handler(
116114
)?)
117115
}
118116

119-
let mut rendering_time = RenderingTimesRecorder::new(&metrics.rustdoc_redirect_rendering_times);
120-
121117
// global static assets for older builds are served from the root, which ends up
122118
// in this handler as `params.name`.
123119
if let Some((_, extension)) = params.name.rsplit_once('.') {
124120
if ["css", "js", "png", "svg", "woff", "woff2"]
125121
.binary_search(&extension)
126122
.is_ok()
127123
{
128-
rendering_time.step("serve static asset");
129124
return try_serve_legacy_toolchain_asset(storage, config, params.name)
130125
.instrument(info_span!("serve static asset"))
131126
.await;
@@ -162,7 +157,6 @@ pub(crate) async fn rustdoc_redirector_handler(
162157

163158
// it doesn't matter if the version that was given was exact or not, since we're redirecting
164159
// anyway
165-
rendering_time.step("match version");
166160
let matched_release = match_version(
167161
&mut conn,
168162
&crate_name,
@@ -177,21 +171,16 @@ pub(crate) async fn rustdoc_redirector_handler(
177171
if let Some(ref target) = params.target {
178172
if target.ends_with(".js") {
179173
// this URL is actually from a crate-internal path, serve it there instead
180-
rendering_time.step("serve JS for crate");
181-
182174
return async {
183175
let krate = CrateDetails::from_matched_release(&mut conn, matched_release).await?;
184176

185-
rendering_time.step("fetch from storage");
186-
187177
match storage
188178
.fetch_rustdoc_file(
189179
&crate_name,
190180
&krate.version.to_string(),
191181
krate.latest_build_id.unwrap_or(0),
192182
target,
193183
krate.archive_storage,
194-
Some(&mut rendering_time),
195184
)
196185
.await
197186
{
@@ -231,8 +220,6 @@ pub(crate) async fn rustdoc_redirector_handler(
231220
}
232221

233222
if matched_release.rustdoc_status() {
234-
rendering_time.step("redirect to doc");
235-
236223
let url_str = if let Some(target) = target {
237224
format!(
238225
"/{crate_name}/{}/{target}/{}/",
@@ -261,7 +248,6 @@ pub(crate) async fn rustdoc_redirector_handler(
261248
)?
262249
.into_response())
263250
} else {
264-
rendering_time.step("redirect to crate");
265251
Ok(axum_cached_redirect(
266252
format!("/crate/{crate_name}/{}", matched_release.req_version),
267253
CachePolicy::ForeverInCdn,
@@ -361,8 +347,6 @@ pub(crate) async fn rustdoc_html_server_handler(
361347
Extension(csp): Extension<Arc<Csp>>,
362348
uri: Uri,
363349
) -> AxumResult<AxumResponse> {
364-
let mut rendering_time = RenderingTimesRecorder::new(&metrics.rustdoc_rendering_times);
365-
366350
// since we directly use the Uri-path and not the extracted params from the router,
367351
// we have to percent-decode the string here.
368352
let original_path = percent_encoding::percent_decode(uri.path().as_bytes())
@@ -394,8 +378,6 @@ pub(crate) async fn rustdoc_html_server_handler(
394378
}
395379

396380
trace!("match version");
397-
rendering_time.step("match version");
398-
399381
let mut conn = pool.get_async().await?;
400382

401383
// Check the database for releases with the requested version while doing the following:
@@ -430,13 +412,10 @@ pub(crate) async fn rustdoc_html_server_handler(
430412
})?;
431413

432414
trace!("crate details");
433-
rendering_time.step("crate details");
434-
435415
// Get the crate's details from the database
436416
let krate = CrateDetails::from_matched_release(&mut conn, matched_release).await?;
437417

438418
if !krate.rustdoc_status {
439-
rendering_time.step("redirect to crate");
440419
return Ok(axum_cached_redirect(
441420
format!("/crate/{}/{}", params.name, params.version),
442421
CachePolicy::ForeverInCdn,
@@ -465,10 +444,6 @@ pub(crate) async fn rustdoc_html_server_handler(
465444

466445
trace!(?storage_path, ?req_path, "try fetching from storage");
467446

468-
// record the data-fetch step
469-
// until we re-add it below inside `fetch_rustdoc_file`
470-
rendering_time.step("fetch from storage");
471-
472447
// Attempt to load the file from the database
473448
let blob = match storage
474449
.fetch_rustdoc_file(
@@ -477,7 +452,6 @@ pub(crate) async fn rustdoc_html_server_handler(
477452
krate.latest_build_id.unwrap_or(0),
478453
&storage_path,
479454
krate.archive_storage,
480-
Some(&mut rendering_time),
481455
)
482456
.await
483457
{
@@ -541,16 +515,13 @@ pub(crate) async fn rustdoc_html_server_handler(
541515
// Serve non-html files directly
542516
if !storage_path.ends_with(".html") {
543517
trace!(?storage_path, "serve asset");
544-
rendering_time.step("serve asset");
545518

546519
// default asset caching behaviour is `Cache::ForeverInCdnAndBrowser`.
547520
// This is an edge-case when we serve invocation specific static assets under `/latest/`:
548521
// https://github.com/rust-lang/docs.rs/issues/1593
549522
return Ok(File(blob).into_response());
550523
}
551524

552-
rendering_time.step("find latest path");
553-
554525
let latest_release = krate.latest_release()?;
555526

556527
// Get the latest version of the crate
@@ -618,8 +589,6 @@ pub(crate) async fn rustdoc_html_server_handler(
618589
format!("{target}/")
619590
};
620591

621-
rendering_time.step("rewrite html");
622-
623592
// Build the page of documentation,
624593
templates
625594
.render_in_threadpool({

0 commit comments

Comments
 (0)