Commit Graph
286 Commits
Author SHA1 Message Date
nutcas3 6d0c0ced1b feat: Add charging handler with credit management endpoints for IP-based operations
- Add ChargingHandler struct with ChargingEngineClient dependency
- Add NewChargingHandler constructor
- Add CheckCredit endpoint to validate sufficient credit for requested bytes
- Add GetBalance endpoint to retrieve current balance for an IP
- Add AddCredit endpoint to add bytes to an IP's credit
- Add DeductCredit endpoint to deduct bytes from an IP's credit
- Add IP parameter validation and JSON request binding
2026-04-25 03:28:51 +03:00
nutcas3 fff289f957 feat: Add Prometheus metrics endpoint to carrier-connector
- Add prometheus/client_golang v1.20.5 dependency to go.mod
- Add /api/v1/metrics endpoint using promhttp.Handler() wrapped with gin.WrapH
2026-04-25 03:28:26 +03:00
nutcas3 121cb60a62 feat: Add HTTP health check endpoints with Redis and eBPF status validation for packet-gateway
- Add axum, serde, serde_json, and chrono dependencies to Cargo.toml
- Add health_port CLI argument (defaults to 8081)
- Add /health endpoint returning basic health status
- Add /health/live endpoint for liveness checks (always returns alive if service is running)
- Add /health/ready endpoint for readiness checks with Redis connectivity and eBPF attachment validation
- Add AtomicBool to track eBPF attachment status across
2026-04-25 03:25:01 +03:00
nutcas3 8e40a54d8b feat: Add liveness and readiness health check endpoints with database connectivity validation
- Add Ping method to PostgresProfileStore to check database connection status
- Add Ping method to ProfileRepository interface
- Add /api/v1/health/live endpoint for liveness checks (always returns alive if service is running)
- Add /api/v1/health/ready endpoint for readiness checks with database connectivity validation
- Add readinessHandler that returns SERVICE_UNAVAILABLE status when database ping fails
2026-04-25 03:23:01 +03:00
nutcas3 05eb31e117 feat: Add comprehensive unit tests for charging engine components
- Add credit_management_tests.rs with tests for SubscriberAccount, UsageEvent, UsageType, AccountStatus, and integer arithmetic operations
- Add error_tests.rs with tests for ChargingError Display implementation, cloning, and log_error function
- Add rating_billing_tests.rs with tests for ChargingRule variants, as_str conversion, billing period parsing, timestamp filtering, and cost calculations
- Add validation_tests.rs with tests for validate_bytes, validate
2026-04-25 03:17:21 +03:00
nutcas3 4cdecfc932 feat: Add library module exports for charging engine components
- Add public module exports for charging, errors, handlers, routes, models, and monitoring
2026-04-25 03:17:04 +03:00
nutcas3 379dc251d3 feat: Add library configuration and test dependencies to charging-engine
- Add [lib] section with charging_engine name and src/lib.rs path
- Add dev-dependencies: tokio-test 0.4, mockall 0.13, serial_test 3.2
2026-04-25 03:16:53 +03:00
nutcas3 2dd6c3304d feat: Add configurable expiration times for credit and block operations via environment variables
- Add CREDIT_EXPIRATION_SECONDS environment variable to configure credit key expiration (defaults to 86400)
- Add BLOCK_EXPIRATION_SECONDS environment variable to configure block key expiration (defaults to 86400)
- Replace hardcoded 86400 expiration values with configurable variables in add_credit and block_user
- Update block_user warning message to include expiration duration
2026-04-25 03:06:37 +03:00
nutcas3 ff33263df3 feat: Add configurable limits for bytes and amount validation via environment variables
- Add MAX_BYTES_LIMIT environment variable to configure bytes validation limit (defaults to 1TB)
- Add MAX_AMOUNT_LIMIT environment variable to configure amount validation limit (defaults to 10,000)
- Replace hardcoded 1_000_000_000_000 bytes limit with configurable max_bytes value
- Replace hardcoded 10_000.0 amount limit with configurable max_amount value
2026-04-25 03:05:40 +03:00
nutcas3 c4746970a2 feat: Add DatabaseError variant and improve error response handling
- Add DatabaseError(String) variant to ChargingError enum
- Add DatabaseError case to log_error helper with error-level logging
- Add DatabaseError Display implementation
- Refactor IntoResponse to use generic error messages instead of detailed strings
- Add detail field to error responses containing full error message via to_string()
- Change RedisConnection status code from INTERNAL_SERVER_ERROR to SERVICE_UNAVAILABLE
2026-04-25 03:04:25 +03:00
nutcas3 c9c493fd70 feat: Add ChargingRule enum with string conversion for charging decisions
- Add ChargingRule enum with 7 variants (Allowed, InsufficientCredit, DataLimitExceeded, VoiceLimitExceeded, SmsLimitExceeded, UserBlocked, Blocked)
- Add Debug, Clone, Serialize, Deserialize, PartialEq, Eq derives to ChargingRule
- Add as_str method to convert ChargingRule variants to uppercase string constants
2026-04-25 03:03:37 +03:00
nutcas3 7e47f09e54 feat: Replace RedisOperation with DatabaseError in rating_plans_repo error mapping
- Replace RedisOperation error variant with DatabaseError in new/get/list_map/add/remove methods
- Update 5 map_err calls to use DatabaseError for SQLx operation failures
2026-04-25 03:03:27 +03:00
nutcas3 69a84d85e6 feat: Improve rating_billing with integer arithmetic, overflow checks, and SCAN optimization
- Replace float division with integer arithmetic in calculate_usage_cost for data/voice conversions
- Add checked_add overflow protection for usage accumulation in apply_charging_rules and process_usage
- Replace String-based charging rules with ChargingRule enum variants
- Add Datelike import and implement billing period filtering in generate_invoice
- Replace blocking KEYS command with SCAN cursor iteration
2026-04-25 03:03:06 +03:00
nutcas3 3c5878d3cc feat: Replace unwrap_or with proper error handling in credit_management
- Replace unwrap_or(0) with map_err for get operation in deduct_credit
- Replace unwrap_or(0) with ? operator in check_credit
- Add RedisOperation error mapping for current_balance retrieval
2026-04-25 03:02:36 +03:00
nutcas3 40e9d1f221 remove comments 2026-04-25 02:52:41 +03:00
nutcas3 c37ba6c8f2 feat: Remove handlers module and relocate 25+ API handler functions
- Delete handlers.rs module containing credit management handlers (check_credit, deduct_credit, add_credit, get_balance)
- Remove subscriber account handlers (get_subscriber, update_subscriber)
- Remove usage event handlers (record_usage, calculate_usage_cost, rate_usage, process_usage)
- Remove rating plan handlers (list_rating_plans, get_rating_plan, add_rating_plan, remove_rating_plan)
- Remove user blocking handlers (block_user, unblock_user,
2026-04-25 02:52:27 +03:00
nutcas3 69c54c4a35 feat: Remove dead_code attributes and add duplicate block check to block_user
- Remove dead_code attributes from get_balance/add_credit/start/stop/uptime/rating plan methods in credit_management and engine
- Remove dead_code attributes from calculate_usage_cost in rating_billing
- Remove dead_code attributes from get/list_map/deactivate methods in rating_plans_repo and row_to_plan function
- Remove dead_code attributes from get_performance_metrics/start_background_sync in monitoring modules
2026-04-25 02:43:57 +03:00
nutcas3 607040da6c feat: Add usage processing and invoice generation API endpoints
- Add POST /v1/usage/calculate-cost endpoint to calculate usage cost for events
- Add POST /v1/usage/rate endpoint to rate usage events
- Add POST /v1/usage/process endpoint for full rating and billing processing
- Add GET /v1/invoice/:imsi/:period endpoint to generate invoices for billing periods
- Add list_map call to list_rating_plans handler for internal lookups
- Add session_id validation to all usage endpoints using validate_session_id helper
2026-04-25 02:43:22 +03:00
nutcas3 dcd1cdeca0 feat: Remove api module and relocate handlers, clean up unused code and dead_code attributes
- Delete api.rs module containing 20+ handler functions (credit management, subscriber accounts, rating plans, user blocking, system stats, metrics, engine control, error stats, sync control, health checks)
- Remove dead_code attributes from UsageEvent and UsageType in charging/types
- Remove validate_imsi helper function and dead_code attribute from errors/helpers
- Remove ConfigurationError logging case
2026-04-25 02:37:42 +03:00
nutcas3 231f03c903 feat: Extract API handlers from api module into dedicated handlers module
- Move all handler functions from api.rs to new handlers.rs module
- Add 20+ handler functions for credit management, subscriber accounts, rating plans, user blocking, system stats, metrics, engine control, error stats, sync control, and health checks
- Add input validation using validate_ip/validate_bytes/validate_amount/validate_session_id helpers
- Add error context and logging to all handlers using with_context and log
2026-04-25 02:14:23 +03:00
nutcas3 1ee156af75 feat: Add list_rating_plans error handling, dead_code attributes, and refactor monitoring/models
- Add error mapping to list_rating_plans in engine.rs
- Add dead_code attributes to get/list_map/deactivate methods in rating_plans_repo and row_to_plan function
- Add list method to RatingPlansRepo returning Vec<RatingPlan>
- Add dead_code attribute to validate_imsi in helpers
- Add UsageBlocked and ConfigurationError variants to ChargingError with Display/IntoResponse implementations
- Add Default
2026-04-25 02:14:10 +03:00
nutcas3 8b86e55226 feat: Refactor charging engine modules with dead_code annotations and error handling improvements
- Add AsyncCommands import and dead_code attributes to get_balance/add_credit/start/stop/uptime/rating plan methods
- Remove validate_imsi/validate_session_id calls from get_subscriber_account/record_usage_event
- Update logging in get_subscriber_account and simplify record_usage_event log message
- Remove usage event expiration logic from record_usage_event
- Reorder engine methods and add dead_code attributes
2026-04-25 02:10:24 +03:00
nutcas3 99943c769e feat: Extract router configuration from api module into dedicated routes module
- Move create_router function from api.rs to new routes.rs module
- Move routing imports (delete/get/post/put/Router/CorsLayer) from api to routes
- Add handler function imports to routes module
- Move AppState from api to models module
- Remove validation comments from check_credit/deduct_credit/add_credit/get_balance/record_usage handlers
- Add IntoResponse import to api module
2026-04-25 01:59:40 +03:00
nutcas3 67a2c807d1 feat: Remove unused imports and suppress dead_code warnings across charging engine modules
- Remove unused AsyncCommands/error/ChargingSession/ErrorContext imports from credit_management
- Remove unused ErrorContext/ChargingError imports from engine
- Remove unused ErrorContext import from rating_billing and prefix unused variables with underscore
- Remove unused ErrorContext import from rating_plans_repo
- Remove unused Context import from errors/helpers
- Remove unused info/debug/SystemTime imports from monitoring
- Remove unused sleep
2026-04-25 01:33:20 +03:00
nutcas3 4c14721dfc feat: Add error statistics, sync control, and detailed health check API endpoints
- Add GET /v1/errors endpoint to retrieve error statistics (total/types/last error)
- Add POST /v1/sync/start endpoint to start background sync
- Add GET /v1/health/detailed endpoint for detailed health checks (redis/sync/memory status)
2026-04-25 01:32:34 +03:00
nutcas3 ab986927d0 feat: Add error stats, sync control, detailed health endpoints and fix subscriber account balance type
- Add GET /v1/errors endpoint to retrieve error statistics
- Add POST /v1/sync/start endpoint for sync control
- Add GET /v1/health/detailed endpoint for detailed health checks
- Fix balance field type from u64 to i64 in update_subscriber
- Add status and last_updated fields to SubscriberAccount in update_subscriber
2026-04-25 01:30:39 +03:00
nutcas3 4c50359bdb feat: Add subscriber update, performance metrics, and engine control API endpoints
- Add PUT /v1/subscriber/:imsi endpoint to update subscriber account details (balance/data/voice/sms usage and limits)
- Add GET /v1/metrics endpoint to retrieve performance metrics (connected clients/memory/commands/RPS/response time)
- Add POST /v1/engine/start and POST /v1/engine/stop endpoints for engine lifecycle management
- Add GET /v1/engine/uptime endpoint to retrieve engine uptime in seconds
- Add put to
2026-04-25 01:28:13 +03:00
nutcas3 1b5ee4ad4a feat: Add rating plan management, user blocking, and system stats API endpoints
- Add GET/POST /v1/rating-plans and GET/DELETE /v1/rating-plans/:id endpoints for rating plan CRUD operations
- Add POST /v1/block/:ip, POST /v1/unblock/:ip, and GET /v1/blocked/:ip endpoints for user blocking management
- Add GET /v1/stats endpoint to retrieve system statistics (accounts/sessions/blocked users/alerts/uptime)
- Add delete to routing imports and remove unused IntoResponse/warn imports
- Add RatingPlan
2026-04-25 01:27:51 +03:00
nutcas3 71ae1925f1 feat: Add subscriber account and usage recording API endpoints with validation
- Add GET /v1/subscriber/:imsi endpoint to retrieve subscriber account details
- Add POST /v1/usage endpoint to record usage events with session validation
- Remove unused validate_imsi import and dummy validation calls from check_credit
- Add validate_amount call for bytes_used in deduct_credit
- Add balance retrieval logging and fix IP clone in get_balance response
- Add IMSI/session_id validation and error handling for missing fields in record_usage
- Return subscriber
2026-04-25 01:22:12 +03:00
nutcas3 8076d9b79a feat: Migrate web-dashboard CI workflow from npm to pnpm
- Replace npm cache with pnpm setup and store caching in CI workflow
- Add pnpm/action-setup@v4 with version 9
- Configure pnpm store path caching with pnpm-lock.yaml hash key
- Update install command to use pnpm install --frozen-lockfile instead of npm ci
- Update lint and build commands to use pnpm run instead of npm run
2026-04-25 01:19:02 +03:00
nutcas3 ad417defbf feat: Add validation calls and error logging to API, credit management, billing, and sync operations
- Add validate_imsi/validate_session_id/validate_amount/log_error imports to api/credit_management/rating_billing/sync modules
- Add validation calls for IMSI in get_subscriber_account and session_id in record_usage_event
- Add dummy validation calls in check_credit to prevent unused function removal
- Add validate_amount call after cost calculation in calculate_usage_cost
- Add log_error call in check
2026-04-25 01:14:13 +03:00
nutcas3 79f217ff1b feat: Fix formatting, type conversion, and test assertions in middleware and monitoring modules
- Add fmt import and fix X-RateLimit-Limit header conversion from rune to string in ratelimit middleware
- Fix whitespace alignment for rate limiter variable declarations and JSON error responses
- Update mock expectations in redis_ratelimit_test to use explicit argument type matchers
- Add severity validation check in alerting_test rule validation
- Fix health_test assertions for degraded/unhealthy counts
2026-04-25 01:07:52 +03:00
nutcas3 9d3b8428bd feat: Remove unused imports across charging engine modules
- Remove unused IntoResponse/warn/error/ChargingError/validate_* imports from api
- Remove unused AsyncCommands/error/ChargingSession/ErrorContext imports from credit_management
- Remove unused ErrorContext/ChargingError imports from engine
- Remove unused ErrorContext import from rating_billing and prefix unused variables with underscore
- Remove unused ErrorContext import from rating_plans_repo
- Remove unused log_error/validate_amount/validate_im
2026-04-25 01:06:30 +03:00
nutcas3 eb8e7bc48a feat: Add Redis serialization trait implementations for SubscriberAccount and UsageEvent types
- Add redis::FromRedisValue/ToRedisArgs/ToSingleRedisArg imports
- Implement FromRedisValue for SubscriberAccount with JSON deserialization and ParsingError mapping
- Implement ToRedisArgs for SubscriberAccount with JSON serialization
- Implement ToSingleRedisArg for SubscriberAccount
- Implement FromRedisValue for UsageEvent with JSON deserialization and ParsingError mapping
- Implement ToRedisArgs for UsageEvent with JSON serial
2026-04-25 00:52:19 +03:00
nutcas3 2bd7e19f09 feat: Replace context error handling with map_err for ChargingError in RatingPlansRepo Postgres operations
- Replace context with map_err for InternalError on Postgres connection
- Replace context with map_err for RedisOperation on schema migration/fetch/list/upsert/deactivate operations
2026-04-25 00:51:27 +03:00
nutcas3 dd12518786 feat: Refactor rating_billing to use async rating plans from Postgres and multiplexed Redis connections
- Remove RatingPlan import and update get_rating_plan call to async with await
- Update generate_invoice to use get_multiplexed_async_connection instead of get_async_connection
- Replace context error handling with map_err for RedisConnection/RedisOperation errors
- Add explicit redis::AsyncCommands trait qualification for keys/get/set operations
- Update apply_monthly_fees to use async get_rating
2026-04-25 00:51:15 +03:00
nutcas3 c3522cad3a feat: Refactor ChargingEngine to use RatingPlansRepo for Postgres-backed rating plans and multiplexed Redis connections
- Replace in-memory HashMap rating plans with RatingPlansRepo for Postgres-backed storage
- Update constructor to accept RatingPlansRepo and remove hardcoded default plans (basic/premium/enterprise)
- Make redis_client/plans/sync_interval/startup_time fields public(crate) for module access
- Convert get_rating_plan/add_rating_plan/remove_rating_plan/list_rating_plans to async methods using
2026-04-25 00:51:01 +03:00
nutcas3 f0bbbc4459 feat: Refactor credit management to use multiplexed Redis connections and explicit AsyncCommands trait for improved connection pooling
- Update all Redis operations to use get_multiplexed_async_connection instead of get_async_connection for better connection pooling
- Replace context error handling with map_err for RedisConnection/RedisOperation errors
- Add explicit redis::AsyncCommands trait qualification for all Redis operations (get/set/del/incr/decr/expire)
- Add ChargingSession import to types
2026-04-25 00:50:42 +03:00
nutcas3 0fc60e553d feat: Remove operations module from monitoring module declarations
- Remove operations module declaration from monitoring/mod.rs
2026-04-25 00:50:31 +03:00
nutcas3 20bb3239b2 feat: Initialize RatingPlansRepo from DATABASE_URL and seed defaults before creating ChargingEngine
- Add RatingPlansRepo import from charging module
- Add DATABASE_URL environment variable requirement for rating plans
- Connect to Postgres via RatingPlansRepo::connect and seed default rating plans
- Pass plans_repo to ChargingEngine::new constructor
- Add info log for Postgres connection and default rating plans
2026-04-25 00:49:33 +03:00
nutcas3 75d00704b9 feat: Add RatingPlansRepo module and public re-export to charging module
- Add rating_plans_repo module declaration
- Add RatingPlansRepo re-export from rating_plans_repo
2026-04-25 00:49:23 +03:00
nutcas3 49e132cecb feat: Add Clone derive to AppState and cast balance values to i64 in API responses
- Add Clone derive to AppState struct
- Cast remaining_bytes to i64 in CreditCheckResponse
- Cast balance_bytes to i64 in BalanceResponse
2026-04-25 00:48:50 +03:00
nutcas3 181ddf2969 feat: Add public re-exports for ChargingError and helper functions to errors module
- Add ChargingError re-export from types
- Add log_error/validate_amount/validate_bytes/validate_imsi/validate_ip/validate_session_id/ChargingResult/ErrorContext re-exports from helpers
2026-04-25 00:48:41 +03:00
nutcas3 5fa329e4e0 feat: Refactor monitoring sync module to use multiplexed Redis connections and explicit AsyncCommands trait for improved connection pooling
- Update all Redis operations to use get_multiplexed_async_connection instead of get_async_connection for better connection pooling
- Replace context error handling with map_err for RedisConnection/RedisOperation errors
- Add explicit redis::AsyncCommands trait qualification for all Redis operations (keys/get/set/del/ttl/expire)
- Add chrono::Datelike import
2026-04-25 00:48:27 +03:00
nutcas3 1f90b27d34 feat: Add ErrorContext trait implementation for anyhow::Result to enable context error handling with ChargingError conversion
- Add ChargingError import from super::types
- Add ErrorContext<T> implementation for anyhow::Result<T> with with_context method that maps errors to ChargingError::InternalError with formatted context message
2026-04-25 00:48:16 +03:00
nutcas3 5c03c48e22 feat: Remove system statistics and health check methods from monitoring module and update Redis connection handling
- Remove get_system_statistics/get_uptime/health_check/get_memory_usage/get_process_memory/estimate_memory_usage/get_redis_memory_usage methods from ChargingEngine impl
- Remove SystemStats/HealthStatus struct definitions
- Update get_performance_metrics/calculate_rps/calculate_avg_response_time/get_error_statistics/get_last_error/get_redis_latency to use get_multiplexed_async_connection instead of get_async_connection
- Replace context error handling with map
2026-04-25 00:47:45 +03:00
nutcas3 0e41a05cb0 feat: Remove charging-engine monitoring operations module and clean up module declarations
- Remove monitoring/operations.rs with background sync implementation (start_background_sync/perform_sync/cleanup_expired_blocks/update_usage_statistics/check_low_balance_alerts/apply_monthly_fees_if_needed methods)
- Remove charging/mod.rs module declaration with types/engine/credit_management/rating_billing submodules and ChargingEngine re-export
- Remove errors/mod.rs module declaration with types/helpers
2026-04-25 00:47:23 +03:00
nutcas3 758bb8ad15 feat: Add RatingPlansRepo with Postgres persistence for rating plan management shared between charging-engine and api-server
- Add RatingPlansRepo struct with PgPool for Postgres-backed rating plan storage
- Add connect method with max_connections=10 and idempotent schema creation for rating_plans table with plan_id/name/data_rate/voice_rate/sms_rate/monthly_fee/data_limit/voice_limit/sms_limit/is_active/created_at/updated_at columns
- Add seed_defaults with basic/premium/enterprise plans (data
2026-04-24 09:09:05 +03:00
nutcas3 3f19a5135c feat: Remove redundant chrono dependency as it's already included via sqlx features
- Remove standalone chrono 0.4.44 dependency from Cargo.toml
- Chrono functionality remains available through sqlx's chrono feature
2026-04-24 09:06:20 +03:00
nutcas3 eff14e3718 feat: Update workspace dependencies to latest versions and add sqlx/chrono for Postgres persistence
- Update tokio from 1.40 to 1.52.1, async-std from 1.13 to 1.13.2
- Update aya from 0.13 to 0.13.1, aya-ebpf from 0.1 to 0.1.1, aya-log from 0.2 to 0.2.1, aya-log-ebpf to 0.1.0
- Update serde from 1.0 to 1.0.228, serde_json from 1.0 to 1.0.149
- Update redis from 0.27 to 1.2.0 with tokio-comp/connection-manager/cluster-async features
- Add sqlx 0.8.6 with runtime-tokio-rustls/postgres/chrono/uuid/migrate features
2026-04-24 09:02:45 +03:00