From f4c48a17e534bc9736a0ede807ef01ad2d321dce Mon Sep 17 00:00:00 2001 From: Jai A Date: Fri, 29 Mar 2024 20:29:06 -0700 Subject: [PATCH] add sentry + prom --- Cargo.lock | 53 +++++++++++++++-------------- Cargo.toml | 1 + src/database/models/project_item.rs | 7 +++- src/database/redis.rs | 7 +++- src/lib.rs | 6 ++-- src/main.rs | 10 +++--- src/routes/internal/moderation.rs | 30 ++++++++-------- src/routes/v2/threads.rs | 3 +- src/routes/v2/version_file.rs | 9 ++--- src/util/extract.rs | 2 +- 10 files changed, 68 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a43e988..69e42acb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,7 +156,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -289,7 +289,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -492,7 +492,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", "syn_derive", ] @@ -991,7 +991,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1013,7 +1013,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core 0.20.8", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1105,7 +1105,7 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1511,7 +1511,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -2220,6 +2220,7 @@ dependencies = [ "rust_decimal", "rust_iso3166", "sentry", + "sentry-tower", "serde", "serde_json", "serde_urlencoded", @@ -2443,7 +2444,7 @@ checksum = "5cf92c10c7e361d6b99666ec1c6f9805b0bea2c3bd8c78dc6fe98ac5bd78db11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -2788,7 +2789,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -2950,7 +2951,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3000,7 +3001,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3801,9 +3802,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -3814,9 +3815,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ "core-foundation-sys", "libc", @@ -3969,7 +3970,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -4043,7 +4044,7 @@ dependencies = [ "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -4531,9 +4532,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35" dependencies = [ "proc-macro2", "quote", @@ -4549,7 +4550,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -4642,7 +4643,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -4737,7 +4738,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -4893,7 +4894,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5211,7 +5212,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", "wasm-bindgen-shared", ] @@ -5245,7 +5246,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5576,7 +5577,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index dce8069c..ce564078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ axum-prometheus = "0.6.1" # middleware + utils sentry = { version = "0.32.1", features = ["tracing", "tower", "tower-http", "tower-axum-matched-path"] } +sentry-tower = "0.32.2" tower-http = { version = "0.5.0", features = ["trace", "cors", "sensitive-headers", "fs", "compression-zstd", "compression-gzip", "compression-deflate", "compression-br"] } tower = "0.4.13" governor = "0.6.0" diff --git a/src/database/models/project_item.rs b/src/database/models/project_item.rs index 1a982d65..d462ca5d 100644 --- a/src/database/models/project_item.rs +++ b/src/database/models/project_item.rs @@ -519,7 +519,12 @@ impl Project { } #[allow(clippy::manual_async_fn)] - pub fn get_many<'a, 'c, E, T: Display + Hash + Eq + PartialEq + Clone + Debug + std::marker::Sync + std::marker::Send>( + pub fn get_many< + 'a, + 'c, + E, + T: Display + Hash + Eq + PartialEq + Clone + Debug + std::marker::Sync + std::marker::Send, + >( project_strings: &'a [T], exec: E, redis: &'a RedisPool, diff --git a/src/database/redis.rs b/src/database/redis.rs index 35f6f5a8..312ac251 100644 --- a/src/database/redis.rs +++ b/src/database/redis.rs @@ -288,7 +288,12 @@ impl RedisPool { #[allow(clippy::type_complexity)] let mut fetch_tasks: Vec< - Pin>, DatabaseError>> + Send>>, + Pin< + Box< + dyn Future>, DatabaseError>> + + Send, + >, + >, > = Vec::new(); if !ids.is_empty() { diff --git a/src/lib.rs b/src/lib.rs index fb54b54b..2d0af75f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,10 +15,10 @@ use tracing::{info, warn}; extern crate clickhouse as clickhouse_crate; use clickhouse_crate::Client; +use crate::queue::moderation::AutomatedModerationQueue; use crate::routes::not_found; use crate::scheduler::schedule; use crate::util::cors::default_cors; -use crate::queue::moderation::AutomatedModerationQueue; use crate::{ queue::payouts::process_payout, search::indexing::index_projects, @@ -280,7 +280,9 @@ pub fn app_config(labrinth_config: LabrinthConfig) -> Router { .layer(Extension(labrinth_config.clickhouse.clone())) .layer(Extension(labrinth_config.maxmind.clone())) .layer(Extension(labrinth_config.active_sockets.clone())) - .layer(Extension(labrinth_config.automated_moderation_queue.clone())) + .layer(Extension( + labrinth_config.automated_moderation_queue.clone(), + )) .layer(DefaultBodyLimit::max(5 * 1024 * 1024)) } diff --git a/src/main.rs b/src/main.rs index eef0ec98..41b87fc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,7 +121,7 @@ async fn main() -> std::io::Result<()> { false, ); - // let (prometheus_layer, metric_handle) = PrometheusMetricLayer::pair(); + let (prometheus_layer, metric_handle) = PrometheusMetricLayer::pair(); let limiter: Arc = Arc::new( RateLimiter::keyed(Quota::per_minute(NonZeroU32::new(300).unwrap())) @@ -146,8 +146,8 @@ async fn main() -> std::io::Result<()> { let app = labrinth::app_config(labrinth_config) .layer(axum::middleware::from_fn(ratelimit)) .layer(Extension(limiter)) - // .route("/metrics", get(|| async move { metric_handle.render() })) - // .layer(prometheus_layer) + .route("/metrics", get(|| async move { metric_handle.render() })) + .layer(prometheus_layer) .layer( CompressionLayer::new() .br(true) @@ -159,8 +159,8 @@ async fn main() -> std::io::Result<()> { AUTHORIZATION, ))) .layer(TraceLayer::new_for_http()) - // .layer(sentry::NewSentryLayer::new_from_top()) - // .layer(sentry::SentryHttpLayer::with_transaction()) + .layer(sentry_tower::NewSentryLayer::new_from_top()) + .layer(sentry_tower::SentryHttpLayer::with_transaction()) .into_make_service_with_connect_info::(); // run our app with hyper, listening globally on port 3000 diff --git a/src/routes/internal/moderation.rs b/src/routes/internal/moderation.rs index d6324a52..d422404c 100644 --- a/src/routes/internal/moderation.rs +++ b/src/routes/internal/moderation.rs @@ -5,27 +5,25 @@ use crate::models::ids::random_base62; use crate::models::projects::{Project, ProjectStatus}; use crate::queue::moderation::{ApprovalType, IdentifiedFile, MissingMetadata}; use crate::queue::session::AuthQueue; +use crate::util::extract::{ConnectInfo, Extension, Json, Path, Query}; use crate::{auth::check_is_moderator_from_headers, models::pats::Scopes}; +use axum::http::{HeaderMap, StatusCode}; +use axum::routing::{get, post}; +use axum::Router; use serde::Deserialize; use sqlx::PgPool; use std::collections::HashMap; use std::net::SocketAddr; use std::sync::Arc; -use axum::http::{HeaderMap, StatusCode}; -use axum::Router; -use axum::routing::{get, post}; -use crate::util::extract::{ConnectInfo, Extension, Json, Path, Query}; - pub fn config() -> Router { - Router::new() - .nest( - "/moderation", - Router::new() - .route("/projects", get(get_projects)) - .route("/project/:id", get(get_project_meta)) - .route("/project", post(set_project_meta)), - ) + Router::new().nest( + "/moderation", + Router::new() + .route("/projects", get(get_projects)) + .route("/project/:id", get(get_project_meta)) + .route("/project", post(set_project_meta)), + ) } #[derive(Deserialize)] @@ -54,7 +52,7 @@ pub async fn get_projects( &session_queue, Some(&[Scopes::PROJECT_READ]), ) - .await?; + .await?; use futures::stream::TryStreamExt; @@ -98,7 +96,7 @@ pub async fn get_project_meta( &session_queue, Some(&[Scopes::PROJECT_READ]), ) - .await?; + .await?; let project = database::models::Project::get(&project_id, &pool, &redis).await?; @@ -249,7 +247,7 @@ pub async fn set_project_meta( &session_queue, Some(&[Scopes::PROJECT_WRITE]), ) - .await?; + .await?; let mut transaction = pool.begin().await?; diff --git a/src/routes/v2/threads.rs b/src/routes/v2/threads.rs index 63e79f91..00c91e20 100644 --- a/src/routes/v2/threads.rs +++ b/src/routes/v2/threads.rs @@ -19,8 +19,7 @@ pub fn config() -> Router { Router::new() .nest( "/thread", - Router::new() - .route("/:id", get(thread_get).post(thread_send_message)) + Router::new().route("/:id", get(thread_get).post(thread_send_message)), ) .nest( "/message", diff --git a/src/routes/v2/version_file.rs b/src/routes/v2/version_file.rs index 7da59338..51561fb0 100644 --- a/src/routes/v2/version_file.rs +++ b/src/routes/v2/version_file.rs @@ -263,12 +263,9 @@ pub async fn update_files( hashes: update_data.hashes, }; - let Json(map) = v3::version_file::update_files( - Extension(pool), - Extension(redis), - Json(update_data), - ) - .await?; + let Json(map) = + v3::version_file::update_files(Extension(pool), Extension(redis), Json(update_data)) + .await?; // Convert response to V2 format let map = map diff --git a/src/util/extract.rs b/src/util/extract.rs index f33544ae..9089bc63 100644 --- a/src/util/extract.rs +++ b/src/util/extract.rs @@ -1,8 +1,8 @@ +pub use axum::extract::ConnectInfo; use axum::extract::FromRequest; use axum::extract::FromRequestParts; use axum::response::{IntoResponse, Response}; use serde::Serialize; -pub use axum::extract::ConnectInfo; #[derive(FromRequest, FromRequestParts)] #[from_request(via(axum::Json), rejection(crate::routes::ApiError))]