You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously with the RpcLogger it was easy to log when a connection was opened/closed but
it's not easy anymore because the TowerService::call returns once the HTTP request has
been answered.
Thus, for instance I guess a common use-case is the emit prometheus metrics when a connection is opened and closed but the following won't work correctly:
let make_service = make_service_fn(move |_conn:&AddrStream| {asyncmove{Ok::<_,Infallible>(service_fn(move |req| {let metrics = metrics.clone();let svc_builder = svc_builder.clone();let is_websocket = ws::is_upgrade_request(&req);let transport_label = if is_websocket {"ws"}else{"http"};let metrics = metrics.map(|m| MetricsLayer::new(m, transport_label));let rpc_middleware = RpcServiceBuilder::new().option_layer(metrics.clone());letmut svc = svc_builder
.set_rpc_middleware(rpc_middleware).build(methods.clone(), stop_handle.clone());asyncmove{if is_websocket {let now = std::time::Instant::now();
metrics.as_ref().map(|m| m.ws_connect());// This will return once the HTTP upgrade request has been answered.let rp = svc.call(req).await;// Thus, this will not actually be when the connection was closed// but once the WS upgrade handshake is done
metrics.as_ref().map(|m| m.ws_disconnect(now));
rp
}else{
svc.call(req).await}}.boxed()}))}});
Option 1
Introduce an alternative API to build the TowerService with future that resolves
once the connection is closed.
/// Build a tower service and get a future to resolves when the connection/// has been terminated.pubfn build_with_close_handle(self,methods:implInto<Methods>,stop_handle:StopHandle,) -> (TowerService<RpcMiddleware,HttpMiddleware>,implFuture<Output = ()>){
That is not great either because the TowerServiceBuilder can actually be reused/cloned to make another request....
Thus, the future will be fired once
Option 2
Tell folks to use the low-level API but annoying for just the logging stuff.
The text was updated successfully, but these errors were encountered:
Previously with the RpcLogger it was easy to log when a connection was opened/closed but
it's not easy anymore because the
TowerService::call
returns once the HTTP request hasbeen answered.
Thus, for instance I guess a common use-case is the emit prometheus metrics when a connection is opened and closed but the following won't work correctly:
Option 1
Introduce an alternative API to build the TowerService with future that resolves
once the connection is closed.
That is not great either because the TowerServiceBuilder can actually be reused/cloned to make another request....
Thus, the
future
will be fired onceOption 2
Tell folks to use the low-level API but annoying for just the logging stuff.
The text was updated successfully, but these errors were encountered: