-
Notifications
You must be signed in to change notification settings - Fork 989
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
feat(gossipsub): feature gate metrics related code #5711
base: master
Are you sure you want to change the base?
Conversation
This pull request has merge conflicts. Could you please resolve them @drHuangMHT? 🙏 |
Oops that would probably take a while to find where the side effect is. |
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.
It would be great if we can avoid the duplicated API for each Behavior::new_*
method.
Wdyt think of instead:
- by default don't include metrics when creating a new behavior
- havea single, feature-gated method
fn with_metrics(&mut self, metrics_registry: &mut Registry, metrics_config: MetricsConfig,)
to enable them? The method could optionally also take& return ownership of self, so that one could callBehavior::new(..).with_metrics(...)
.
A mutable borrow would allow users to change the |
The scoring part can be tricky though. The behaviour need to provide a reference to
|
Wdyt of:
I usually try to avoid such tuple return types, but in this specific case it may be cleaner than constructing a dummy structure? |
There are 98 places where
No problem.
Just out of curiosity: do alias work in this case? |
Hmm, I just noticed that
Good idea 👍.
If we do the vec, we could only push something into the vec if metrics are enabled. I would assume that the compiler then just optimizes it away when the feature is not enabled. |
The penalties are fungible, and I don't think the ordering is of any importance, so a number will suffice. And yeah we don't have to increment the counter when the feature is not enable, the impact will be minimal. |
Well this probably also improves performance now that the |
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.
One comment, rest LGTM.
I'd still like to wait for @jxs's review since he's more familiar with gossipsub than I am.
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.
Hi and sorry for the delay! Thanks for the inititative @drHuangMHT, and @elenaf9 for the review.
I am torn on this one, I know #2923 was opened and that gossipsub
uses metrics differently than any other behaviour, but I wonder if there there is any use case for usage of gossipsub
without metrics
where the the dependency on prometheus-client
creates significant problems? Is that your case @drHuangMHT?
Cause I think this PR makes it even more confusing to understand the scoring system, with variables declared in places for metrics like here where it's not clear why it's outside the metrics scope just below. and duplicated functions used only for metrics (remove_peer_from_mesh
) where it's also not clear why the whole code needs to be duplicated.
If we really wanna make prometheus-client
a optional dependency can we try to first decouple the metrics logic from the scoring system? So that when we make metrics
feature gated it's only
#[cfg(feature = "metrics")]
if let Some(metrics) = self.metrics.as_mut() {
// code
}
No, I just picked the issue up. But just as thomas said it wouldn't be a bad thing to do.
Ugh because another block of gated code used the same variable. If I moved it in there will be a scoping problem. I'll look into that to see what I can do. I'm keeping them separate because I don't want to change the original code structure too much.
Oops that's probably an oversight. I'll look into it, the duplication probably isn't necessary.
I'll try. |
Description
May close #2923.
Notes & open questions
Breaking change: Contains public API changes.
I'm trying to keep the change as small as possible, which introduces a lot of duplicate code. Is there a better way?
Change checklist