Skip to content

Commit

Permalink
[Traffic Control] Add metrics for policy config settings (#20810)
Browse files Browse the repository at this point in the history
## Description 

This will allow us to contextualize blocked request metrics from
community nodes given that they control their own configuration.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
williampsmith authored Jan 7, 2025
1 parent 332ef78 commit 338a4dd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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

0 comments on commit 338a4dd

Please sign in to comment.