mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
http: upgrade metrics crate to 0.22
This commit is contained in:
parent
fe6a7ef8b5
commit
c7f7f010ca
6 changed files with 90 additions and 161 deletions
|
|
@ -26,9 +26,9 @@ use once_cell::sync::Lazy;
|
|||
use crate::common::*;
|
||||
use crate::config::Config;
|
||||
|
||||
use super::request::{parse_request, RequestParseError};
|
||||
#[cfg(feature = "metrics")]
|
||||
use super::{peer_addr_to_ip_version_str, WORKER_INDEX};
|
||||
use super::peer_addr_to_ip_version_str;
|
||||
use super::request::{parse_request, RequestParseError};
|
||||
|
||||
const REQUEST_BUFFER_SIZE: usize = 2048;
|
||||
const RESPONSE_BUFFER_SIZE: usize = 4096;
|
||||
|
|
@ -67,6 +67,7 @@ pub enum ConnectionError {
|
|||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) async fn run_connection(
|
||||
config: Rc<Config>,
|
||||
access_list: Arc<AccessListArcSwap>,
|
||||
|
|
@ -75,6 +76,7 @@ pub(super) async fn run_connection(
|
|||
opt_tls_config: Option<Arc<ArcSwap<RustlsConfig>>>,
|
||||
valid_until: Rc<RefCell<ValidUntil>>,
|
||||
stream: TcpStream,
|
||||
worker_index: usize,
|
||||
) -> Result<(), ConnectionError> {
|
||||
let access_list_cache = create_access_list_cache(&access_list);
|
||||
let request_buffer = Box::new([0u8; REQUEST_BUFFER_SIZE]);
|
||||
|
|
@ -114,6 +116,7 @@ pub(super) async fn run_connection(
|
|||
request_buffer_position: 0,
|
||||
response_buffer,
|
||||
stream,
|
||||
worker_index_string: worker_index.to_string(),
|
||||
};
|
||||
|
||||
conn.run().await
|
||||
|
|
@ -130,6 +133,7 @@ pub(super) async fn run_connection(
|
|||
request_buffer_position: 0,
|
||||
response_buffer,
|
||||
stream,
|
||||
worker_index_string: worker_index.to_string(),
|
||||
};
|
||||
|
||||
conn.run().await
|
||||
|
|
@ -148,6 +152,7 @@ struct Connection<S> {
|
|||
request_buffer_position: usize,
|
||||
response_buffer: Box<[u8; RESPONSE_BUFFER_SIZE]>,
|
||||
stream: S,
|
||||
worker_index_string: String,
|
||||
}
|
||||
|
||||
impl<S> Connection<S>
|
||||
|
|
@ -244,12 +249,13 @@ where
|
|||
match request {
|
||||
Request::Announce(request) => {
|
||||
#[cfg(feature = "metrics")]
|
||||
::metrics::increment_counter!(
|
||||
::metrics::counter!(
|
||||
"aquatic_requests_total",
|
||||
"type" => "announce",
|
||||
"ip_version" => peer_addr_to_ip_version_str(&peer_addr),
|
||||
"worker_index" => WORKER_INDEX.with(|index| index.get()).to_string(),
|
||||
);
|
||||
"worker_index" => self.worker_index_string.clone(),
|
||||
)
|
||||
.increment(1);
|
||||
|
||||
let info_hash = request.info_hash;
|
||||
|
||||
|
|
@ -291,12 +297,13 @@ where
|
|||
}
|
||||
Request::Scrape(ScrapeRequest { info_hashes }) => {
|
||||
#[cfg(feature = "metrics")]
|
||||
::metrics::increment_counter!(
|
||||
::metrics::counter!(
|
||||
"aquatic_requests_total",
|
||||
"type" => "scrape",
|
||||
"ip_version" => peer_addr_to_ip_version_str(&peer_addr),
|
||||
"worker_index" => WORKER_INDEX.with(|index| index.get()).to_string(),
|
||||
);
|
||||
"worker_index" => self.worker_index_string.clone(),
|
||||
)
|
||||
.increment(1);
|
||||
|
||||
let mut info_hashes_by_worker: BTreeMap<usize, Vec<InfoHash>> = BTreeMap::new();
|
||||
|
||||
|
|
@ -438,12 +445,13 @@ where
|
|||
.opt_peer_addr
|
||||
.expect("peer addr should already have been extracted by now");
|
||||
|
||||
::metrics::increment_counter!(
|
||||
::metrics::counter!(
|
||||
"aquatic_responses_total",
|
||||
"type" => response_type,
|
||||
"ip_version" => peer_addr_to_ip_version_str(&peer_addr),
|
||||
"worker_index" => WORKER_INDEX.with(|index| index.get()).to_string(),
|
||||
);
|
||||
"worker_index" => self.worker_index_string.clone(),
|
||||
)
|
||||
.increment(1);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@ use crate::common::*;
|
|||
use crate::config::Config;
|
||||
use crate::workers::socket::connection::{run_connection, ConnectionError};
|
||||
|
||||
#[cfg(feature = "metrics")]
|
||||
thread_local! { static WORKER_INDEX: ::std::cell::Cell<usize> = Default::default() }
|
||||
|
||||
struct ConnectionHandle {
|
||||
close_conn_sender: LocalSender<()>,
|
||||
valid_until: Rc<RefCell<ValidUntil>>,
|
||||
|
|
@ -44,9 +41,6 @@ pub async fn run_socket_worker(
|
|||
server_start_instant: ServerStartInstant,
|
||||
worker_index: usize,
|
||||
) {
|
||||
#[cfg(feature = "metrics")]
|
||||
WORKER_INDEX.with(|index| index.set(worker_index));
|
||||
|
||||
let config = Rc::new(config);
|
||||
let access_list = state.access_list;
|
||||
|
||||
|
|
@ -93,12 +87,14 @@ pub async fn run_socket_worker(
|
|||
)
|
||||
async move {
|
||||
#[cfg(feature = "metrics")]
|
||||
::metrics::increment_gauge!(
|
||||
let active_connections_gauge = ::metrics::gauge!(
|
||||
"aquatic_active_connections",
|
||||
1.0,
|
||||
"worker_index" => worker_index.to_string(),
|
||||
);
|
||||
|
||||
#[cfg(feature = "metrics")]
|
||||
active_connections_gauge.increment(1.0);
|
||||
|
||||
let f1 = async { run_connection(
|
||||
config,
|
||||
access_list,
|
||||
|
|
@ -107,6 +103,7 @@ pub async fn run_socket_worker(
|
|||
opt_tls_config,
|
||||
valid_until.clone(),
|
||||
stream,
|
||||
worker_index,
|
||||
).await
|
||||
};
|
||||
let f2 = async {
|
||||
|
|
@ -118,11 +115,7 @@ pub async fn run_socket_worker(
|
|||
let result = race(f1, f2).await;
|
||||
|
||||
#[cfg(feature = "metrics")]
|
||||
::metrics::decrement_gauge!(
|
||||
"aquatic_active_connections",
|
||||
1.0,
|
||||
"worker_index" => worker_index.to_string(),
|
||||
);
|
||||
active_connections_gauge.decrement(1.0);
|
||||
|
||||
match result {
|
||||
Ok(()) => (),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue