Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
add sentry + prom
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Mar 30, 2024
1 parent 9ed8612 commit f4c48a1
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 60 deletions.
53 changes: 27 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/database/models/project_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/database/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,12 @@ impl RedisPool {

#[allow(clippy::type_complexity)]
let mut fetch_tasks: Vec<
Pin<Box<dyn Future<Output = Result<HashMap<K, RedisValue<T, K, S>>, DatabaseError>> + Send>>,
Pin<
Box<
dyn Future<Output = Result<HashMap<K, RedisValue<T, K, S>>, DatabaseError>>
+ Send,
>,
>,
> = Vec::new();

if !ids.is_empty() {
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyedRateLimiter> = Arc::new(
RateLimiter::keyed(Quota::per_minute(NonZeroU32::new(300).unwrap()))
Expand All @@ -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)
Expand All @@ -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::<SocketAddr>();

// run our app with hyper, listening globally on port 3000
Expand Down
30 changes: 14 additions & 16 deletions src/routes/internal/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -54,7 +52,7 @@ pub async fn get_projects(
&session_queue,
Some(&[Scopes::PROJECT_READ]),
)
.await?;
.await?;

use futures::stream::TryStreamExt;

Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -249,7 +247,7 @@ pub async fn set_project_meta(
&session_queue,
Some(&[Scopes::PROJECT_WRITE]),
)
.await?;
.await?;

let mut transaction = pool.begin().await?;

Expand Down
3 changes: 1 addition & 2 deletions src/routes/v2/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit f4c48a1

Please sign in to comment.