-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrument Solver Engine #2129
Merged
Merged
Instrument Solver Engine #2129
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e0f41cb
Instrument Solver Engine
fleupold 96496ad
comments
fleupold d1ef287
comments
fleupold 05609e3
clippy
fleupold 3720160
Merge branch 'main' into instrument_solver_engine
fleupold 238a707
fix e2e test
fleupold 7d227b5
Merge branch 'instrument_solver_engine' of github.com:cowprotocol/ser…
fleupold c3fff89
Merge branch 'main' into instrument_solver_engine
fleupold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 @@ | ||
use prometheus::Encoder; | ||
|
||
pub async fn metrics() -> 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() | ||
fleupold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod cli; | |
pub mod config; | ||
pub mod contracts; | ||
pub mod dex; | ||
pub mod observe; |
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,29 @@ | ||
/// Metrics for the solver engine. | ||
#[derive(Debug, Clone, prometheus_metric_storage::MetricStorage)] | ||
pub 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))] | ||
pub 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))] | ||
pub remaining_time: prometheus::Histogram, | ||
|
||
/// Errors that occurred during solving. | ||
#[metric(labels("reason"))] | ||
pub solve_errors: prometheus::IntCounterVec, | ||
|
||
/// The number of solutions that were found. | ||
pub solutions: prometheus::IntCounter, | ||
} | ||
|
||
/// Setup the metrics registry. | ||
pub fn init() { | ||
observe::metrics::setup_registry_reentrant(Some("solver-engine".to_owned()), None); | ||
} | ||
|
||
/// Get the metrics instance. | ||
pub 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use { | ||
crate::domain::{auction, solution}, | ||
chrono::Utc, | ||
}; | ||
|
||
pub mod metrics; | ||
|
||
pub fn solve(auction: &auction::Auction) { | ||
fleupold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metrics::get() | ||
.time_limit | ||
.observe(remaining_time(&auction.deadline)); | ||
} | ||
|
||
pub fn solved(deadline: &auction::Deadline, solutions: &[solution::Solution]) { | ||
metrics::get() | ||
.remaining_time | ||
.observe(remaining_time(deadline)); | ||
metrics::get().solutions.inc_by(solutions.len() as u64); | ||
} | ||
|
||
pub fn solve_error(reason: &str) { | ||
metrics::get() | ||
.solve_errors | ||
.with_label_values(&[reason]) | ||
.inc(); | ||
} | ||
|
||
fn remaining_time(deadline: &auction::Deadline) -> f64 { | ||
deadline | ||
.0 | ||
.signed_duration_since(Utc::now()) | ||
.num_milliseconds() as f64 | ||
/ 1000.0 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan didn't pan out entirely. 🙁
Maybe we can reexport the types we need from those crates in the
observe
crate as well in another PR. Thenobserve
should be the only crate that directly depends on them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to get this to compile. The proc macro that generates the Metrics struct requires
prometheus_metric_storage
so even with re-exports I'm gettingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to merge the PR without this. It would just be a nice clean up that can happen at any time and should not delay proper metrics on the
solvers
crate.That being said I remember exporting macros requiring a specific macro on top of it and reexporting a macro might be even more magical. 😄 🤷♂️