Commit Graph

32 Commits

Author SHA1 Message Date
zenfun
51e55cb036 feat(api): add update endpoints for providers and models
Register admin routes to handle updates for providers and models via
their respective handlers.
2025-12-15 16:22:54 +08:00
zenfun
ca03ac1b79 docs(api): update swagger documentation for admin endpoints
Reflect recent API changes in Swagger documentation:
- Add endpoints for feature flag management (/admin/features)
- Add endpoint for issuing child keys to masters (/admin/masters/{id}/keys)
- Add endpoint for updating providers (/admin/providers/{id})
- Update provider model definitions with new fields (auto_ban, google_* attributes, status)
2025-12-15 16:12:56 +08:00
zenfun
aa69ce3659 feat(api): add admin endpoint to issue keys for masters
Add `POST /admin/masters/{id}/keys` allowing admins to issue child keys
on behalf of a master. Introduce an `issued_by` field in the Key model
to audit whether a key was issued by the master or an admin.

Refactor master service to use typed errors for consistent HTTP status
mapping and ensure validation logic (active status, group check) is
shared.
2025-12-15 15:59:33 +08:00
zenfun
11f6e81798 feat(api): add feature flag management endpoints
Add FeatureHandler to manage lightweight runtime configuration toggles
stored in the Redis `meta:features` hash. This enables dynamic control
over system behavior (e.g., storage backends) via the admin API.

- Add `GET /admin/features` to list flags
- Add `PUT /admin/features` to update flags
- Update README with feature flag documentation
2025-12-15 15:01:01 +08:00
zenfun
fb68e0f155 docs(testing): point provider snapshot golden to foundation 2025-12-14 23:54:57 +08:00
zenfun
85223cc31d chore(deps): bump foundation to v0.2.0 2025-12-14 23:54:12 +08:00
zenfun
d1d1b1c42a refactor(deps): use foundation shared utilities 2025-12-14 23:52:46 +08:00
zenfun
71c183a480 test(service): add golden file validation and master key tests
- Update TESTING.md to reflect current testing status and future plans
- Add golden file comparison for provider snapshot validation in sync_test.go
- Introduce master_test.go for testing Master/Key functionality
- Add testdata directory for contract testing snapshots
2025-12-14 23:37:16 +08:00
zenfun
d0011f3eb2 test: add comprehensive unit tests for provider, middleware, and sync service
- Add TESTING.md documentation explaining unit test conventions and integration testing setup
- Add miniredis and sqlite dependencies to go.mod for in-memory testing
- Add provider_handler_test.go ensuring Vertex providers default google_location to "global"
- Add request_id_test.go verifying request ID generation and header preservation
- Add sync_test.go validating Redis snapshot writes and routing key generation
- Update README.md with testing section referencing new documentation
2025-12-14 00:35:35 +08:00
zenfun
50da2ff668 chore: bump foundation to v0.1.0 2025-12-14 00:03:49 +08:00
zenfun
531ac6e5a8 feat(telemetry): implement request tracing identifier
Introduce a middleware layer to attach a unique identifier to each HTTP request for observability purposes. The identifier is propagated via the X-Request-ID header, allowing for correlation of logs and events across distributed system components.
2025-12-13 23:49:58 +08:00
zenfun
a6b4306d08 feat(server): add request ID middleware
Add request ID middleware to trace requests through the system. The middleware checks for existing X-Request-ID headers, generates a new UUID if not present, and sets the ID in both request/response headers and Gin context.
2025-12-13 22:24:37 +08:00
zenfun
67df74e09a feat(provider): add google project and location fields
Add support for Google Cloud-specific configuration in provider models.
New fields `GoogleProject` and `GoogleLocation` are now included in the
Provider DTO, database model, API handlers, and sync service snapshots.

- Extend Provider struct in model with gorm/json tags
- Update ProviderDTO with omitempty JSON tags
- Include fields in handler create/update logic with trim
- Add fields to providerSnapshot for sync operations
2025-12-13 20:24:44 +08:00
zenfun
89cb74ba6e refactor(log): migrate from zerolog to structured slog with bridge
- Replace direct zerolog usage with standard library `log/slog` in business code
- Add `internal/logging` package with zerolog bridge handler for structured output
- Create `internal/jsoncodec` package to centralize JSON encoding/decoding using Sonic
- Update all services and main entry point to use new logging interface
- Maintain backward compatibility with existing zerolog console output
- Remove custom logger setup in favor of structured logging bridge
2025-12-13 16:50:56 +08:00
zenfun
305f2ebf18 feat(provider): add update endpoint and enforce status checks
Add `PUT /admin/providers/{id}` endpoint to allow updating provider
configurations, including status and ban details. Update synchronization
logic to exclude inactive or banned providers from routing tables to
ensure traffic is not routed to them.
2025-12-12 23:44:52 +08:00
zenfun
2407afe0e6 feat(provider): add status and banning mechanism
Introduce fields for managing provider status (active, auto_disabled,
manual_disabled) and banning logic.

- Add Status, AutoBan, BanReason, and BanUntil to Provider model and DTO
- Update CreateProvider handler to process new fields with defaults
- Extend sync service to propagate status and ban information in snapshots
- Serialize BanUntil as Unix timestamp for sync compatibility
2025-12-12 23:40:18 +08:00
zenfun
eaf99e1582 feat(config): migrate configuration management to viper
Replace manual environment variable parsing with Viper to support
file-based configuration.

- Enable loading config from `config.yaml` or `./config/config.yaml`
- Allow custom config path via `EZ_CONFIG_FILE` environment variable
- Bind existing environment variables to maintain backward compatibility
- Update documentation with configuration examples and precedence rules
2025-12-12 22:50:54 +08:00
zenfun
5891722526 feat(log): replace standard logger with zerolog
- Integrate `rs/zerolog` for structured and leveled logging
- Add `EZ_LOG_LEVEL` environment variable support (default: info)
- Configure console output with timestamps and service fields
- Migrate `main.go` and `LogWriter` to use the new logger instance
- Update README with logging configuration and design details
2025-12-12 22:39:10 +08:00
zenfun
5826db3954 perf(json): replace encoding/json with bytedance/sonic
Migrate all JSON marshaling and unmarshaling operations to use
github.com/bytedance/sonic for improved performance. This affects
adapters, middleware, proxy handlers, and the sync store.
2025-12-10 23:21:51 +08:00
770a9fef2b feat: Add Swagger documentation for admin and master API endpoints
- Added Swagger documentation for the following admin endpoints:
  - Create a new master tenant
  - Create a new provider
  - Register a new model
  - List all models
  - Update a model
  - Force sync snapshot
  - Ingest logs

- Added Swagger documentation for the master endpoint:
  - Issue a child key

- Updated go.mod and go.sum to include necessary dependencies for Swagger.
2025-12-05 15:01:35 +08:00
zenfun
25e5e105b3 feat(auth): enhance security with token hashing and sync integration
- Add token hash fields to Master and Key models for indexed lookups
- Implement SyncService integration in admin and master handlers
- Update master key validation with backward-compatible digest lookup
- Hash child keys in database and store token digests for Redis sync
- Add master metadata sync to Redis for balancer validation
- Ensure backward compatibility with legacy rows during migration
2025-12-05 00:17:22 +08:00
zenfun
8645b22b83 feat(auth): implement master key authentication system with child key issuance
Add admin and master authentication layers with JWT support. Replace direct
key creation with hierarchical master/child key system. Update database
schema to support master accounts with configurable limits and epoch-based
key revocation. Add health check endpoint with system status monitoring.

BREAKING CHANGE: Removed direct POST /keys endpoint in favor of master-based
key issuance through /v1/tokens. Database migration requires dropping old User
table and creating Master table with new relationships.
2025-12-05 00:16:47 +08:00
5360cc6f1a feat(test): update integration tests to include models in provider creation and clean up code 2025-12-03 08:46:50 +08:00
b8bd613f77 feat(provider): add Models field to ProviderDTO and update provider handling 2025-12-02 16:32:03 +08:00
zenfun
d147f3ab04 test(integration): reorganize test structure and add runner script
- Move integration tests and mock upstream resources from `integration/` to `test/` directory.
- Add `test/integration.sh` script to orchestrate environment setup and test execution.
- Update build context in `docker-compose.integration.yml` to match new structure.
- Add documentation for local development and integration testing workflows in README.
2025-12-02 15:56:17 +08:00
zenfun
a0f13d55c1 docs: update readme with system architecture and usage guide
Replace placeholder with comprehensive documentation including:
- System goals and control plane responsibilities
- Architecture design and technology stack
- API endpoint reference for management and system interfaces
- Configuration variables and default values
- Deployment instructions for local and Docker environments
2025-12-02 15:00:13 +08:00
zenfun
f56f9215d8 test(integration): add e2e testing suite and infrastructure
Introduces a comprehensive integration testing setup and local development environment.

Changes include:
- Add `docker-compose.yml` for local stack orchestration.
- Add `docker-compose.integration.yml` for the integration test environment.
- Create `mock-upstream` service to simulate external LLM provider responses.
- Implement Go-based end-to-end tests verifying control plane configuration and data plane routing.
- Add `integration_test.sh` for quick connectivity verification.
2025-12-02 14:51:33 +08:00
zenfun
aa57af874c feat(core): implement group-based routing and optimize sync
Replace direct provider linkage with group-based routing for Keys and
Providers. This allows for more flexible load balancing and tiering
strategies.

Changes include:
- Remove `ProviderID` from Key model and DTO
- Add `Group` field to Key and Provider models
- Refactor Redis sync to use Hashes for O(1) partial updates
- Update API handlers to perform incremental syncs

BREAKING CHANGE: Key API payload no longer accepts `provider_id`. Redis
configuration storage format has changed from JSON strings to Hashes.
2025-12-02 14:49:03 +08:00
57d92de5e6 feat(docker): add docker-compose configuration for PostgreSQL, Redis, EZ-API, and Balancer services 2025-12-02 14:33:07 +08:00
zenfun
64d71953a6 feat(server): implement management endpoints and redis sync
Enable full resource management via API and support data plane
synchronization.

- Add CRUD handlers for Providers, Models, and Keys using DTOs
- Implement LogWriter service for asynchronous, batched audit logging
- Update SyncService to snapshot full configuration state to Redis
- Register new API routes and initialize background services
- Add configuration options for logging performance tuning
2025-12-02 14:26:16 +08:00
zenfun
2c3a6af7bf add readme 2025-12-02 13:55:51 +08:00
zenfun
58dfe5e9ac feat(server): initialize project skeleton with db and api setup
Establish the foundational structure for the ez-api server.

Key changes include:
- Set up main entry point with graceful shutdown and Gin router
- Configure database connections for PostgreSQL (GORM) and Redis
- Define core data models (User, Provider, Key, Model)
- Implement configuration loading and basic key creation handler
- Add Dockerfile for multi-stage builds and .gitignore
2025-12-02 13:35:17 +08:00