Overview
Add support for distributing load across multiple Matomo instances, enabling users to test scenarios with multiple tracking endpoints concurrently.
Motivation
- Scalability testing: Validate that multiple Matomo instances can handle distributed loads
- Multi-tenant scenarios: Test SaaS deployments with separate instances per customer
- High availability: Verify failover and load balancing configurations
- Realistic workloads: Mirror production architectures with multiple tracking endpoints
Acceptance Criteria
Backend (Loader)
Configuration Model
Control UI - Backend
Control UI - Frontend
Documentation & Testing
Technical Approach
Async Concurrency Pattern
Based on research from httpx and docker-py documentation:
import httpx
import asyncio
async def send_to_target(client: httpx.AsyncClient, target: dict, tracking_data: dict):
"""Send tracking request to a single target"""
try:
response = await client.post(
f"{target['url']}/matomo.php",
data=tracking_data,
timeout=10.0
)
return {"target": target["url"], "status": response.status_code}
except Exception as e:
return {"target": target["url"], "error": str(e)}
async def distribute_requests(targets: list, tracking_data: dict):
"""Concurrently send requests to all targets"""
async with httpx.AsyncClient(http2=True) as client:
tasks = [send_to_target(client, target, tracking_data) for target in targets]
results = await asyncio.gather(*tasks, return_exceptions=True)
return results
Data Model Extension
class Target(BaseModel):
url: HttpUrl
site_id: int
token_auth: Optional[str] = None
weight: int = 1 # For weighted distribution
enabled: bool = True
class MultiTargetConfig(BaseModel):
targets: List[Target]
distribution_strategy: Literal["round-robin", "weighted", "random"] = "round-robin"
# ... existing config fields
Implementation Plan
-
Research & Design (Step 1 - CURRENT)
- Research async patterns (Context7 MCP) ✅
- Create GitHub issue ✅
- Draft ADR for design decisions
-
Backend Data Models (Step 2)
- Extend Pydantic models
- Update SQLite schema
- Add migration if needed
-
Loader Multi-Target Support (Step 3)
- Implement async distribution logic
- Add per-target metrics
- Create unit tests
-
Control UI Updates (Step 4)
- Backend API updates
- Frontend target editor
- Status dashboard enhancements
-
Documentation & Testing (Step 5)
- Integration tests
- User documentation
- Create PR
Dependencies
- None (can start immediately)
Estimated Effort
- Backend: 4-6 hours
- Frontend: 3-4 hours
- Testing & Docs: 2-3 hours
- Total: 8-12 hours
References
Overview
Add support for distributing load across multiple Matomo instances, enabling users to test scenarios with multiple tracking endpoints concurrently.
Motivation
Acceptance Criteria
Backend (Loader)
asyncio+httpx.AsyncClientConfiguration Model
Control UI - Backend
/api/validateto test all target connections/api/statusto return per-target statistics/api/presetsto persist multi-target configurations/api/targetsCRUD endpoints (optional, if needed)Control UI - Frontend
Documentation & Testing
Technical Approach
Async Concurrency Pattern
Based on research from httpx and docker-py documentation:
Data Model Extension
Implementation Plan
Research & Design (Step 1 - CURRENT)
Backend Data Models (Step 2)
Loader Multi-Target Support (Step 3)
Control UI Updates (Step 4)
Documentation & Testing (Step 5)
Dependencies
Estimated Effort
References
P-008