diff --git a/Cargo.lock b/Cargo.lock
index 5c3704fae..bcb141a53 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -376,7 +376,6 @@ dependencies = [
"handlebars-iron 0.25.2 (registry+https://github.com/rust-lang/crates.io-index)",
"iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kuchiki 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1816,6 +1815,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "once_cell"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
[[package]]
name = "oorandom"
diff --git a/Cargo.toml b/Cargo.toml
index ee265de4d..6b1ff0c06 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,14 +37,13 @@ futures = "0.1"
tokio = "0.1"
systemstat = "0.1.4"
prometheus = { version = "0.7.0", default-features = false }
-lazy_static = "1.0.0"
rustwide = "0.7.1"
mime_guess = "2"
dotenv = "0.15"
zstd = "0.5"
git2 = { version = "0.13.6", default-features = false }
-once_cell = "1.4.0"
path-slash = "0.1.3"
+once_cell = { version = "1.4.0", features = ["parking_lot"] }
# Data serialization and deserialization
serde = { version = "1.0", features = ["derive"] }
diff --git a/src/web/badge/test.svg b/src/web/badge/test.svg
new file mode 100644
index 000000000..2d42753d0
--- /dev/null
+++ b/src/web/badge/test.svg
@@ -0,0 +1,23 @@
+
\ No newline at end of file
diff --git a/src/web/metrics.rs b/src/web/metrics.rs
index bf947bcfa..a69e0fd26 100644
--- a/src/web/metrics.rs
+++ b/src/web/metrics.rs
@@ -3,6 +3,7 @@ use crate::BuildQueue;
use iron::headers::ContentType;
use iron::prelude::*;
use iron::status::Status;
+use once_cell::sync::Lazy;
use prometheus::{
opts, register_counter, register_int_counter, register_int_gauge, Encoder, IntCounter,
IntGauge, TextEncoder, __register_gauge, register_int_counter_vec, IntCounterVec,
@@ -10,112 +11,141 @@ use prometheus::{
};
use std::time::{Duration, Instant};
-lazy_static::lazy_static! {
- static ref QUEUED_CRATES_COUNT: IntGauge = register_int_gauge!(
+static QUEUED_CRATES_COUNT: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_queued_crates_count",
"Number of crates in the build queue"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref PRIORITIZED_CRATES_COUNT: IntGauge = register_int_gauge!(
+pub static PRIORITIZED_CRATES_COUNT: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_prioritized_crates_count",
"Number of crates in the build queue that have a positive priority"
)
- .unwrap();
+ .unwrap()
+});
- static ref FAILED_CRATES_COUNT: IntGauge = register_int_gauge!(
+static FAILED_CRATES_COUNT: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_failed_crates_count",
"Number of crates that failed to build"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref TOTAL_BUILDS: IntCounter = register_int_counter!(
- "docsrs_total_builds",
- "Number of crates built"
- )
- .unwrap();
+pub static TOTAL_BUILDS: Lazy =
+ Lazy::new(|| register_int_counter!("docsrs_total_builds", "Number of crates built").unwrap());
- pub static ref SUCCESSFUL_BUILDS: IntCounter = register_int_counter!(
+pub static SUCCESSFUL_BUILDS: Lazy = Lazy::new(|| {
+ register_int_counter!(
"docsrs_successful_builds",
"Number of builds that successfully generated docs"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref FAILED_BUILDS: IntCounter = register_int_counter!(
+pub static FAILED_BUILDS: Lazy = Lazy::new(|| {
+ register_int_counter!(
"docsrs_failed_builds",
"Number of builds that generated a compile error"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref NON_LIBRARY_BUILDS: IntCounter = register_int_counter!(
+pub static NON_LIBRARY_BUILDS: Lazy = Lazy::new(|| {
+ register_int_counter!(
"docsrs_non_library_builds",
"Number of builds that did not complete due to not being a library"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref UPLOADED_FILES_TOTAL: IntCounter = register_int_counter!(
+pub static UPLOADED_FILES_TOTAL: Lazy = Lazy::new(|| {
+ register_int_counter!(
"docsrs_uploaded_files_total",
"Number of files uploaded to S3 or stored in the database"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref ROUTES_VISITED: IntCounterVec = register_int_counter_vec!(
+pub static ROUTES_VISITED: Lazy = Lazy::new(|| {
+ register_int_counter_vec!(
"docsrs_routes_visited",
"The traffic of various docs.rs routes",
&["route"]
)
- .unwrap();
+ .unwrap()
+});
- pub static ref RESPONSE_TIMES: HistogramVec = register_histogram_vec!(
+pub static RESPONSE_TIMES: Lazy = Lazy::new(|| {
+ register_histogram_vec!(
"docsrs_response_time",
"The response times of various docs.rs routes",
&["route"]
)
- .unwrap();
+ .unwrap()
+});
- pub static ref RUSTDOC_RENDERING_TIMES: HistogramVec = register_histogram_vec!(
+pub static RUSTDOC_RENDERING_TIMES: Lazy = Lazy::new(|| {
+ register_histogram_vec!(
"docsrs_rustdoc_rendering_time",
"The time it takes to render a rustdoc page",
&["step"]
)
- .unwrap();
+ .unwrap()
+});
- pub static ref FAILED_DB_CONNECTIONS: IntCounter = register_int_counter!(
+pub static FAILED_DB_CONNECTIONS: Lazy = Lazy::new(|| {
+ register_int_counter!(
"docsrs_failed_db_connections",
"Number of attempted and failed connections to the database"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref USED_DB_CONNECTIONS: IntGauge = register_int_gauge!(
+pub static USED_DB_CONNECTIONS: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_used_db_connections",
"The number of used database connections"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref IDLE_DB_CONNECTIONS: IntGauge = register_int_gauge!(
+pub static IDLE_DB_CONNECTIONS: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_idle_db_connections",
"The number of idle database connections"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref MAX_DB_CONNECTIONS: IntGauge = register_int_gauge!(
+pub static MAX_DB_CONNECTIONS: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_max_db_connections",
"The maximum database connections"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref OPEN_FILE_DESCRIPTORS: IntGauge = register_int_gauge!(
+#[cfg(not(windows))]
+pub static OPEN_FILE_DESCRIPTORS: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_open_file_descriptors",
"The number of currently opened file descriptors"
)
- .unwrap();
+ .unwrap()
+});
- pub static ref CURRENTLY_RUNNING_THREADS: IntGauge = register_int_gauge!(
+#[cfg(not(windows))]
+pub static CURRENTLY_RUNNING_THREADS: Lazy = Lazy::new(|| {
+ register_int_gauge!(
"docsrs_running_threads",
"The number of threads being used by docs.rs"
)
- .unwrap();
-}
+ .unwrap()
+});
pub fn metrics_handler(req: &mut Request) -> IronResult {
let pool = extension!(req, Pool);
@@ -231,6 +261,7 @@ impl Drop for RenderingTimesRecorder {
#[cfg(test)]
mod tests {
use crate::test::{assert_success, wrapper};
+ use once_cell::sync::Lazy;
use std::{
collections::HashMap,
sync::{
@@ -240,9 +271,8 @@ mod tests {
};
static ROUTES_VISITED: AtomicUsize = AtomicUsize::new(0);
- lazy_static::lazy_static! {
- static ref RESPONSE_TIMES: Mutex> = Mutex::new(HashMap::new());
- }
+ static RESPONSE_TIMES: Lazy>> =
+ Lazy::new(|| Mutex::new(HashMap::new()));
pub fn record_tests(route: &str) {
ROUTES_VISITED.fetch_add(1, Ordering::SeqCst);
diff --git a/src/web/page/handlebars.rs b/src/web/page/handlebars.rs
index 988f29560..c493a8f8e 100644
--- a/src/web/page/handlebars.rs
+++ b/src/web/page/handlebars.rs
@@ -3,6 +3,7 @@
use handlebars_iron::Template;
use iron::response::Response;
use iron::{status, IronResult, Set};
+use once_cell::sync::Lazy;
use serde::{
ser::{SerializeStruct, Serializer},
Serialize,
@@ -10,10 +11,8 @@ use serde::{
use serde_json::Value;
use std::collections::BTreeMap;
-lazy_static::lazy_static! {
- static ref RUSTC_RESOURCE_SUFFIX: String = load_rustc_resource_suffix()
- .unwrap_or_else(|_| "???".into());
-}
+static RUSTC_RESOURCE_SUFFIX: Lazy =
+ Lazy::new(|| load_rustc_resource_suffix().unwrap_or_else(|_| "???".into()));
fn load_rustc_resource_suffix() -> Result {
// New instances of the configuration or the connection pool shouldn't be created inside the
diff --git a/src/web/page/templates.rs b/src/web/page/templates.rs
index 2c9da5e0c..801de6c29 100644
--- a/src/web/page/templates.rs
+++ b/src/web/page/templates.rs
@@ -77,6 +77,7 @@ fn load_rustc_resource_suffix(conn: &Connection) -> Result {
"SELECT value FROM config WHERE name = 'rustc_version';",
&[],
)?;
+
if res.is_empty() {
failure::bail!("missing rustc version");
}