-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from zama-ai/davidk/prom-metrics
Add prometheus instrumentation for coprocessor
- Loading branch information
Showing
10 changed files
with
542 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
|
||
DB_URL ?= DATABASE_URL=postgres://postgres:[email protected]:5432/coprocessor | ||
|
||
.PHONY: build | ||
build: | ||
cargo build | ||
|
@@ -11,9 +13,9 @@ cleanup: | |
init_db: | ||
docker compose up -d | ||
sleep 3 | ||
DATABASE_URL=postgres://postgres:[email protected]:5432/coprocessor sqlx db create | ||
DATABASE_URL=postgres://postgres:[email protected]:5432/coprocessor sqlx migrate run | ||
DATABASE_URL=postgres://postgres:[email protected]:5432/coprocessor cargo test setup_test_user -- --nocapture --ignored | ||
$(DB_URL) sqlx db create | ||
$(DB_URL) sqlx migrate run | ||
$(DB_URL) cargo test setup_test_user -- --nocapture --ignored | ||
|
||
.PHONY: recreate_db | ||
recreate_db: | ||
|
@@ -23,4 +25,4 @@ recreate_db: | |
.PHONY: clean_run | ||
clean_run: | ||
$(MAKE) recreate_db | ||
RUST_BACKTRACE=1 cargo run -- --run-server --run-bg-worker | ||
RUST_BACKTRACE=1 $(DB_URL) cargo run --release -- --run-server --run-bg-worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
async fn metrics() -> impl actix_web::Responder { | ||
let encoder = prometheus::TextEncoder::new(); | ||
let metric_families = prometheus::gather(); | ||
encoder.encode_to_string(&metric_families).expect("can't encode metrics") | ||
} | ||
|
||
async fn healthcheck() -> impl actix_web::Responder { | ||
"OK" | ||
} | ||
|
||
pub async fn run_metrics_server( | ||
args: crate::cli::Args, | ||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
println!("metrics server listening at {}", args.metrics_addr); | ||
let _ = actix_web::HttpServer::new(|| { | ||
actix_web::App::new() | ||
.route("/metrics", actix_web::web::to(metrics)) | ||
.route("/health", actix_web::web::to(healthcheck)) | ||
}) | ||
.bind(&args.metrics_addr) | ||
.expect("can't bind to metrics server address") | ||
.workers(1) | ||
.run() | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters