Skip to content

Commit

Permalink
simplify stats cast
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Aug 16, 2023
1 parent 22c1085 commit 245eee3
Show file tree
Hide file tree
Showing 65 changed files with 127 additions and 337 deletions.
6 changes: 3 additions & 3 deletions g3bench/src/target/h1/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tokio::time::Instant;

use g3_http::client::HttpForwardRemoteResponse;
use g3_http::HttpBodyReader;
use g3_io_ext::{ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReader, LimitedWriter};
use g3_io_ext::{LimitedReader, LimitedWriter};

use super::{
BenchHttpArgs, BenchTaskContext, HttpHistogramRecorder, HttpRuntimeStats, ProcArgs,
Expand Down Expand Up @@ -103,13 +103,13 @@ impl HttpTaskContext {
r,
self.proc_args.tcp_sock_speed_limit.shift_millis,
self.proc_args.tcp_sock_speed_limit.max_south,
self.runtime_stats.clone() as ArcLimitedReaderStats,
self.runtime_stats.clone() as _,
);
let w = LimitedWriter::new(
w,
self.proc_args.tcp_sock_speed_limit.shift_millis,
self.proc_args.tcp_sock_speed_limit.max_north,
self.runtime_stats.clone() as ArcLimitedWriterStats,
self.runtime_stats.clone() as _,
);
Ok(SavedHttpForwardConnection::new(BufReader::new(r), w))
}
Expand Down
14 changes: 4 additions & 10 deletions g3proxy/src/escape/direct_fixed/ftp_connect/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ impl FtpControlRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcFtpTaskRemoteControlStats);
self.others.push(s as _);
}
}

pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) {
let s = Arc::new(self);
(
Arc::clone(&s) as ArcLimitedReaderStats,
s as ArcLimitedWriterStats,
)
(Arc::clone(&s) as _, s as _)
}
}

Expand Down Expand Up @@ -101,16 +98,13 @@ impl FtpTransferRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcFtpTaskRemoteTransferStats);
self.others.push(s as _);
}
}

pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) {
let s = Arc::new(self);
(
Arc::clone(&s) as ArcLimitedReaderStats,
s as ArcLimitedWriterStats,
)
(Arc::clone(&s) as _, s as _)
}
}

Expand Down
2 changes: 1 addition & 1 deletion g3proxy/src/escape/direct_fixed/http_forward/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl DirectFixedEscaper {
ups_r,
limit_config.shift_millis,
limit_config.max_south,
self.stats.for_limited_reader(),
self.stats.clone() as _,
r_wrapper_stats.into_reader(),
);
let ups_w = LimitedWriter::new(
Expand Down
4 changes: 2 additions & 2 deletions g3proxy/src/escape/direct_fixed/http_forward/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ impl DirectHttpMixedRemoteStats {

pub(super) fn push_user_io_stats_by_ref(&mut self, all: &[Arc<UserUpstreamTrafficStats>]) {
for s in all {
self.others.push(s.clone() as ArcHttpForwardTaskRemoteStats);
self.others.push(s.clone() as _);
}
}

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcHttpForwardTaskRemoteStats);
self.others.push(s as _);
}
}

Expand Down
11 changes: 3 additions & 8 deletions g3proxy/src/escape/direct_fixed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ use g3_types::net::{Host, OpensslTlsClientConfig, UpstreamAddr};
use g3_types::resolve::{ResolveRedirection, ResolveStrategy};
use g3_types::route::EgressPathSelection;

use super::{
ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperInternal, EscaperStats,
};
use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperInternal, EscaperStats};
use crate::auth::UserUpstreamTrafficStats;
use crate::config::escaper::direct_fixed::DirectFixedEscaperConfig;
use crate::config::escaper::{AnyEscaperConfig, EscaperConfig};
Expand Down Expand Up @@ -271,7 +269,7 @@ impl Escaper for DirectFixedEscaper {
}

fn get_escape_stats(&self) -> Option<ArcEscaperStats> {
Some(Arc::clone(&self.stats) as ArcEscaperStats)
Some(Arc::clone(&self.stats) as _)
}

async fn publish(&self, _data: String) -> anyhow::Result<()> {
Expand Down Expand Up @@ -328,10 +326,7 @@ impl Escaper for DirectFixedEscaper {
}

fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext {
let ctx = DirectHttpForwardContext::new(
Arc::clone(&self.stats) as ArcEscaperInternalStats,
escaper,
);
let ctx = DirectHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper);
Box::new(ctx)
}

Expand Down
14 changes: 1 addition & 13 deletions g3proxy/src/escape/direct_fixed/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use std::sync::Arc;

use arc_swap::ArcSwapOption;

use g3_io_ext::{
ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats,
};
use g3_io_ext::{LimitedReaderStats, LimitedWriterStats};
use g3_types::metrics::{MetricsName, StaticMetricsTags};
use g3_types::stats::{StatId, TcpIoSnapshot, UdpIoSnapshot};

Expand Down Expand Up @@ -52,16 +50,6 @@ impl DirectFixedEscaperStats {
}
}

#[inline]
pub(crate) fn for_limited_reader(self: &Arc<Self>) -> ArcLimitedReaderStats {
Arc::clone(self) as ArcLimitedReaderStats
}

#[inline]
pub(crate) fn for_limited_writer(self: &Arc<Self>) -> ArcLimitedWriterStats {
Arc::clone(self) as ArcLimitedWriterStats
}

pub(super) fn set_extra_tags(&self, tags: Option<Arc<StaticMetricsTags>>) {
self.extra_metrics_tags.store(tags);
}
Expand Down
7 changes: 2 additions & 5 deletions g3proxy/src/escape/direct_fixed/tcp_connect/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ impl DirectTcpMixedRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcTcpConnectionTaskRemoteStats);
self.others.push(s as _);
}
}

pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) {
let s = Arc::new(self);
(
Arc::clone(&s) as ArcLimitedReaderStats,
s as ArcLimitedWriterStats,
)
(Arc::clone(&s) as _, s as _)
}
}

Expand Down
4 changes: 2 additions & 2 deletions g3proxy/src/escape/direct_fixed/tls_connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ impl DirectFixedEscaper {
ups_r,
limit_config.shift_millis,
limit_config.max_south,
self.stats.for_limited_reader(),
self.stats.clone() as _,
);
let ups_w = LimitedWriter::new(
ups_w,
limit_config.shift_millis,
limit_config.max_north,
self.stats.for_limited_writer(),
self.stats.clone() as _,
);

let ssl = tls_config
Expand Down
7 changes: 2 additions & 5 deletions g3proxy/src/escape/direct_fixed/udp_connect/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,13 @@ impl DirectUdpConnectRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcUdpConnectTaskRemoteStats);
self.others.push(s as _);
}
}

pub(super) fn into_pair(self) -> (ArcLimitedRecvStats, ArcLimitedSendStats) {
let s = Arc::new(self);
(
Arc::clone(&s) as ArcLimitedRecvStats,
s as ArcLimitedSendStats,
)
(Arc::clone(&s) as _, s as _)
}
}

Expand Down
6 changes: 3 additions & 3 deletions g3proxy/src/escape/direct_fixed/udp_relay/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ impl DirectUdpRelayRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcUdpRelayTaskRemoteStats);
self.others.push(s as _);
}
}

pub(super) fn for_recv(self: &Arc<Self>) -> ArcLimitedRecvStats {
Arc::clone(self) as ArcLimitedRecvStats
Arc::clone(self) as _
}

pub(super) fn for_send(self: &Arc<Self>) -> ArcLimitedSendStats {
Arc::clone(self) as ArcLimitedSendStats
Arc::clone(self) as _
}
}

Expand Down
7 changes: 2 additions & 5 deletions g3proxy/src/escape/direct_float/ftp_connect/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ impl FtpControlRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcFtpTaskRemoteControlStats);
self.others.push(s as _);
}
}

pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) {
let s = Arc::new(self);
(
Arc::clone(&s) as ArcLimitedReaderStats,
s as ArcLimitedWriterStats,
)
(Arc::clone(&s) as _, s as _)
}
}

Expand Down
2 changes: 1 addition & 1 deletion g3proxy/src/escape/direct_float/http_forward/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl DirectFloatEscaper {
ups_r,
limit_config.shift_millis,
limit_config.max_south,
self.stats.for_limited_reader(),
self.stats.clone() as _,
r_wrapper_stats.into_reader(),
);
let ups_w = LimitedWriter::new(
Expand Down
14 changes: 1 addition & 13 deletions g3proxy/src/escape/direct_float/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use std::sync::Arc;

use arc_swap::ArcSwapOption;

use g3_io_ext::{
ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats,
};
use g3_io_ext::{LimitedReaderStats, LimitedWriterStats};
use g3_types::metrics::{MetricsName, StaticMetricsTags};
use g3_types::stats::{StatId, TcpIoSnapshot, UdpIoSnapshot};

Expand Down Expand Up @@ -52,16 +50,6 @@ impl DirectFloatEscaperStats {
}
}

#[inline]
pub(crate) fn for_limited_reader(self: &Arc<Self>) -> ArcLimitedReaderStats {
Arc::clone(self) as ArcLimitedReaderStats
}

#[inline]
pub(crate) fn for_limited_writer(self: &Arc<Self>) -> ArcLimitedWriterStats {
Arc::clone(self) as ArcLimitedWriterStats
}

pub(super) fn set_extra_tags(&self, tags: Option<Arc<StaticMetricsTags>>) {
self.extra_metrics_tags.store(tags);
}
Expand Down
7 changes: 2 additions & 5 deletions g3proxy/src/escape/direct_float/tcp_connect/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ impl DirectTcpMixedRemoteStats {

pub(super) fn push_user_io_stats(&mut self, all: Vec<Arc<UserUpstreamTrafficStats>>) {
for s in all {
self.others.push(s as ArcTcpConnectionTaskRemoteStats);
self.others.push(s as _);
}
}

pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) {
let s = Arc::new(self);
(
Arc::clone(&s) as ArcLimitedReaderStats,
s as ArcLimitedWriterStats,
)
(Arc::clone(&s) as _, s as _)
}
}

Expand Down
4 changes: 2 additions & 2 deletions g3proxy/src/escape/direct_float/tls_connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ impl DirectFloatEscaper {
ups_r,
limit_config.shift_millis,
limit_config.max_south,
self.stats.for_limited_reader(),
self.stats.clone() as _,
);
let ups_w = LimitedWriter::new(
ups_w,
limit_config.shift_millis,
limit_config.max_north,
self.stats.for_limited_writer(),
self.stats.clone() as _,
);

let ssl = tls_config
Expand Down
9 changes: 3 additions & 6 deletions g3proxy/src/escape/dummy_deny/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use g3_daemon::stat::remote::ArcTcpConnectionTaskRemoteStats;
use g3_types::metrics::MetricsName;
use g3_types::net::{OpensslTlsClientConfig, UpstreamAddr};

use super::{ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperInternal};
use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperInternal};
use crate::config::escaper::dummy_deny::DummyDenyEscaperConfig;
use crate::config::escaper::{AnyEscaperConfig, EscaperConfig};
use crate::module::ftp_over_http::{
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Escaper for DummyDenyEscaper {
}

fn get_escape_stats(&self) -> Option<ArcEscaperStats> {
Some(Arc::clone(&self.stats) as ArcEscaperStats)
Some(Arc::clone(&self.stats) as _)
}

async fn publish(&self, _data: String) -> anyhow::Result<()> {
Expand Down Expand Up @@ -153,10 +153,7 @@ impl Escaper for DummyDenyEscaper {
}

fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext {
let ctx = DirectHttpForwardContext::new(
Arc::clone(&self.stats) as ArcEscaperInternalStats,
escaper,
);
let ctx = DirectHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper);
Box::new(ctx)
}

Expand Down
9 changes: 3 additions & 6 deletions g3proxy/src/escape/proxy_float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use g3_daemon::stat::remote::ArcTcpConnectionTaskRemoteStats;
use g3_types::metrics::MetricsName;
use g3_types::net::{OpensslTlsClientConfig, UpstreamAddr};

use super::{ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperInternal};
use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperInternal};
use crate::config::escaper::proxy_float::ProxyFloatEscaperConfig;
use crate::config::escaper::{AnyEscaperConfig, EscaperConfig};
use crate::module::ftp_over_http::{
Expand Down Expand Up @@ -190,7 +190,7 @@ impl Escaper for ProxyFloatEscaper {
}

fn get_escape_stats(&self) -> Option<ArcEscaperStats> {
Some(Arc::clone(&self.stats) as ArcEscaperStats)
Some(Arc::clone(&self.stats) as _)
}

async fn publish(&self, data: String) -> anyhow::Result<()> {
Expand Down Expand Up @@ -272,10 +272,7 @@ impl Escaper for ProxyFloatEscaper {
}

fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext {
let ctx = DirectHttpForwardContext::new(
Arc::clone(&self.stats) as ArcEscaperInternalStats,
escaper,
);
let ctx = DirectHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper);
Box::new(ctx)
}

Expand Down
4 changes: 2 additions & 2 deletions g3proxy/src/escape/proxy_float/peer/http/tcp_connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ impl ProxyFloatHttpPeer {
r,
limit_config.shift_millis,
limit_config.max_south,
self.escaper_stats.for_limited_reader(),
self.escaper_stats.clone() as _,
);
let w = LimitedWriter::new(
w,
limit_config.shift_millis,
limit_config.max_north,
self.escaper_stats.for_limited_writer(),
self.escaper_stats.clone() as _,
);

Ok((r, w))
Expand Down
Loading

0 comments on commit 245eee3

Please sign in to comment.