-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Solver engines are currently not exposing any metrics. This PR changes that. # Changes - [ ] Collect histogram of initial time_limit when requests come in - [ ] Collect histogram of remaining time when requests are done - [ ] Collect number of proposed solutions - [ ] Collect failure reasons ## How to test Run everything locally and visit http://localhost:7872/metrics Once merged, this will require an infra change to start scraping metrics in prometheus. ## Related Issues Fixes #1239
- Loading branch information
Showing
13 changed files
with
98 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
use prometheus::Encoder; | ||
|
||
pub(in crate::infra::api) fn metrics(app: axum::Router<()>) -> axum::Router<()> { | ||
app.route("/metrics", axum::routing::get(route)) | ||
} | ||
|
||
async fn route() -> String { | ||
let registry = observe::metrics::get_registry(); | ||
let encoder = prometheus::TextEncoder::new(); | ||
let mut buffer = Vec::new(); | ||
encoder.encode(®istry.gather(), &mut buffer).unwrap(); | ||
String::from_utf8(buffer).unwrap() | ||
observe::metrics::encode(registry) | ||
} |
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
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,4 @@ | ||
pub async fn metrics() -> String { | ||
let registry = observe::metrics::get_registry(); | ||
observe::metrics::encode(registry) | ||
} |
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
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,53 @@ | ||
use crate::domain::{auction, solution}; | ||
|
||
/// Metrics for the solver engine. | ||
#[derive(Debug, Clone, prometheus_metric_storage::MetricStorage)] | ||
#[metric(subsystem = "solver_engine")] | ||
struct Metrics { | ||
/// The amount of time this solver engine has for solving. | ||
#[metric(buckets(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15))] | ||
time_limit: prometheus::Histogram, | ||
|
||
/// The amount of time this solver engine has left when it finished solving. | ||
#[metric(buckets(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15))] | ||
remaining_time: prometheus::Histogram, | ||
|
||
/// Errors that occurred during solving. | ||
#[metric(labels("reason"))] | ||
solve_errors: prometheus::IntCounterVec, | ||
|
||
/// The number of solutions that were found. | ||
solutions: prometheus::IntCounter, | ||
} | ||
|
||
/// Setup the metrics registry. | ||
pub fn init() { | ||
observe::metrics::setup_registry_reentrant(Some("solver-engine".to_owned()), None); | ||
} | ||
|
||
pub fn solve(auction: &auction::Auction) { | ||
get().time_limit.observe( | ||
auction | ||
.deadline | ||
.remaining() | ||
.unwrap_or_default() | ||
.as_secs_f64(), | ||
); | ||
} | ||
|
||
pub fn solved(deadline: &auction::Deadline, solutions: &[solution::Solution]) { | ||
get() | ||
.remaining_time | ||
.observe(deadline.remaining().unwrap_or_default().as_secs_f64()); | ||
get().solutions.inc_by(solutions.len() as u64); | ||
} | ||
|
||
pub fn solve_error(reason: &str) { | ||
get().solve_errors.with_label_values(&[reason]).inc(); | ||
} | ||
|
||
/// Get the metrics instance. | ||
fn get() -> &'static Metrics { | ||
Metrics::instance(observe::metrics::get_storage_registry()) | ||
.expect("unexpected error getting metrics instance") | ||
} |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod cli; | |
pub mod config; | ||
pub mod contracts; | ||
pub mod dex; | ||
pub mod metrics; |