mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-06 21:33:14 +00:00
refactor: centralize RIO HTTP runtime sources (#3795)
This commit is contained in:
@@ -20,12 +20,8 @@ use pin_project_lite::pin_project;
|
||||
use reqwest::{Certificate, Client, Identity, Method, RequestBuilder};
|
||||
use rustfs_io_metrics::internode_metrics::{
|
||||
INTERNODE_OPERATION_PUT_FILE_STREAM, INTERNODE_OPERATION_READ_FILE_STREAM, INTERNODE_OPERATION_WALK_DIR,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP, global_internode_metrics,
|
||||
};
|
||||
use rustfs_tls_runtime::{
|
||||
load_cert_bundle_der_bytes, load_global_outbound_tls_generation, load_global_outbound_tls_state,
|
||||
record_tls_consumer_stale_generation,
|
||||
};
|
||||
use rustfs_tls_runtime::load_cert_bundle_der_bytes;
|
||||
use rustfs_utils::get_env_opt_str;
|
||||
use rustls_pki_types::pem::PemObject;
|
||||
use std::io::IoSlice;
|
||||
@@ -303,7 +299,7 @@ async fn get_http_client(url: &str) -> Client {
|
||||
|
||||
// Fast path: check generation first (cheap atomic read) to avoid cloning
|
||||
// the full PEM + identity bytes when the TLS state hasn't changed.
|
||||
let generation = load_global_outbound_tls_generation().0;
|
||||
let generation = crate::http_runtime_sources::outbound_tls_generation();
|
||||
|
||||
let guard = CLIENT_CACHE.lock().await;
|
||||
if let Some(cached) = guard.as_ref() {
|
||||
@@ -314,12 +310,12 @@ async fn get_http_client(url: &str) -> Client {
|
||||
cached.client.clone()
|
||||
};
|
||||
}
|
||||
record_tls_consumer_stale_generation("rio_http_reader");
|
||||
crate::http_runtime_sources::record_stale_outbound_tls_generation("rio_http_reader");
|
||||
}
|
||||
drop(guard);
|
||||
|
||||
// Cache miss or stale generation — load full outbound TLS state.
|
||||
let outbound_tls = load_global_outbound_tls_state().await;
|
||||
let outbound_tls = crate::http_runtime_sources::outbound_tls_state().await;
|
||||
|
||||
let client = build_http_client(false, &outbound_tls).await;
|
||||
let local_client = build_http_client(true, &outbound_tls).await;
|
||||
@@ -734,11 +730,7 @@ fn record_internode_outgoing_request(track: bool, operation: Option<&'static str
|
||||
return;
|
||||
}
|
||||
|
||||
match operation {
|
||||
Some(operation) => global_internode_metrics()
|
||||
.record_outgoing_request_for_operation_and_backend(operation, INTERNODE_TRANSPORT_BACKEND_TCP_HTTP),
|
||||
None => global_internode_metrics().record_outgoing_request(),
|
||||
}
|
||||
crate::http_runtime_sources::record_outgoing_request(operation);
|
||||
}
|
||||
|
||||
fn record_internode_sent_bytes(track: bool, operation: Option<&'static str>, bytes: usize) {
|
||||
@@ -746,14 +738,7 @@ fn record_internode_sent_bytes(track: bool, operation: Option<&'static str>, byt
|
||||
return;
|
||||
}
|
||||
|
||||
match operation {
|
||||
Some(operation) => global_internode_metrics().record_sent_bytes_for_operation_and_backend(
|
||||
operation,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP,
|
||||
bytes,
|
||||
),
|
||||
None => global_internode_metrics().record_sent_bytes(bytes),
|
||||
}
|
||||
crate::http_runtime_sources::record_sent_bytes(operation, bytes);
|
||||
}
|
||||
|
||||
fn record_internode_recv_bytes(track: bool, operation: Option<&'static str>, bytes: usize) {
|
||||
@@ -761,14 +746,7 @@ fn record_internode_recv_bytes(track: bool, operation: Option<&'static str>, byt
|
||||
return;
|
||||
}
|
||||
|
||||
match operation {
|
||||
Some(operation) => global_internode_metrics().record_recv_bytes_for_operation_and_backend(
|
||||
operation,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP,
|
||||
bytes,
|
||||
),
|
||||
None => global_internode_metrics().record_recv_bytes(bytes),
|
||||
}
|
||||
crate::http_runtime_sources::record_recv_bytes(operation, bytes);
|
||||
}
|
||||
|
||||
fn record_internode_error(track: bool, operation: Option<&'static str>) {
|
||||
@@ -776,12 +754,7 @@ fn record_internode_error(track: bool, operation: Option<&'static str>) {
|
||||
return;
|
||||
}
|
||||
|
||||
match operation {
|
||||
Some(operation) => {
|
||||
global_internode_metrics().record_error_for_operation_and_backend(operation, INTERNODE_TRANSPORT_BACKEND_TCP_HTTP)
|
||||
}
|
||||
None => global_internode_metrics().record_error(),
|
||||
}
|
||||
crate::http_runtime_sources::record_error(operation);
|
||||
}
|
||||
|
||||
fn record_internode_classified_error(track: bool, operation: Option<&'static str>, classification: InternodeHttpErrorKind) {
|
||||
@@ -790,11 +763,7 @@ fn record_internode_classified_error(track: bool, operation: Option<&'static str
|
||||
}
|
||||
|
||||
if let Some(operation) = operation {
|
||||
global_internode_metrics().record_classified_error_for_operation_and_backend(
|
||||
operation,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP,
|
||||
classification.metric_label(),
|
||||
);
|
||||
crate::http_runtime_sources::record_classified_error(operation, classification.metric_label());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// 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::{INTERNODE_TRANSPORT_BACKEND_TCP_HTTP, global_internode_metrics};
|
||||
use rustfs_tls_runtime::{
|
||||
GlobalPublishedOutboundTlsState, load_global_outbound_tls_generation, load_global_outbound_tls_state,
|
||||
record_tls_consumer_stale_generation,
|
||||
};
|
||||
|
||||
pub(crate) fn outbound_tls_generation() -> u64 {
|
||||
load_global_outbound_tls_generation().0
|
||||
}
|
||||
|
||||
pub(crate) async fn outbound_tls_state() -> GlobalPublishedOutboundTlsState {
|
||||
load_global_outbound_tls_state().await
|
||||
}
|
||||
|
||||
pub(crate) fn record_stale_outbound_tls_generation(consumer: &'static str) {
|
||||
record_tls_consumer_stale_generation(consumer);
|
||||
}
|
||||
|
||||
pub(crate) fn record_outgoing_request(operation: Option<&'static str>) {
|
||||
match operation {
|
||||
Some(operation) => global_internode_metrics()
|
||||
.record_outgoing_request_for_operation_and_backend(operation, INTERNODE_TRANSPORT_BACKEND_TCP_HTTP),
|
||||
None => global_internode_metrics().record_outgoing_request(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_sent_bytes(operation: Option<&'static str>, bytes: usize) {
|
||||
match operation {
|
||||
Some(operation) => global_internode_metrics().record_sent_bytes_for_operation_and_backend(
|
||||
operation,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP,
|
||||
bytes,
|
||||
),
|
||||
None => global_internode_metrics().record_sent_bytes(bytes),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_recv_bytes(operation: Option<&'static str>, bytes: usize) {
|
||||
match operation {
|
||||
Some(operation) => global_internode_metrics().record_recv_bytes_for_operation_and_backend(
|
||||
operation,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP,
|
||||
bytes,
|
||||
),
|
||||
None => global_internode_metrics().record_recv_bytes(bytes),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_error(operation: Option<&'static str>) {
|
||||
match operation {
|
||||
Some(operation) => {
|
||||
global_internode_metrics().record_error_for_operation_and_backend(operation, INTERNODE_TRANSPORT_BACKEND_TCP_HTTP)
|
||||
}
|
||||
None => global_internode_metrics().record_error(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_classified_error(operation: &'static str, classification: &'static str) {
|
||||
global_internode_metrics().record_classified_error_for_operation_and_backend(
|
||||
operation,
|
||||
INTERNODE_TRANSPORT_BACKEND_TCP_HTTP,
|
||||
classification,
|
||||
);
|
||||
}
|
||||
@@ -109,6 +109,7 @@ pub use writer::*;
|
||||
|
||||
mod http_reader;
|
||||
pub use http_reader::*;
|
||||
mod http_runtime_sources;
|
||||
|
||||
pub use compress_index::{Index, TryGetIndex};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user