Commit Graph
122 Commits
Author SHA1 Message Date
nutcas3 393685846c fix: Convert Status field to string in ListSubscribers database request
- Cast req.Status to string when passing to database.ListSubscribersRequest
- Ensure type compatibility between service and database layer status fields
2026-04-29 03:31:29 +03:00
nutcas3 71353fc237 feat: Replace GORM AutoMigrate with Goose CLI migrations in api-server database initialization
- Add os/exec import for running external commands
- Replace AutoMigrate function with runMigrations function using goose postgres command
- Call runMigrations in NewDatabase before initializing IMSI allocation
- Remove PoolStats function and GORM-based schema migration code
- Reorganize database methods with section comments (Subscriber CRUD, Payment methods, Transactions, Additional CRUD, IMSI allocation)
-
2026-04-29 03:31:00 +03:00
nutcas3 85b97c0950 deps: Update lib/pq from v1.10.2 to v1.12.3 in api-server 2026-04-29 02:55:05 +03:00
nutcas3 b734ea7d3a refactor: Add environment variable support to API server configuration and fix build path
- Add getEnv and getEnvInt helper functions for reading environment variables with defaults
- Update all configuration fields to use environment variables (DB_HOST, REDIS_HOST, API_PORT, etc.)
- Change CI build command from ./cmd/server.go to ./cmd/ directory path
2026-04-26 00:15:45 +03:00
nutcas3 0e382a81c9 refactor: Update API server CI test scope and fix rate limit test comment
- Change test command to run only internal/services/ tests with race detector enabled
- Update RateLimit_ErrorHandling test to use high limit instead of invalid value
- Update test comments to reflect new approach of using very high limit to simulate no rate limiting
2026-04-25 22:53:25 +03:00
nutcas3 4edee2c82f test: Fix rate limit header casing and adjust test expectations for Gin behavior
- Change X-RateLimit-* headers to X-Ratelimit-* in test assertions
- Skip IPv6 test case due to Gin's ClientIP() handling limitations
- Update EndpointKeyExtractor test to expect empty FullPath() without route registration
- Fix Reset test mock to use string slice parameter for Del method
2026-04-25 22:14:13 +03:00
nutcas3 d74ac722c4 test: Add unit tests for service discovery and message queue with integration test skips
- Add discovery_test.go with Service and ServiceDiscovery struct tests
- Add integration test placeholders for service registration, discovery, deregistration, and health checks
- Add mq_test.go with Message serialization and profile event tests
- Add integration test placeholders for RabbitMQ connectivity, queue declaration, and publish/consume flow
- Add github.com/stretchr/testify v1.11.1 to carrier-connector dependencies
2026-04-25 06:59:03 +03:00
nutcas3 f6ec659fe9 refactor: Fix race condition in chaos service and update Redis rate limiter test mocks
- Add copy method to Experiment struct to create deep copy with proper Finished pointer handling
- Return experiment copy from RunExperiment to prevent race condition with JSON marshaling
- Update mock Eval calls to use float64 for window parameter instead of int64 in redis_ratelimit_test.go
- Update comments to reflect correct parameter types: now (int64), window (float64), limit (int64)
2026-04-25 06:54:29 +03:00
nutcas3 93bf51df65 feat: Add Consul service discovery integration to API server with automatic registration
- Add discovery package import to server.go
- Add fmt and strconv imports for service ID generation and port parsing
- Add CONSUL_ADDR environment variable check to conditionally enable service discovery
- Add discovery.NewServiceDiscovery initialization with error handling and logging
- Add service registration with api-server name, dynamic port from config, and api/telecom tags
- Add serviceID generation using api
2026-04-25 06:51:04 +03:00
nutcas3 1fc84859df refactor: Remove structured logging initialization from API server startup
- Remove logging package import from server.go
- Remove logging.InitWithDefaults call and error handling
- Replace logging.Fatalf with log.Fatalf for database initialization errors
2026-04-25 06:37:33 +03:00
nutcas3 1c89fdac92 feat: Add structured logging initialization to API server startup with database error logging
- Add logging package import to server.go
- Add logging.InitWithDefaults call after config loading with error handling
- Replace log.Fatalf with logging.Fatalf for database initialization errors
2026-04-25 06:36:37 +03:00
nutcas3 2a71cba13e feat: Move casbin, gorm-adapter, gorilla/websocket, and validator to direct dependencies
- Move github.com/casbin/casbin/v2 v2.135.0 from indirect to direct dependencies
- Move github.com/casbin/gorm-adapter/v3 v3.41.0 from indirect to direct dependencies
- Move github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 from indirect to direct dependencies
- Move github.com/go-playground/validator/v10 v10.30.2 from indirect to direct dependencies
- Add github.com/dgryski/go-rendezvous v0.0.0-20
2026-04-25 06:36:18 +03:00
nutcas3 47c57c9b48 feat: Add timeout handling to health check execution with goroutine-based result channel
- Add resultChan channel to receive health check results asynchronously
- Execute checker.CheckHealth in goroutine to enable timeout detection
- Add select statement to handle both successful completion and timeout cases
- Return StatusUnhealthy with "Health check timed out" message on context timeout
- Set ResponseTime to 10 seconds when timeout occurs
2026-04-25 06:34:12 +03:00
nutcas3 6cf546712b refactor: Replace interface{} with any type alias across codebase
- Replace interface{} with any in api_integration_test.go makeRequest method and test response maps
- Replace interface{} with any in logging.go WithField method and all logging function signatures
- Replace interface{} with any in middleware etag.go sync.Map.Range callback
- Replace interface{} with any in middleware redis_ratelimit.go RedisClientInterface and result parsing
- Replace interface{} with any in middleware redis_ratelimit_
2026-04-25 06:31:02 +03:00
nutcas3 715417c0eb feat: Add structured logging with logrus and configurable output formats
- Add sirupsen/logrus v1.9.4 dependency to go.mod
- Add logging package with global Logger instance
- Add Config struct with Level, Format, and Output fields
- Add DefaultConfig with LOG_LEVEL, LOG_FORMAT, and LOG_OUTPUT environment variables
- Add Init function with level parsing, JSON/text formatter selection, and stdout/stderr output
- Add InitWithDefaults helper function
- Add WithField, WithFields, and WithError helper
2026-04-25 06:19:48 +03:00
nutcas3 b714fa8382 feat: Add HashiCorp Consul service discovery integration with API client v1.34.2
- Add hashicorp/consul/api v1.34.2 dependency to go.mod
- Add armon/go-metrics v0.4.1 for metrics collection
- Add hashicorp/go-hclog v1.5.0 for structured logging
- Add hashicorp/go-cleanhttp v0.5.2 for HTTP client utilities
- Add hashicorp/go-immutable-radix v1.3.1 for radix tree data structures
- Add hashicorp/go-multierror v1.1.1 for error aggregation
- Add hashicorp/go-rootcerts v1.0.2 for certificate management
2026-04-25 06:19:22 +03:00
nutcas3 76d1f7b1ec feat: Add RabbitMQ message queue integration with exchange and queue management support
- Add rabbitmq/amqp091-go v1.11.0 dependency to go.mod
- Add MessageQueue struct with connection, channel, and url fields
- Add Message struct with Type, Payload, and Timestamp fields
- Add NewMessageQueue constructor with RABBITMQ_URL environment variable support and amqp://guest:guest@localhost:5672/ default
- Add Close method for connection cleanup
- Add DeclareQueue method with durable configuration
- Add Publish method with 5
2026-04-25 06:15:11 +03:00
nutcas3 19a4aaee01 feat: Add user-based rate limiting to protected API routes with 100 requests per minute limit
- Add RateLimitByUser middleware to protected route group with 100 req/min limit
- Add RateLimitByUser middleware to apiProtected route group with 100 req/min limit
2026-04-25 06:12:59 +03:00
nutcas3 653f23ff24 feat: Wrap all Kubernetes API operations with circuit breaker protection and improve error handling
- Add strings import to kubernetes.go
- Wrap ListDeployments with circuitBreaker.Execute and move result building inside closure
- Wrap GetDeployment with circuitBreaker.Execute and move result assignment inside closure
- Wrap ScaleDeployment with circuitBreaker.Execute and simplify error messages
- Wrap RestartDeployment with circuitBreaker.Execute
- Wrap PodLogs with circuitBreaker.Execute and add streaming
2026-04-25 06:12:40 +03:00
nutcas3 12513943cc feat: Add circuit breaker protection to Kubernetes service with configurable thresholds and timeout
- Add circuitbreaker import to kubernetes.go
- Add circuitBreaker field to KubernetesService struct
- Add circuit breaker initialization in NewKubernetesService with Config struct
- Add K8S_CB_FAILURE_THRESHOLD environment variable with 5 default
- Add K8S_CB_SUCCESS_THRESHOLD environment variable with 2 default
- Add K8S_CB_TIMEOUT_SECONDS environment variable with 60 second default
- Add getEnvUint helper
2026-04-25 06:04:15 +03:00
nutcas3 2b23461eef feat: Add circuit breaker pattern implementation to API server with configurable thresholds and timeout
- Add State enum with Closed, Open, and HalfOpen states and String method
- Add CircuitBreaker struct with mutex, state tracking, failure/success counters, and timeout
- Add Config struct with FailureThreshold, SuccessThreshold, and Timeout fields
- Add NewCircuitBreaker constructor with Config parameter
- Add DefaultConfig with 5 failure threshold, 2 success threshold, and 60 second timeout
2026-04-25 06:04:00 +03:00
nutcas3 2c5d513c4b feat: Add subscriber management API endpoints with RBAC authorization
- Add SubscriberHandler to serverDeps with NewSubscriberService initialization
- Add subscriber routes to v1 API with GET (list, by id, by IMSI) and protected POST/PUT operations
- Add RBAC enforcement for subscriber creation, updates, suspension, and termination (admin, operator roles)
- Add registerSubscriberRoutes function with /subscribers endpoint group
2026-04-25 05:28:14 +03:00
nutcas3 d7e83c1f0d feat: Add API key authentication support to charging engine client
- Add APIKey field to ChargingEngineConfig struct
- Add apiKey field to ChargingEngineClient struct
- Add setAPIKeyHeader method to set X-API-Key header when API key is configured
- Call setAPIKeyHeader in CheckCredit, DeductCredit, AddCredit, GetBalance, and HealthCheck methods
2026-04-25 03:43:32 +03:00
nutcas3 552d9d5e1f feat: Move charging routes to public v1 group and add health check endpoint
- Move charging routes from protected /api group to public /v1/charging group for packet-gateway integration
- Add GET /v1/health endpoint returning status ok
- Remove registerChargingRoutes function (routes now inline in registerV1Routes)
- Remove registerChargingRoutes call from apiProtected group
2026-04-25 03:33:08 +03:00
nutcas3 7aa582ee3d feat: Add charging routes and handler integration to API server
- Add chargingH field to serverDeps struct
- Add ChargingEngineClient initialization in buildDeps
- Add NewChargingHandler with chargingEngineClient dependency
- Add registerChargingRoutes function with /charging group
- Add POST /charging/credit/:ip/check endpoint
- Add GET /charging/credit/:ip/balance endpoint
- Add POST /charging/credit/:ip/add endpoint
- Add POST /charging/credit/:ip/deduct endpoint
- Call registerChargingRoutes in
2026-04-25 03:32:05 +03:00
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 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 c0034b195a feat: Refactor api-server main.go to extract route setup and handlers into separate packages for improved modularity
- Move route registration logic to registerV1Routes with dependency injection pattern
- Extract metrics collector initialization to buildMetricsCollector helper function
- Extract service/handler dependency initialization to buildDeps helper function
- Remove all inline handler implementations (auth/services/monitoring/deployments/plugins/automation/config/chaos/billing routes)
- Remove all metrics collection helper functions (startMetricsCollection/
2026-04-24 08:58:53 +03:00
nutcas3 000640149d feat: Remove package documentation from platform.go and normalize imports formatting
- Remove package-level documentation comment mapping handler files to domains (services/monitoring/deployments/plugins/automation/config/chaos/billing)
- Normalize imports from inline to block format (net/http, strconv, github.com/gin-gonic/gin)
- Retain ErrorResponse struct and shared helper functions
2026-04-24 08:56:31 +03:00
nutcas3 85ed3e1598 feat: Refactor GraphQL resolvers to extract domain methods into separate files and retain only shared helpers
- Add package documentation mapping resolver files to domains (subscriber/usage/billing/mutations/esim/alerts/subscriptions)
- Remove models package import and add blank imports for context/base64 to preserve helper function dependencies
- Remove all resolver method implementations (Subscriber/SubscriberByImsi/Subscribers/SubscriberAccount/UsageEvents/UsageStats/RealTimeUsage/Invoices/Invoice
2026-04-24 08:55:28 +03:00
nutcas3 d99109386b feat: Refactor platform.go to extract domain handlers into separate files and retain only shared helpers
- Add package documentation mapping handler files to domains (services/monitoring/deployments/plugins/automation/config/chaos/billing)
- Remove gorm.io/gorm, models, monitoring, and services package imports
- Remove ServicesHandler struct and all methods (List/Get/Restart/Start/Stop/Scale/Logs/Health/PodStatus/Events)
- Remove MonitoringHandler struct and all methods (Metrics/Alerts/Health/Logs)
2026-04-24 08:54:23 +03:00
nutcas3 cb1d7171e0 feat: Add PaymentController with modular handlers for payment operations, refunds, and webhook processing
- Add PaymentController struct with paymentService/db dependencies and NewPaymentController constructor
- Add SetupRoutes with /payments endpoints (POST /top-up, POST/DELETE/GET /payment-methods, GET /transactions/:id, POST /transactions/:id/refund) and /webhooks/stripe endpoint
- Add ProcessTopUp handler with amount/paymentMethodId validation, subscriberID authentication, and PaymentService.
2026-04-24 08:53:34 +03:00
nutcas3 26731d4390 feat: Extract Stripe gateway types to separate file for improved code organization and maintainability
- Move StripeGateway struct from stripe.go to types.go
- Move PaymentRequest/PaymentResponse/CustomerResponse/RefundResponse/PaymentStatusResponse/WebhookEvent/InvoiceItem/InvoiceResponse structs to types.go
- Remove encoding/json import from stripe.go (moved to types.go)
- Remove PaymentRequest comment from types.go for consistency with other type definitions
2026-04-24 08:51:37 +03:00
nutcas3 1889e78db2 feat: Refactor SubscriberService to split monolithic service into modular files with method organization by domain
- Remove all method implementations from subscriber.go (CreateSubscriber/GetSubscriber/GetSubscriberByIMSI/UpdateSubscriber/SuspendSubscriber/TerminateSubscriber/ListSubscribers/terminateSubscriberSessions/GetAccount/ListInvoices/GetInvoice/ListRatingPlans/GetRatingPlan/ListAlerts/SearchSubscribers/ResolveAlert/CreateAlert and all other methods)
- Update SubscriberService struct comment
2026-04-24 08:51:13 +03:00
nutcas3 d9c2ad1f71 feat: Add structured JSON logging to PerformanceMiddleware slow request handler with comprehensive request metadata
- Replace fmt.Appendf with json.Marshal for structured log output
- Add logData map with level/type/method/path/query/response_time/status/user_agent/ip/timestamp fields
- Update logSlowRequest to output JSON-formatted logs with newline terminator for better log parsing and monitoring integration
2026-04-24 07:35:32 +03:00
nutcas3 3b338b0e20 feat: Add comprehensive ETag middleware with content-based generation, validation, and cache invalidation support
- Add ResponseWriterWrapper struct with Write/Body methods for response body capture
- Add ETagData/ETagGenerator structs with GenerateETag/GenerateWeakETag/GetCachedETag/CacheETag/InvalidateCache methods for sophisticated ETag generation and caching
- Add generateETag/generateContentETag/generateWeakETag helper functions with path/method/content/timestamp/user context hashing
- Add ETagValid
2026-04-24 07:34:14 +03:00
nutcas3 7ee875c544 feat: Remove ETag generation and validation middleware, simplify CacheMiddleware to basic Cache-Control header
- Remove ResponseWriterWrapper struct with Write/Body methods for response body capture
- Remove ETagData/ETagGenerator structs and all ETag generation/validation/caching logic
- Remove generateETag/generateContentETag/generateWeakETag/etagMatches helper functions
- Remove ETagValidationMiddleware/ContentBasedETagMiddleware/CacheInvalidationMiddleware/AdvancedCacheMiddleware handlers
2026-04-24 07:33:07 +03:00
nutcas3 8909126612 feat: Refactor Redis rate limiter to use interface for improved testability and remove mock client replacement pattern
- Add RedisClientInterface with Eval/Del/ZCount methods for Redis operation abstraction
- Update RedisRateLimiter/NewRedisRateLimiter/NewMultiTierRateLimiter to accept RedisClientInterface instead of concrete redis.Client
- Update MockRedisClient.Eval to properly construct call arguments with script and keys
- Update MockRedisClient.Del to accept keys as slice instead of variadic parameters
2026-04-23 03:16:00 +03:00
nutcas3 857ca98382 feat: Add comprehensive Redis rate limiter tests with mock client, middleware validation, and multi-tier support
- Add MockRedisClient struct with Eval/Del/ZCount methods for Redis operation mocking
- Add TestRedisRateLimiter_Allow with under/over limit scenarios and mock Redis response validation
- Add TestRedisRateLimitMiddleware with IP-based rate limiting and empty key bypass tests
- Add TestIPKeyExtractor/TestUserKeyExtractor/TestAPIKeyExtractor with valid/invalid input validation
- Add TestEnd
2026-04-23 03:02:00 +03:00
nutcas3 85926ee377 feat: Add distributed Redis-based rate limiting with sliding window, token bucket, and multi-tier support
- Add RedisRateLimiter struct with client/prefix/limit/window fields for distributed rate limit tracking
- Add RateLimitResult struct with allowed/remaining/reset_time/total_limit/retry_after fields
- Add NewRedisRateLimiter constructor and Allow method with Lua script for atomic sliding window operations
- Add AllowTokenBucket method with token bucket algorithm using Redis HMSET for refill rate
2026-04-23 03:00:33 +03:00
nutcas3 5a3f08829f feat: Add response body capture to ContentBasedETagMiddleware for accurate content-based ETag generation
- Add ResponseWriterWrapper struct with gin.ResponseWriter and body buffer fields to capture response content
- Add Write method to ResponseWriterWrapper that captures response body while writing to original writer
- Add Body method to ResponseWriterWrapper that returns captured response bytes
- Update ContentBasedETagMiddleware to wrap response writer with ResponseWriterWrapper before calling
2026-04-23 02:59:18 +03:00
nutcas3 cae53ebd17 feat: Add comprehensive rate limiting middleware with IP-based, user-based, and endpoint-specific throttling strategies
- Add SimpleRateLimiter struct with requests map, mutex, limit, window fields for in-memory rate limit tracking
- Add NewSimpleRateLimiter constructor and Allow method with time-based request cleanup and limit validation
- Add global rate limiters: authRateLimiter (10/min), apiRateLimiter (100/min), readRateLimiter (200/min), adminRateLimiter (50/min)
- Add RateLimit middleware
2026-04-23 02:59:03 +03:00
nutcas3 e2e39d8b37 feat: Add comprehensive API integration tests with authentication, RBAC, and endpoint coverage for all platform handlers
- Add TestSetup struct with DB/Router/AuthService/test users/JWT tokens for test environment initialization
- Add setupTest function with SQLite in-memory database, user/plugin/automation/config/auth session migrations, and test user creation with admin/operator/viewer/user roles
- Add makeRequest helper for authenticated HTTP requests with Bearer token and JSON body support
2026-04-23 02:58:34 +03:00
nutcas3 546c9cd69f feat: Add authentication configuration with JWT secret and reorganize environment variables with categorized sections
- Add AuthConfig struct with JWTSecret field to config package
- Add Auth field to Config struct with JSON tag for authentication settings
- Add JWT_SECRET to Auth config with default value "change-me-in-production"
- Replace MONGODB_URI with DATABASE_URL using PostgreSQL connection string in .env.example
- Add categorized sections in .env.example: Database/Server/Authentication/
2026-04-23 02:58:01 +03:00
nutcas3 bda6c5931c feat: Add comprehensive alerting system with rule evaluation, multi-channel notifications, and health-based alert triggers
- Add AlertSeverity enum with info/warning/critical levels and AlertStatus enum with firing/resolved/silenced states
- Add Alert struct with id/name/description/severity/status/timestamp/labels/annotations/last_evaluated fields
- Add AlertRule struct with id/name/description/severity/query/threshold/duration/labels/enabled fields for rule definitions
- Add AlertManager struct with rules
2026-04-23 02:57:44 +03:00
nutcas3 dd7ff85da6 feat: Add comprehensive health monitoring system with component checks, system metrics, and HTTP handlers
- Add HealthStatus enum with healthy/degraded/unhealthy states and HealthCheck struct with name/status/message/last_checked/response_time/metadata fields
- Add SystemHealth struct with status/timestamp/uptime/version/environment/checks/summary fields and HealthSummary with total/healthy/degraded/unhealthy counts
- Add HealthMonitor struct with checks map, mutex, startTime, version, env fields
2026-04-23 02:57:31 +03:00
nutcas3 d905478e89 feat: Add authentication models with User, Role, Permission, AuthSession, and APIKey structs
- Add User struct with username/email/password/first_name/last_name/role/is_active/last_login fields and GORM tags
- Add Role struct with name/description/permissions many2many relationship and GORM tags
- Add Permission struct with name/resource/action/description fields for RBAC
- Add AuthSession struct with user_id/token/refresh_token/expires_at/ip_address/user_agent/is_active fields
- Add APIKey struct with name
2026-04-23 02:57:12 +03:00
nutcas3 cf62b79932 feat: Add platform handlers for services, monitoring, deployments, plugins, automations, chaos experiments, and configuration management
- Add ServicesHandler with List/Get/Restart/Start/Stop/Scale/Logs/Health/PodStatus/Events methods and Kubernetes service integration
- Add MonitoringHandler with Metrics/Alerts/Health/Logs methods and Prometheus service integration
- Add DeploymentsHandler with Status/Start/Rollback/History methods and deployment service integration
- Add PluginsHandler with List
2026-04-23 02:56:57 +03:00
nutcas3 8b619577c8 feat: Add database connection pool optimization, statistics monitoring, and platform model migrations
- Update connection pool config with SetMaxIdleConns(25), SetConnMaxIdleTime(30min), and descriptive comments
- Add AutoMigrate for Plugin/Automation/AutomationRun/ConfigEntry/DeploymentRecord/ChaosExperimentRecord models
- Add PoolStats method with max_open_connections/open_connections/in_use/idle/wait_count/wait_duration/max_idle_closed/max_idle_time_closed/max_lifetime_closed fields
- Add Ping method
2026-04-23 02:56:43 +03:00