4.8 KiB
4.8 KiB
1. Project Setup & Common Utilities
- 1.1 Create project structure,
requirements.txt(withconfluent-kafka,clickhouse-connect,phonenumbers), and.env.exampledefining all environment variables and verify file presence. - 1.2 Implement standard library structured JSON logging module emitting
timestamp,level,service,raw_id, andevent, and verify output formatting with unit test. - 1.3 Create idempotent ClickHouse canonical initialization schema (
app/worker/schema.sql) creating databasetelecomandReplacingMergeTreetablecdr_recordswith TTL and indexing settings, and verify schema correctness.
2. Framework-less Async Ingestion API
- 2.1 Implement lightweight HTTP/1.1 server using standard library
asyncio.start_serverwith route dispatching forPOST /api/v1/cdr/raw,GET /metrics, andGET /stats. - 2.2 Implement bounded outstanding-delivery backpressure: verify
429 Too Many Requestsat capacity and202 Acceptedonly after broker acknowledgement. - 2.3 Implement incoming payload validation: verify
400 Bad Requestwith structured JSON error{ "error": "...", "detail": "..." }on malformed JSON or missing required fields. - 2.4 Integrate
confluent-kafkaproducer publishing tocdr.rawusingraw_idas message key, and return503 Service Unavailableif Kafka is unreachable. - 2.5 Implement Prometheus metrics endpoint (
cdr_api_received_total) and publicGET /statsendpoint that fetches worker runtime stats via internal HTTP and returns unified JSON.
3. Processing Worker Implementation
- 3.1 Implement Kafka consumer loop with
confluent-kafkaconsuming fromcdr.rawand DLQ producer publishing tocdr.raw.dlq. - 3.2 Implement safe parser routing malformed records to DLQ with structured envelope and reason taxonomy (
missing_required_field,invalid_rat_value,invalid_epoch,malformed_json,normalization_error). - 3.3 Implement schema normalizer: E.164 phone conversion via
phonenumbers, RAT mapping (1→3G,6→LTE_4G,9→5G_NR),cell_idderivation (lac_ci), and deterministic UUIDv5cdr_idgeneration. - 3.4 Implement micro-batching buffer flushing on 1,000 records or 2 seconds elapsed, batch-inserting into ClickHouse via
clickhouse-connect, and committing offsets only after ClickHouse ACK. - 3.5 Implement exponential backoff retry for ClickHouse write timeouts (
CH_RETRY_MAX_ATTEMPTS,CH_RETRY_INITIAL_DELAY_MS,CH_RETRY_BACKOFF_FACTOR) with fallback to DLQ. - 3.6 Implement worker internal HTTP stats endpoint (
GET /internal/stats) and worker Prometheus metrics (cdr_processed_total,cdr_dlq_total, histograms, gauges). - 3.7 Implement
SIGTERMandSIGINTsignal handlers to stop consuming, flush remaining in-memory buffer to ClickHouse, commit offsets, and exit cleanly without data loss.
4. Containerization & Orchestration
- 4.1 Create lightweight Dockerfiles for Ingestion API and Processing Worker without framework dependencies.
- 4.2 Create
docker-compose.ymldefining Kafka/Redpanda, ClickHouse, Ingestion API, and Processing Worker with healthcheck blocks anddepends_on: { condition: service_healthy }.
5. Verification & Test Traffic Generator
- 5.1 Implement traffic generator script covering the 7 mandatory scenarios (valid records, missing fields, malformed JSON, bad RAT, invalid epoch, duplicates, burst load).
- 5.2 Implement automated verification summary reporting verifying ClickHouse counts, DLQ counts, API 400 errors, and duplicate resolution.
- 5.3 Write comprehensive
README.mdcovering quickstart, architecture, micro-batching, offset management, deduplication, monitoring, and configuration reference.
6. Delivery Safety Regression Gates
- 6.1 Add and pass unit regressions for confirmed API delivery, shutdown, strict validation and HTTP limits.
- 6.2 Add and pass worker regressions for partition ordering, DLQ failure, commit failure, replay, batching, range checks and telemetry.
- 6.3 Run isolated Compose integration with independent ports/storage, fresh defaults, schema collision/replay and failure recovery checks.
- 6.4 Run actual DLQ traffic verification and the acknowledged 500-record burst; record evidence in README.
- 6.5 Validate OpenSpec and reconcile all task completion claims with evidence.
Current evidence
The current files pass 64 pytest tests, resolved Compose configuration validation, git diff --check, and strict OpenSpec validation. The isolated 2026-09-20 Compose assessment passed all seven traffic scenarios with run-correlated ClickHouse and Kafka DLQ evidence, metric deltas, schema collision protection, broker recovery, worker restart/replay, and the acknowledged 500-record burst. The disposable project and its volumes were removed after verification.