Skip to content

feat(BA-2734): Add domain-level app configuration support for frontend#6401

Merged
HyeockJinKim merged 4 commits into
mainfrom
feat/add-domain-level-config-db
Oct 26, 2025
Merged

feat(BA-2734): Add domain-level app configuration support for frontend#6401
HyeockJinKim merged 4 commits into
mainfrom
feat/add-domain-level-config-db

Conversation

@HyeockJinKim
Copy link
Copy Markdown
Collaborator

Implement scope-based configuration system with database schema,
repository pattern, and cache layer for efficient configuration
management.

  • Add app_configs table with scope-based design (DOMAIN/PROJECT/USER)
  • Implement hierarchical config merging (domain → user override)
  • Add repository pattern with DB and cache sources
  • Create ValkeyCache client for manager-level cache operations
  • Implement efficient domain-level cache invalidation using Redis Sets
  • Use Batch operations for atomic-like cache updates

Database Schema:

  • app_configs table with scope_type, scope_id, and JSONB extra_config
  • Unique constraint on (scope_type, scope_id)
  • Created alembic migration c3b9dacd4f79

Data Models:

  • AppConfigData: Database row representation
  • MergedAppConfig: Contains domain_name, user_id, and merged config
  • AppConfigCreator/Modifier: For create and upsert operations

Repository Pattern:

  • AppConfigDBSource: Handles all database operations
  • AppConfigCacheSource: Handles Redis/Valkey cache operations
  • AppConfigRepository: Combines sources with cache-aside pattern
  • ValkeyCache: Manager-level client providing direct Glide access

Cache Strategy:

  • Cache merged configs per user with 10-minute TTL
  • Track users per domain using Redis Sets
  • Domain config changes invalidate all domain users
  • User config changes invalidate only that user
  • Use Valkey Batch for efficient multi-operation execution

resolves #6294 (BA-2734)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

Copilot AI review requested due to automatic review settings October 26, 2025 03:03
@github-actions github-actions Bot added size:XL 500~ LoC comp:manager Related to Manager component require:db-migration Automatically set when alembic migrations are added or updated labels Oct 26, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive configuration management system for frontend applications with support for domain, project, and user-level scopes. The implementation follows a repository pattern with database persistence and Redis/Valkey caching for efficient configuration retrieval.

Key changes include:

  • Database schema with app_configs table supporting hierarchical scope-based configuration (domain → project → user)
  • Repository pattern implementation with separate DB and cache sources
  • Cache invalidation strategy using Redis Sets to track domain-user relationships
  • ValkeyCache client wrapper providing direct Glide client access for cache operations

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ai/backend/manager/models/alembic/versions/c3b9dacd4f79_*.py Alembic migration creating app_configs table with scope-based design
src/ai/backend/manager/models/app_config.py SQLAlchemy model definition for app_configs table
src/ai/backend/manager/data/app_config/types.py Data models for configuration entities and operations
src/ai/backend/manager/repositories/app_config/db_source/db_source.py Database operations layer with config merging logic
src/ai/backend/manager/repositories/app_config/cache_source/cache_source.py Cache operations with domain-level invalidation using Redis Sets
src/ai/backend/manager/repositories/app_config/repository.py Main repository coordinating DB and cache sources
src/ai/backend/manager/clients/valkey_client/valkey_cache/client.py ValkeyCache client wrapper for direct Glide access
src/ai/backend/manager/repositories/utils.py Shared repository utilities including exception suppression
tests/manager/repositories/app_config/test_app_config.py Comprehensive integration tests for repository functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +20 to +22
count = 0


Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global variable 'count' appears to be debug code that should be removed before merging to production. This creates shared mutable state that will cause issues in multi-threaded/async environments and is not thread-safe.

Suggested change
count = 0

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +62
global count
count += 1
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug code using global variable should be removed. This counter is not thread-safe and will produce incorrect results in concurrent environments.

Copilot uses AI. Check for mistakes.
global count
count += 1
if cached_value:
log.debug("Cache hit for merged config: {}, hit count: {}", user_id, count)
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug logging with global counter. This appears to be temporary debugging code.

Copilot uses AI. Check for mistakes.
Implement scope-based configuration system with database schema,
repository pattern, and cache layer for efficient configuration
management.

- Add app_configs table with scope-based design (DOMAIN/PROJECT/USER)
- Implement hierarchical config merging (domain → user override)
- Add repository pattern with DB and cache sources
- Create ValkeyCache client for manager-level cache operations
- Implement efficient domain-level cache invalidation using Redis Sets
- Use Batch operations for atomic-like cache updates

Database Schema:
- app_configs table with scope_type, scope_id, and JSONB extra_config
- Unique constraint on (scope_type, scope_id)
- Created alembic migration c3b9dacd4f79

Data Models:
- AppConfigData: Database row representation
- MergedAppConfig: Contains domain_name, user_id, and merged config
- AppConfigCreator/Modifier: For create and upsert operations

Repository Pattern:
- AppConfigDBSource: Handles all database operations
- AppConfigCacheSource: Handles Redis/Valkey cache operations
- AppConfigRepository: Combines sources with cache-aside pattern
- ValkeyCache: Manager-level client providing direct Glide access

Cache Strategy:
- Cache merged configs per user with 10-minute TTL
- Track users per domain using Redis Sets
- Domain config changes invalidate all domain users
- User config changes invalidate only that user
- Use Valkey Batch for efficient multi-operation execution
Add comprehensive tests for AppConfigRepository with real database
and Valkey cache. Fix circular import issue by moving AppConfigScopeType
to data layer.

Tests:
- Create domain-level and user-level configurations
- Test merged config retrieval with override logic
- Test upsert (create/update) operations
- Test delete operations
- Test cache invalidation on config updates

Fixtures:
- test_domain_name: Creates domain in DB, returns domain name string
- test_user_id: Creates user in DB, returns user UUID string
- valkey_stat_client: Real Valkey client using redis container
- app_config_repository: Repository with real DB and cache

Fixes:
- Move AppConfigScopeType from models to data/app_config/types
- Prevents circular dependency between models and data layers
@HyeockJinKim HyeockJinKim force-pushed the feat/add-domain-level-config-db branch from 63e59fb to cfa39b2 Compare October 26, 2025 03:17
@HyeockJinKim HyeockJinKim added this pull request to the merge queue Oct 26, 2025
Merged via the queue into main with commit 3cf1f71 Oct 26, 2025
31 checks passed
@HyeockJinKim HyeockJinKim deleted the feat/add-domain-level-config-db branch October 26, 2025 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component require:db-migration Automatically set when alembic migrations are added or updated size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add database schema for domain-level configuration storage

2 participants