Skip to content

Commit

Permalink
Implement correct prometheus metrics for FVR
Browse files Browse the repository at this point in the history
  • Loading branch information
samdealy committed Jan 3, 2023
1 parent 50b9e31 commit 9b2d8a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions fog/view/server/src/fog_view_router_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use mc_fog_api::{
use mc_fog_uri::FogViewStoreUri;
use mc_fog_view_enclave_api::ViewEnclaveProxy;
use mc_util_grpc::{check_request_chain_id, rpc_logger, send_result, Authenticator};
use mc_util_metrics::SVC_COUNTERS;
use mc_util_metrics::{ServiceMetrics, SVC_COUNTERS};
use std::{
collections::HashMap,
sync::{Arc, RwLock},
Expand Down Expand Up @@ -64,13 +64,14 @@ where
requests: RequestStream<FogViewRouterRequest>,
responses: DuplexSink<FogViewRouterResponse>,
) {
let _timer = SVC_COUNTERS.req(&ctx);
mc_common::logger::scoped_global_logger(&rpc_logger(&ctx, &self.logger), |logger| {
let logger = logger.clone();
// TODO: Confirm that we don't need to perform the authenticator logic. I think
// we don't because of streaming...
let shard_clients = self.shard_clients.read().expect("RwLock poisoned");
let method_name = ServiceMetrics::get_method_name(&ctx);
let future = router_request_handler::handle_requests(
method_name,
shard_clients.values().cloned().collect(),
self.enclave.clone(),
requests,
Expand Down
12 changes: 11 additions & 1 deletion fog/view/server/src/router_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ use mc_fog_api::{
use mc_fog_types::view::MultiViewStoreQueryResponse;
use mc_fog_uri::FogViewStoreUri;
use mc_fog_view_enclave_api::ViewEnclaveProxy;
use mc_util_grpc::{rpc_invalid_arg_error, ConnectionUriGrpcioChannel};
use mc_util_grpc::{rpc_invalid_arg_error, ConnectionUriGrpcioChannel, ResponseStatus};
use mc_util_metrics::{GrpcMethodName, SVC_COUNTERS};
use mc_util_uri::ConnectionUri;
use std::sync::Arc;

const RETRY_COUNT: usize = 3;

/// Handles a series of requests sent by the Fog Router client.
pub async fn handle_requests<E>(
method_name: GrpcMethodName,
shard_clients: Vec<Arc<FogViewStoreApiClient>>,
enclave: E,
mut requests: RequestStream<FogViewRouterRequest>,
Expand All @@ -34,13 +36,21 @@ where
E: ViewEnclaveProxy,
{
while let Some(request) = requests.try_next().await? {
let _timer = SVC_COUNTERS.req_impl(&method_name);
let result = handle_request(
request,
shard_clients.clone(),
enclave.clone(),
logger.clone(),
)
.await;

// Perform prometheus logic before the match statement to ensure that
// this logic is executed.
let response_status = ResponseStatus::new(&result);
SVC_COUNTERS.resp_impl(&method_name, response_status.is_success);
SVC_COUNTERS.status_code_impl(&method_name, response_status.code);

match result {
Ok(response) => responses.send((response, WriteFlags::default())).await?,
Err(rpc_status) => return responses.fail(rpc_status).await,
Expand Down
2 changes: 1 addition & 1 deletion util/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use prometheus::{
register, register_histogram, Histogram, HistogramOpts, HistogramVec, IntCounter,
IntCounterVec, IntGauge, IntGaugeVec, Opts,
};
pub use service_metrics::ServiceMetrics;
pub use service_metrics::{GrpcMethodName, ServiceMetrics};

lazy_static! {
pub static ref SVC_COUNTERS: ServiceMetrics = ServiceMetrics::new_and_registered();
Expand Down

0 comments on commit 9b2d8a3

Please sign in to comment.