Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .assistant/backlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,17 @@
deps: none
accepts: Users can add Python modules to define custom traffic behaviors

- [ ] **P-032** Historical backfill mode (date-ranged traffic replay)
tags: feature, data, matomo priority: medium est: 6h
- [x] **P-032** Historical backfill mode (date-ranged traffic replay)
tags: feature, data, matomo priority: medium est: 6h completed: 2025-11-27
deps: P-006 (patterns), P-015 (backend)
accepts: Backfill mode to generate timestamped visits over a configurable past window (e.g., 30–90 days) with timezone-aware `cdt`, optional visits-per-day override, guardrails on date ranges, and optional deterministic seeds for reruns.
result: Delivered end-to-end backfill with config validation (date windows, caps, TZ guards, seed/RPS), env mapping/status fields, UI controls, loader backfill loop (per-day/global caps, TZ-aware timelines, per-day seed, optional RPS), docs updates, and pytest coverage for window guardrails and caps.
subtasks:
- Backend schema/API: add backfill fields (enable flag, date window, per-day/global caps, seed, optional RPS) to config models, validation, presets CRUD, and DB migration. ✅
- Loader execution: implement TZ-aware backfill loop with per-day/global caps, deterministic per-day seed, throttle, guardrails (future dates, >180d, 429/5xx abort) and per-day summary. ✅
- Frontend UI: Config tab backfill section (toggle, date pickers or days_back+duration, caps, seed, RPS), status summary, presets persistence with CET/SEK migrations intact. ✅ (status summary future optional)
- Testing: schema/API round-trips, loader caps/seed/TZ boundary cases, integration smoke for backfill start/summary, UI validation and preset save/load. ✅ (new pytest for window/caps; integration/manual)
- Docs: WEB_UI_GUIDE backfill section, presets/README env updates, assistant guides/status refresh if needed. ✅

## Infrastructure
- [ ] **P-011** Kubernetes manifests for k8s deployments
Expand Down
67 changes: 38 additions & 29 deletions .assistant/status.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
# Status

**Last Updated:** 2025-10-30 (P-018 Configuration Persistence Complete)
**Last Updated:** 2025-12-05 (P-032 complete, PR pending)

---

## Focus
- Capture follow-up QA for the new presets API and tee up Phase 3 polish (P-025 documentation/testing, P-026 enhancements).
- Merge backfill feature (P-032) from `develop→main`; then shape multi-target support (P-008).

---

## Now / Next / Later
- **Now:** Verify presets persistence end-to-end when runtime is available and note any integration gaps for QA.
- **Next:** Phase 3 polish — P-025 testing + documentation refresh, P-026 enhancement triage.
- **Later:** Phase 4 nice-to-haves (advanced features, metrics, websockets) once polish is stable.
- **Now:** Create PR for P-032 backfill release; merge to main; tag v0.3.0.
- **Next:** Design P-008 (multi-target config/API/loader) and deepen user journey realism (P-006).
- **Later:** P-026 enhancements (websocket logs, graphs, dark mode) plus P-009/P-010 observability/extensibility.

---

## Risks
- **Data integrity:** Need consistent schema between backend models and frontend form payloads.
- **Migration:** Must handle legacy `.env`-only setups without breaking existing deployments.
- **Concurrency:** Simultaneous edits from multiple sessions could cause stale writes without extra safeguards.
- **Testing gap:** Limited automated coverage for DB-backed flows; regression risk during refactors.
- **Config drift:** Multi-target schemas could desync between backend models, DB, and UI forms.
- **Back-compat:** Legacy presets with UTC/USD values may surface unless migrations stay enforced end-to-end.
- **Testing gap:** Limited automated coverage for new funnels/URL/event editors; backfill integration tested via unit tests.

---

## Artifacts
- `control-ui/app.py` — FastAPI entrypoint with routing.
- `control-ui/db.py` — SQLite session helpers (expanding for P-018).
- `control-ui/models.py` — Pydantic models shared across API.
- `control-ui/static/js/app.js` — Frontend controller orchestrating API calls.
- `docker-compose.webui.yml` — Compose stack for control UI + generator.
- `.assistant/ai_guidance.md` — Current AI-assistant quickstart (replaces legacy CLAUDE.md).
- `tools/validate_config.py` — CLI validator for environment variables and Matomo connectivity.
- `presets/.env.*` — Ready-to-use Light/Medium/Heavy environment presets for Docker Compose.
- `control-ui/app.py`, `db.py`, `models.py`, `config_validator.py`, `container_manager.py` — FastAPI + SQLite core + backfill validation.
- `control-ui/static/js/{app,config,presets,urls,funnels,status}.js` — UI controllers including backfill config/status.
- `control-ui/static/index.html` — Web UI shell (Tailwind CDN) with Backfill section.
- `matomo-load-baked/loader.py` — Loader with funnels, backfill mode, CET/SEK defaults.
- `matomo-load-baked/tests/test_backfill.py` — pytest coverage for backfill windows/caps.
- `tools/validate_config.py` — CLI validator and Matomo connectivity probe.
- `presets/.env.{light,medium,heavy,extreme}` — Prebuilt presets (CET/SEK defaults).
- `WEB_UI_GUIDE.md`, `presets/README.md` — Backfill usage documentation.

---

## Recent Progress
- Completed P-015 through P-017 (FastAPI service, REST endpoints, validation + Matomo connectivity).
- Security baseline (P-019) landed: API key auth, CORS, rate limiting, headers.
- Frontend skeleton (P-020+) committed: responsive layout, config form, status dashboard, presets, log viewer.
- Added pytest coverage for ecommerce/events plus CLI validation utility (P-003/P-004).
- Published Docker Compose presets for Light/Medium/Heavy workloads (P-005).
- Delivered funnel data model and CRUD API groundwork (P-029A) ahead of loader/UI implementation.
- Loader now executes funnel journeys with probability/priority rules and tests (P-029B).
- Built Funnels UI tab with templates, editor, and preview to manage journeys (P-029C).
- Documented funnel workflow, added export CLI, and updated compose sharing (P-029D).
- **P-032 Bug Fix:** Fixed critical backfill issue where timestamps were sent in local timezone instead of UTC
- Root cause: Matomo `cdt` parameter expects UTC, but we were sending CET times
- Solution: Added `format_cdt()` helper that converts timezone-aware datetimes to UTC
- Test: `test_format_cdt_converts_to_utc()` confirms 14:30 CET → 13:30 UTC
- **P-032 Complete:** Historical backfill mode delivered end-to-end:
- Config validation (date windows ≤180d, no future dates, caps, TZ guards, seed/RPS)
- Env mapping and status model fields
- UI: Config tab Backfill section, Status tab Backfill panel
- Loader: TZ-aware backfill loop, per-day/global caps, deterministic seeds, optional RPS
- Tests: pytest coverage for window guardrails and caps (5 tests)
- Docs: WEB_UI_GUIDE and presets/README updated
- `develop` branch ahead of `main` by 6 commits (backfill feature + UTC fix)
- PR #11 updated with fix

---

## Pending Actions
- [x] Create PR `develop→main` for P-032 release — **PR #11**: https://github.com/Puttrix/Trafficinator/pull/11
- [ ] Merge and tag v0.3.0
- [ ] Update backlog with next focus (P-008/P-006)

---

## Open Questions
- Do we need optimistic locking/version stamps for saved configs?
- Should presets live in the same table as ad-hoc configs or stay file-based?
- How are secrets (tokens) persisted—store hashed, encrypted, or prompt on load?
- How should multi-target configs be structured (per-target auth, weights, caps) and reflected in API/UI?
- Should CET/SEK migrations also rewrite persisted presets on save to avoid mixed defaults?
66 changes: 66 additions & 0 deletions .assistant/task_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,69 @@
- tool: apply_patch (.assistant/backlog.md)
- result: Added P-032 Historical backfill mode to backlog: date-ranged traffic replay (30–90 days), timezone-aware `cdt`, visits-per-day override, guardrails on date ranges, optional deterministic seeds.
- artifacts: .assistant/backlog.md

## 2025-11-27
- tool: apply_patch (.assistant/status.md)
- args: Refreshed status from backlog/task_log to emphasize P-008 multi-target focus, P-032 backfill planning, and CET/SEK default migrations.
- result: Updated focus, Now/Next/Later, risks, artifacts, recent progress, and open questions to align with current backlog/task_log.
- artifacts: .assistant/status.md

- tool: apply_patch (.assistant/backlog.md)
- args: Added detailed P-032 subtasks (backend schema/API, loader execution, UI, testing, docs).
- result: Backlog now tracks the full breakdown for historical backfill mode.
- artifacts: .assistant/backlog.md

- tool: apply_patch (control-ui/config_validator.py; control-ui/models.py; control-ui/container_manager.py)
- args: Introduced backfill config fields/validation (date windows, caps, seed, RPS), warnings, status model fields, and env mapping for API/apply flows.
- result: Backend accepts and validates backfill settings with guardrails (window <=180d, no future dates, caps consistency) and exposes env mapping/status fields for upcoming UI/loader work.
- artifacts: control-ui/config_validator.py, control-ui/models.py, control-ui/container_manager.py

- tool: apply_patch (matomo-load-baked/loader.py)
- args: Added backfill execution path: env parsing, TZ-aware date window selection, per-day/global caps, optional RPS limit, per-day seed offsets, and day-bound visit timelines. Split realtime/backfill loops and kept existing behavior for non-backfill runs.
- result: Loader can run historical backfill over bounded windows with per-day targets while keeping visits inside each day's timezone bounds; realtime mode unchanged.
- artifacts: matomo-load-baked/loader.py

- tool: apply_patch (control-ui/static/index.html; control-ui/static/js/config.js)
- args: Added Backfill section to Config UI (enable toggle, date or relative window, caps, RPS limit, seed) and wired env parsing/form data handling for backfill fields; skipped empty numeric fields to avoid forcing zeros.
- result: UI can configure backfill settings, and config parsing/saving supports new fields for presets/status/apply flows.
- artifacts: control-ui/static/index.html, control-ui/static/js/config.js

- tool: apply_patch (WEB_UI_GUIDE.md; presets/README.md)
- args: Documented backfill usage in the Config tab (absolute/relative window, caps, RPS, seed, guardrails) and added preset README guidance for enabling backfill via env vars.
- result: Users have guidance for configuring historical replay and enabling it through env files or UI.
- artifacts: WEB_UI_GUIDE.md, presets/README.md

- tool: apply_patch (matomo-load-baked/loader.py; matomo-load-baked/tests/test_backfill.py)
- args: Made backfill runner return summaries and added pytest coverage for backfill windows (absolute/relative guards) and caps/seed path with a stubbed run_backfill_day.
- result: Backfill logic is testable; guardrails enforced via tests and backfill summary returned for assertions.
- artifacts: matomo-load-baked/loader.py, matomo-load-baked/tests/test_backfill.py

- tool: shell (python3 -m pytest matomo-load-baked/tests/test_backfill.py)
- result: Tests passed (4 passed).
- artifacts: none

- tool: apply_patch (control-ui/static/index.html; control-ui/static/js/status.js)
- args: Added Backfill Status panel on the Status tab and wired status parsing to show window type, caps, throttle, and seed when backfill is enabled; shows disabled state otherwise.
- result: Users can see backfill activation/config summary directly in the Status tab using container env values.
- artifacts: control-ui/static/index.html, control-ui/static/js/status.js

## 2025-12-05
- tool: shell (cat > .assistant/status.md)
- args: Refreshed status.md from backlog/task_log; P-032 complete, `develop` ahead of `main` by 5 commits.
- result: Updated focus to PR creation, Now/Next/Later, artifacts list, recent progress with P-032 breakdown.
- artifacts: .assistant/status.md

- tool: mcp_github_github_create_pull_request
- args: owner=Puttrix, repo=Trafficinator, title="feat: Historical backfill mode (P-032)", head=develop, base=main
- result: PR #11 created successfully
- artifacts: https://github.com/Puttrix/Trafficinator/pull/11

- tool: apply_patch (matomo-load-baked/loader.py)
- args: Added format_cdt() helper that converts timezone-aware datetimes to UTC before formatting; replaced all strftime calls for cdt param with format_cdt().
- result: Fixed P-032 backfill bug where timestamps were sent in local timezone instead of UTC. Matomo expects cdt in UTC but we were sending CET times without conversion, causing visits to appear at wrong times.
- artifacts: matomo-load-baked/loader.py

- tool: apply_patch (matomo-load-baked/tests/test_backfill.py)
- args: Added test_format_cdt_converts_to_utc() to verify CET→UTC conversion.
- result: Test confirms 14:30 CET → 13:30 UTC and midnight CET → 23:00 previous day UTC.
- artifacts: matomo-load-baked/tests/test_backfill.py
11 changes: 11 additions & 0 deletions WEB_UI_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ The Web UI consists of 5 main tabs:
- **Visit Behavior** - Duration, pauses, probabilities
- **E-commerce** - Order values, currency
- **System** - Timezone, auto-stop, limits
- **Backfill (Historical Replay)** - Date-ranged replay with caps, throttle, and deterministic seed
- **Real-time Validation** - Instant feedback on invalid values
- **Test Connection** - Verify Matomo accessibility
- **Conditional Fields** - E-commerce fields appear when enabled
Expand All @@ -166,6 +167,16 @@ The Web UI consists of 5 main tabs:
8. Restart container for changes to take effect
```

**Backfill (Historical Replay):**
```
1) Toggle “Enable Backfill” to switch from realtime to historical replay.
2) Choose either absolute dates (start/end) or a relative window (days back + duration). Do not mix both.
3) Set caps: Max visits/day (default 2,000, max 10,000) and Max visits total (default 200k; 0 disables).
4) Optionally set RPS limit to throttle requests and a deterministic seed for repeatable runs (per-day offset applied).
5) Keep TIMEZONE aligned with Matomo; dates are enforced TZ-aware with guards against future dates and >180-day windows (warning above 90).
```
Guardrails: window must end on/before today; start <= end; max 180 days; caps must be consistent (total ≥ per-day); warnings on very high per-day caps and RPS.

**Field Reference:**

| Field | Description | Default | Range |
Expand Down
Loading