Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Traffic Control] Add metrics for policy config settings #20810

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/sui-core/src/traffic_controller/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub struct TrafficControllerMetrics {
pub highest_proxied_spam_rate: IntGauge,
pub highest_direct_error_rate: IntGauge,
pub highest_proxied_error_rate: IntGauge,
pub spam_client_threshold: IntGauge,
pub error_client_threshold: IntGauge,
pub spam_proxied_client_threshold: IntGauge,
pub error_proxied_client_threshold: IntGauge,
}

impl TrafficControllerMetrics {
Expand Down Expand Up @@ -129,6 +133,30 @@ impl TrafficControllerMetrics {
registry
)
.unwrap(),
spam_client_threshold: register_int_gauge_with_registry!(
"spam_client_threshold",
"Spam client threshold",
registry
)
.unwrap(),
error_client_threshold: register_int_gauge_with_registry!(
"error_client_threshold",
"Error client threshold",
registry
)
.unwrap(),
spam_proxied_client_threshold: register_int_gauge_with_registry!(
"spam_proxied_client_threshold",
"Spam proxied client threshold",
registry
)
.unwrap(),
error_proxied_client_threshold: register_int_gauge_with_registry!(
"error_proxied_client_threshold",
"Error proxied client threshold",
registry
)
.unwrap(),
}
}

Expand Down
25 changes: 24 additions & 1 deletion crates/sui-core/src/traffic_controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use mysten_metrics::spawn_monitored_task;
use rand::Rng;
use std::fmt::Debug;
use std::time::{Duration, Instant, SystemTime};
use sui_types::traffic_control::{PolicyConfig, RemoteFirewallConfig, Weight};
use sui_types::traffic_control::{PolicyConfig, PolicyType, RemoteFirewallConfig, Weight};
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, error, info, trace, warn};
Expand Down Expand Up @@ -110,6 +110,7 @@ impl TrafficController {
fw_config: Option<RemoteFirewallConfig>,
) -> Self {
let metrics = Arc::new(metrics);
Self::set_policy_config_metrics(&policy_config, metrics.clone());
let (tx, rx) = mpsc::channel(policy_config.channel_capacity);
// Memoized drainfile existence state. This is passed into delegation
// funtions to prevent them from continuing to populate blocklists
Expand Down Expand Up @@ -151,6 +152,28 @@ impl TrafficController {
}
}

fn set_policy_config_metrics(
policy_config: &PolicyConfig,
metrics: Arc<TrafficControllerMetrics>,
) {
if let PolicyType::FreqThreshold(config) = &policy_config.spam_policy_type {
metrics
.spam_client_threshold
.set(config.client_threshold as i64);
metrics
.spam_proxied_client_threshold
.set(config.proxied_client_threshold as i64);
}
if let PolicyType::FreqThreshold(config) = &policy_config.error_policy_type {
metrics
.error_client_threshold
.set(config.client_threshold as i64);
metrics
.error_proxied_client_threshold
.set(config.proxied_client_threshold as i64);
}
}

pub fn init_for_test(
policy_config: PolicyConfig,
fw_config: Option<RemoteFirewallConfig>,
Expand Down
Loading