-
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
[EASY] Add metrics for logging native price requests #3006
Conversation
@@ -104,16 +112,6 @@ impl Inner { | |||
} | |||
} | |||
|
|||
impl Clone for TradeEstimator { |
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 guess this was done because it required in the pass a specific Clone
implementation. But this currently does what the #[derive(Clone)]
should do.
9311449
to
28b38c9
Compare
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.
Already nitted on a few implementation details when I remembered that we already have InstrumentedPriceEstimator
which already abstracted that logic.
Probably just needs a few adjustments to work with native price estimators as well.
#[derive(prometheus_metric_storage::MetricStorage)] | ||
pub(in crate::price_estimation) struct Metrics { | ||
/// number of requests done by each estimator | ||
#[metric(labels("requests"))] |
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.
#[metric(labels("requests"))] | |
#[metric(labels("estimator"))] |
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 am unifying it with the same naming in InstrumentedPriceEstimator
to be consistent.
@@ -91,6 +92,7 @@ where | |||
token: H160, | |||
) -> futures::future::BoxFuture<'_, NativePriceEstimateResult> { | |||
async move { | |||
Metrics::inc_estimator("buffered"); |
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.
This would become problematic as soon as there are multiple different APIs that support buffering.
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.
You are definitely right, let's add it to CoinGecko
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.
Btw if you use the InstrumentedPriceEstimator
wrapper thingy you don't have to add anything to coingecko. You just wrap it in that struct and it starts instrumenting it.
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.
Yup, that's what I am doing, but I am trying to do it as nicer as possible, because InstrumentedPriceEstimator
is hard-coded for PriceEstimating
Sounds good, let's give it a try. |
3771174
to
2fb58e4
Compare
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.
Nice!
Just a few nits
pub struct InstrumentedPriceEstimator { | ||
inner: Box<dyn PriceEstimating>, | ||
pub struct InstrumentedPriceEstimator<T> { | ||
inner: Arc<T>, |
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.
Was there a reason to turn this into an Arc
? Doesn't look necessary to me.
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.
Good question! The reason I did it is because during the development I wanted to fully remove Box<>
and to have just the type T
, I put Arc<>
temporarily to sanitize some errors and I forgot to delete it during the clean up. Good catch!
The type should be:
inner: T
We do not need any wrapper at all!
// Count as a successful request if the answer is ok (no error) or if the error | ||
// is No Liquidity | ||
let success = | ||
estimate.is_ok() || matches!(&estimate, Err(PriceEstimationError::NoLiquidity)); |
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 think counting NoLiquidity
as a success makes sense but then we should also change that in the regular estimator implementation to not have a drift for no reason here.
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.
Good point! I added a common function to evaluate the result! 👌
@@ -155,7 +155,7 @@ impl<'a> PriceEstimatorFactory<'a> { | |||
.as_ref() | |||
.and_then(|trade_verifier| estimator.verified(trade_verifier)); | |||
|
|||
let fast = instrument(estimator, name); | |||
let fast = instrument::<T>(estimator, name); |
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.
is ::<T>
actually needed here? I thought the compiler would be smart enough to deduce T
on it's own.
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.
Good catch! 👀 it was needed for a middle version I did, but now it is not needed anymore 🙌
b0a06d1
to
4e3ecee
Compare
)) | ||
} | ||
NativePriceEstimatorSource::OneInchSpotPriceApi => { | ||
let name = "OneInchSpotPriceApi".to_string(); |
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.
UpperCamelCase should be avoided since driver.name
uses flatcase. We should use a similar format for other names as well. If not flatcase everywhere, maybe snake_case.
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.
Yeah, I agree with you, but this is something systematic within the natice prices, we should change that in another PR alongside the configuration, because this happens also in the configuration of the services :/
self.metrics | ||
.native_price_estimation_times | ||
.with_label_values(&[self.name.as_str()]) | ||
.observe(start.elapsed().as_secs_f64()); | ||
let result = self.estimate_result(estimate.as_ref()); | ||
self.metrics | ||
.native_price_estimates | ||
.with_label_values(&[self.name.as_str(), result]) | ||
.inc(); |
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.
Do we really need 2 metrics? Can we use only the native_price_estimation_times
with 2 labels and use the _count
metric instead of declaring one more with increment?
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.
@squadgazzz in the end, because of this comment: #3006 (comment)
it was decided to directly reuse the current metrics 👌
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.
LG
a243cdb
to
3f137fc
Compare
Description
Add more metrics for native price requests. So we can properly assess how many requests are sent for each estimator.