Skip to content

Commit 00f475f

Browse files
author
Auto Merge Bot
committed
fix: Apply cargo fmt to rate_limit module
Fix formatting issues in rate_limit module files: - config.rs - dashboard.rs - manager.rs - mod.rs - quota.rs - store.rs This fixes the cargo fmt check failure.
1 parent ba2ad6f commit 00f475f

6 files changed

Lines changed: 22 additions & 33 deletions

File tree

orchestrator/src/rate_limit/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ mod tests {
188188
#[test]
189189
fn test_quota_reset_duration() {
190190
let config = RateLimitConfig::default();
191-
assert_eq!(config.quota_reset_duration(), Duration::from_secs(24 * 3600));
191+
assert_eq!(
192+
config.quota_reset_duration(),
193+
Duration::from_secs(24 * 3600)
194+
);
192195
}
193196

194197
#[test]
@@ -198,4 +201,4 @@ mod tests {
198201
let parsed: RateLimitConfig = serde_json::from_str(&json).unwrap();
199202
assert_eq!(config.default_api_limit, parsed.default_api_limit);
200203
}
201-
}
204+
}

orchestrator/src/rate_limit/dashboard.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,9 @@ impl DashboardBuilder {
110110
let entity_id = parts[1].to_string();
111111

112112
if entity_type_str == "User" {
113-
user_stats_map
114-
.entry(entity_id)
115-
.or_default()
116-
.push(stat);
113+
user_stats_map.entry(entity_id).or_default().push(stat);
117114
} else if entity_type_str == "Agent" {
118-
agent_stats_map
119-
.entry(entity_id)
120-
.or_default()
121-
.push(stat);
115+
agent_stats_map.entry(entity_id).or_default().push(stat);
122116
}
123117
}
124118
}
@@ -157,11 +151,7 @@ impl DashboardBuilder {
157151
let summary = self.build_summary(&user_stats, &agent_stats, &history);
158152

159153
// Get recent history (last 100 records)
160-
let recent_history: Vec<UsageRecord> = history
161-
.into_iter()
162-
.rev()
163-
.take(100)
164-
.collect();
154+
let recent_history: Vec<UsageRecord> = history.into_iter().rev().take(100).collect();
165155

166156
DashboardData {
167157
timestamp: chrono::Utc::now(),
@@ -218,10 +208,7 @@ impl DashboardBuilder {
218208
}
219209
}
220210

221-
let rate_limited_count = history
222-
.iter()
223-
.filter(|r| !r.success)
224-
.count() as u64;
211+
let rate_limited_count = history.iter().filter(|r| !r.success).count() as u64;
225212

226213
let avg_utilization_percent = if quota_count > 0 {
227214
total_utilization / quota_count as f64
@@ -435,4 +422,4 @@ mod tests {
435422
assert_eq!(parsed.entity_id, "user-123");
436423
assert_eq!(parsed.entity_type, EntityType::User);
437424
}
438-
}
425+
}

orchestrator/src/rate_limit/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,4 @@ mod tests {
479479
assert_eq!(denied.retry_after_secs, Some(60));
480480
assert_eq!(denied.reason, Some("Rate limit exceeded".to_string()));
481481
}
482-
}
482+
}

orchestrator/src/rate_limit/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
//! ```
2929
3030
pub mod config;
31+
pub mod dashboard;
3132
pub mod manager;
3233
pub mod quota;
3334
pub mod store;
34-
pub mod dashboard;
3535

3636
pub use config::RateLimitConfig;
37+
pub use dashboard::DashboardData;
3738
pub use manager::RateLimitManager;
3839
pub use quota::{Quota, QuotaType, UsageStats};
3940
pub use store::QuotaStore;
40-
pub use dashboard::DashboardData;

orchestrator/src/rate_limit/quota.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl QuotaType {
3232
/// Get the refill rate (tokens per second)
3333
pub fn default_refill_rate(&self) -> f64 {
3434
match self {
35-
QuotaType::ApiCalls => 100.0 / 60.0, // 100 per minute
36-
QuotaType::VmSpawn => 10.0 / 3600.0, // 10 per hour
35+
QuotaType::ApiCalls => 100.0 / 60.0, // 100 per minute
36+
QuotaType::VmSpawn => 10.0 / 3600.0, // 10 per hour
3737
QuotaType::ApprovalRequest => 50.0 / 3600.0, // 50 per hour
3838
}
3939
}
@@ -450,4 +450,4 @@ mod tests {
450450
// Should need 2 seconds to get 20 tokens at 10 tokens/sec
451451
assert!(time.as_secs_f64() >= 1.9 && time.as_secs_f64() <= 2.1);
452452
}
453-
}
453+
}

orchestrator/src/rate_limit/store.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ impl QuotaStore {
120120
let mut quotas = self.quotas.write().await;
121121

122122
if !quotas.contains_key(key) {
123-
let quota_id = format!("{:?}-{}-{:?}", key.entity_type, key.entity_id, key.quota_type);
123+
let quota_id = format!(
124+
"{:?}-{}-{:?}",
125+
key.entity_type, key.entity_id, key.quota_type
126+
);
124127
let quota = Quota::new(key.quota_type, quota_id);
125128
quotas.insert(key.clone(), quota);
126129
}
@@ -168,11 +171,7 @@ impl QuotaStore {
168171
/// Get usage history for a key
169172
pub async fn get_usage_history(&self, key: &QuotaKey) -> Vec<UsageRecord> {
170173
let history = self.usage_history.read().await;
171-
history
172-
.iter()
173-
.filter(|r| &r.key == key)
174-
.cloned()
175-
.collect()
174+
history.iter().filter(|r| &r.key == key).cloned().collect()
176175
}
177176

178177
/// Get all usage history
@@ -335,4 +334,4 @@ mod tests {
335334
assert_eq!(key.entity_type, EntityType::Agent);
336335
assert_eq!(key.quota_type, QuotaType::VmSpawn);
337336
}
338-
}
337+
}

0 commit comments

Comments
 (0)