1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use grpcio::{RpcStatus, RpcStatusCode};
use std::fmt::Debug;
pub fn make_rpc_error<E: Debug>(err: E) -> RpcStatus {
RpcStatus::new(RpcStatusCode::UNKNOWN, Some(format!("{:?}", err)))
}
#[macro_export]
macro_rules! send_rpc_response {
($res:ident, $sink:ident, $label:ident, $timer:ident) => {{
let res = match $res {
Ok(resp) => {
IMPORT_RPC_DURATION
.with_label_values(&[$label, "ok"])
.observe($timer.elapsed_secs());
$sink.success(resp)
}
Err(e) => {
IMPORT_RPC_DURATION
.with_label_values(&[$label, "error"])
.observe($timer.elapsed_secs());
error_inc($label, &e);
$sink.fail(make_rpc_error(e))
}
};
let _ = res.map_err(|e| warn!("send rpc response"; "err" => %e)).await;
}};
}