-
Notifications
You must be signed in to change notification settings - Fork 279
geyser: add connection slot lag metric #508
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
base: master
Are you sure you want to change the base?
Conversation
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.
Conflicting files.
@@ -1089,7 +1106,7 @@ impl GrpcService { | |||
|
|||
#[tonic::async_trait] | |||
impl Geyser for GrpcService { | |||
type SubscribeStream = ReceiverStream<TonicResult<FilteredUpdate>>; | |||
type SubscribeStream = ReceiverStream; |
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.
We should use BoxStream<'static, TonicResult<FilteredUpdated>>
instead
pub struct ReceiverStream { | ||
rx: mpsc::Receiver<TonicResult<FilteredUpdate>>, | ||
metric_connection_slot_lag: bool, | ||
max_slot: Slot, | ||
} | ||
|
||
impl ReceiverStream { | ||
const fn new( | ||
rx: mpsc::Receiver<TonicResult<FilteredUpdate>>, | ||
metric_connection_slot_lag: bool, | ||
) -> Self { | ||
Self { | ||
rx, | ||
metric_connection_slot_lag, | ||
max_slot: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Stream for ReceiverStream { | ||
type Item = TonicResult<FilteredUpdate>; | ||
|
||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
let value = futures::ready!(self.rx.poll_recv(cx)); | ||
if self.metric_connection_slot_lag { | ||
if let Some(slot) = value | ||
.as_ref() | ||
.and_then(|item| item.as_ref().map(|item| item.message.get_slot()).ok()) | ||
.flatten() | ||
{ | ||
if slot > self.max_slot { | ||
self.max_slot = slot; | ||
metrics::connections_slot_lag_observe(slot); | ||
} | ||
} | ||
} | ||
Poll::Ready(value) | ||
} | ||
} |
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.
We should use boxed the tokio stream and use map
instead of implementing our own Stream
trait.
No description provided.