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

Add /metrics endpoint for Prometheus [MOD-545] #724

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

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

21 changes: 17 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ actix-multipart = "0.6.0"
actix-cors = "0.6.4"
actix-ws = "0.2.5"
actix-files = "0.6.2"
actix-web-prom = "0.7.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the changes besides this were just auto-formats, do we mind?


tokio = { version = "1.29.1", features = ["sync"] }
tokio-stream = "0.1.14"
Expand All @@ -37,7 +38,7 @@ hyper-tls = "0.5.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.0.0"
chrono = { version = "0.4.26", features = ["serde"]}
chrono = { version = "0.4.26", features = ["serde"] }
yaserde = "0.8.0"
yaserde_derive = "0.8.0"
xml-rs = "0.8.15"
Expand Down Expand Up @@ -72,9 +73,21 @@ log = "0.4.19"
env_logger = "0.10.0"
thiserror = "1.0.41"

sqlx = { version = "0.6.3", features = ["offline", "runtime-tokio-rustls", "postgres", "chrono", "macros", "migrate", "decimal", "json"] }
rust_decimal = { version = "1.30.0", features = ["serde-with-float", "serde-with-str"] }
redis = { version = "0.23.0", features = ["tokio-comp", "ahash", "r2d2"]}
sqlx = { version = "0.6.3", features = [
"offline",
"runtime-tokio-rustls",
"postgres",
"chrono",
"macros",
"migrate",
"decimal",
"json",
] }
rust_decimal = { version = "1.30.0", features = [
"serde-with-float",
"serde-with-str",
] }
redis = { version = "0.23.0", features = ["tokio-comp", "ahash", "r2d2"] }
deadpool-redis = "0.12.0"
clickhouse = { version = "0.11.2", features = ["uuid", "time"] }
uuid = { version = "1.2.2", features = ["v4", "fast-rng", "serde"] }
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use actix_web::{App, HttpServer};
use actix_web_prom::PrometheusMetricsBuilder;
use env_logger::Env;
use labrinth::database::redis::RedisPool;
use labrinth::file_hosting::S3Host;
Expand Down Expand Up @@ -88,6 +89,11 @@ async fn main() -> std::io::Result<()> {

let store = MemoryStore::new();

let prometheus = PrometheusMetricsBuilder::new("labrinth")
.endpoint("/metrics")
.build()
.expect("Failed to create prometheus metrics middleware");

info!("Starting Actix HTTP server!");

let labrinth_config = labrinth::app_setup(
Expand All @@ -101,6 +107,7 @@ async fn main() -> std::io::Result<()> {
// Init App
HttpServer::new(move || {
App::new()
.wrap(prometheus.clone())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't play nice with the compression middleware, so I had to put it above it. Didn't investigate why, could if we want.

.wrap(actix_web::middleware::Compress::default())
.wrap(
RateLimiter::new(MemoryStoreActor::from(store.clone()).start())
Expand Down
Loading