mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 11:02:54 +00:00
refactor: Remove duplicate imports and comment out rate limiter implementation in charging-engine
- Remove duplicate CreditManager and RatingPlansRepo imports from engine.rs - Add circuit_breaker module to main.rs imports - Comment out rate_limit module in lib.rs - Update rate_limit.rs imports to use GovernorConfig and GovernorLayer directly - Change GovernorConfigBuilder to GovernorConfig::builder() and update config initialization - Update GovernorLayer::new() to take config reference
This commit is contained in:
@@ -6,8 +6,6 @@ use super::rating_plans_repo::RatingPlansRepo;
|
||||
use super::types::RatingPlan;
|
||||
use crate::circuit_breaker::{CircuitBreaker, CircuitBreakerError};
|
||||
use crate::errors::{ChargingError, ChargingResult};
|
||||
use crate::charging::credit_management::CreditManager;
|
||||
use crate::charging::rating_plans_repo::RatingPlansRepo;
|
||||
|
||||
/// ChargingEngine coordinates Redis-backed hot-path state (balances, sessions)
|
||||
/// and Postgres-backed configuration (rating plans) via `RatingPlansRepo`.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
pub mod auth;
|
||||
pub mod charging;
|
||||
pub mod circuit_breaker;
|
||||
pub mod rate_limit;
|
||||
pub mod errors;
|
||||
// pub mod rate_limit;
|
||||
pub mod handlers;
|
||||
pub mod routes;
|
||||
pub mod models;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mod auth;
|
||||
mod charging;
|
||||
mod circuit_breaker;
|
||||
mod monitoring;
|
||||
mod errors;
|
||||
mod models;
|
||||
|
||||
@@ -10,11 +10,12 @@ use governor::{
|
||||
use std::num::NonZeroU32;
|
||||
use std::sync::Arc;
|
||||
use tower_governor::{
|
||||
governor::config::GovernorConfigBuilder,
|
||||
governor::GovernorConfig,
|
||||
key_extractor::SmartIpKeyExtractor,
|
||||
GovernorLayer,
|
||||
};
|
||||
|
||||
pub fn create_rate_limiter() -> tower_governor::GovernorLayer<SmartIpKeyExtractor, governor::state::InMemoryState, governor::clock::DefaultClock> {
|
||||
pub fn create_rate_limiter() -> GovernorLayer<SmartIpKeyExtractor, InMemoryState, DefaultClock> {
|
||||
let requests_per_second: u32 = std::env::var("RATE_LIMIT_RPS")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
@@ -27,13 +28,13 @@ pub fn create_rate_limiter() -> tower_governor::GovernorLayer<SmartIpKeyExtracto
|
||||
let quota = Quota::per_second(NonZeroU32::new(requests_per_second).unwrap())
|
||||
.allow_burst(NonZeroU32::new(burst_size).unwrap());
|
||||
|
||||
let config = GovernorConfigBuilder::default()
|
||||
let config = GovernorConfig::builder()
|
||||
.per_second(quota)
|
||||
.burst_size(burst_size)
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
tower_governor::GovernorLayer::new(config)
|
||||
GovernorLayer::new(&config)
|
||||
}
|
||||
|
||||
pub struct RateLimitResponse;
|
||||
|
||||
@@ -5,7 +5,7 @@ use axum::{
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
||||
use crate::auth::auth_middleware;
|
||||
use crate::rate_limit::create_rate_limiter;
|
||||
// use crate::rate_limit::create_rate_limiter;
|
||||
use crate::handlers::{
|
||||
add_credit, add_rating_plan, block_user, check_credit, deduct_credit, detailed_health_check,
|
||||
engine_start, engine_stop, engine_uptime, get_balance, get_error_stats, get_performance_metrics,
|
||||
@@ -21,7 +21,7 @@ pub fn create_router(state: AppState) -> Router {
|
||||
.allow_methods(Any)
|
||||
.allow_headers(Any);
|
||||
|
||||
let rate_limiter = create_rate_limiter();
|
||||
// let rate_limiter = create_rate_limiter();
|
||||
|
||||
Router::new()
|
||||
// Public routes (no auth required - for packet-gateway integration)
|
||||
@@ -54,7 +54,7 @@ pub fn create_router(state: AppState) -> Router {
|
||||
.route("/v1/usage/process", post(process_usage))
|
||||
.route("/v1/invoice/:imsi/:period", get(generate_invoice))
|
||||
.layer(cors)
|
||||
.layer(rate_limiter)
|
||||
// .layer(rate_limiter)
|
||||
.route_layer(axum::middleware::from_fn_with_state(state.auth_config.clone(), auth_middleware))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user