mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 00:26:53 +00:00
refactor: centralize network client runtime sources (#3796)
This commit is contained in:
@@ -16,11 +16,10 @@
|
||||
// scoped to that module so generated internals do not relax lints elsewhere.
|
||||
#[allow(unsafe_code)]
|
||||
mod generated;
|
||||
mod runtime_sources;
|
||||
|
||||
use proto_gen::node_service::node_service_client::NodeServiceClient;
|
||||
use rustfs_common::{GLOBAL_CONN_MAP, evict_connection_with_log_level};
|
||||
use rustfs_io_metrics::internode_metrics::global_internode_metrics;
|
||||
use rustfs_tls_runtime::{load_global_outbound_tls_state, record_tls_consumer_stale_generation};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
@@ -134,7 +133,7 @@ pub async fn create_new_channel(addr: &str) -> Result<Channel, Box<dyn Error>> {
|
||||
// Overall timeout for any RPC - fail fast on unresponsive peers
|
||||
.timeout(rpc_timeout);
|
||||
|
||||
let outbound_tls = load_global_outbound_tls_state().await;
|
||||
let outbound_tls = runtime_sources::outbound_tls_state().await;
|
||||
let generation = outbound_tls.generation.0;
|
||||
let mut stale_generation = false;
|
||||
{
|
||||
@@ -180,11 +179,11 @@ pub async fn create_new_channel(addr: &str) -> Result<Channel, Box<dyn Error>> {
|
||||
|
||||
let channel = match connector.connect().await {
|
||||
Ok(channel) => {
|
||||
global_internode_metrics().record_dial_result(dial_started_at.elapsed(), true);
|
||||
runtime_sources::record_grpc_dial_result(dial_started_at.elapsed(), true);
|
||||
channel
|
||||
}
|
||||
Err(err) => {
|
||||
global_internode_metrics().record_dial_result(dial_started_at.elapsed(), false);
|
||||
runtime_sources::record_grpc_dial_result(dial_started_at.elapsed(), false);
|
||||
return Err(err.into());
|
||||
}
|
||||
};
|
||||
@@ -199,7 +198,7 @@ pub async fn create_new_channel(addr: &str) -> Result<Channel, Box<dyn Error>> {
|
||||
generation_cache.insert(addr.to_string(), generation);
|
||||
}
|
||||
if stale_generation {
|
||||
record_tls_consumer_stale_generation("protos_grpc_channel");
|
||||
runtime_sources::record_stale_grpc_channel_tls_generation();
|
||||
}
|
||||
|
||||
debug!("Successfully created and cached gRPC channel to: {}", addr);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use rustfs_io_metrics::internode_metrics::global_internode_metrics;
|
||||
use rustfs_tls_runtime::{GlobalPublishedOutboundTlsState, load_global_outbound_tls_state, record_tls_consumer_stale_generation};
|
||||
use std::time::Duration;
|
||||
|
||||
const PROTOS_GRPC_CHANNEL_TLS_CONSUMER: &str = "protos_grpc_channel";
|
||||
|
||||
pub(crate) async fn outbound_tls_state() -> GlobalPublishedOutboundTlsState {
|
||||
load_global_outbound_tls_state().await
|
||||
}
|
||||
|
||||
pub(crate) fn record_stale_grpc_channel_tls_generation() {
|
||||
record_tls_consumer_stale_generation(PROTOS_GRPC_CHANNEL_TLS_CONSUMER);
|
||||
}
|
||||
|
||||
pub(crate) fn record_grpc_dial_result(duration: Duration, success: bool) {
|
||||
global_internode_metrics().record_dial_result(duration, success);
|
||||
}
|
||||
Reference in New Issue
Block a user