docs(obs): add observability foundation reference for BIT-14225
ai-news-writer-ci / test (pull_request) Failing after 0s
ai-news-writer-ci / test (pull_request) Failing after 0s
Documents the monitoring stack delivered by BIT-14225: structured logging, Prometheus metrics, health/metrics HTTP endpoints, and webhook alerting. All implementation files were committed in prior commits (b095214,de9fff6, etc.); this adds the ops reference doc. Paperclip-Task-Id: BIT-14225 Paperclip-Run-Id: $PAPERCLIP_RUN_ID
This commit is contained in:
1 parent
38ebc60ad9
commit
eb6b99e2fe
1 file changed
+250
@@ -0,0 +1,250 @@
|
||||
# Observability Foundation — BIT-14225
|
||||
|
||||
This document describes the observability foundation (logs, metrics, alerts) for ai-news-writer as part of BIT-2708.3.
|
||||
|
||||
## Overview
|
||||
|
||||
The ai-news-writer application includes a comprehensive observability foundation with:
|
||||
|
||||
- **Metrics**: In-process collection with Prometheus-compatible exposition
|
||||
- **Structured Logging**: JSON-formatted logs with correlation IDs
|
||||
- **Health Checks**: HTTP endpoints for monitoring and load balancers
|
||||
- **Alerting**: Webhook-based pipeline alerts for critical failures
|
||||
|
||||
## Components
|
||||
|
||||
### 1. Metrics System
|
||||
|
||||
**Location**: `src/monitoring/metrics.js`
|
||||
|
||||
**Features**:
|
||||
- **Counters**: Increment-only metrics (articles generated, errors, etc.)
|
||||
- **Histograms**: Latency and size distributions with percentiles
|
||||
- **Gauges**: Point-in-time values (memory usage, queue depth, etc.)
|
||||
- **System Metrics**: Automatic CPU, memory, and load avg tracking
|
||||
- **Prometheus Exposition**: OpenMetrics 0.0.4 text format for scraping
|
||||
|
||||
**Key Metrics**:
|
||||
- `articles.generated`, `articles.published`, `articles.failed`
|
||||
- `pipeline.*` - RSS fetch, scrape, parse, publish operations
|
||||
- `quality.score` - Article quality assessment
|
||||
- `process.memory.*`, `process.cpu.*`, `process.loadavg*`
|
||||
|
||||
### 2. Pipeline-Specific Metrics
|
||||
|
||||
**Location**: `src/monitoring/pipeline-metrics.js`
|
||||
|
||||
**Features**:
|
||||
- Source-specific fetch tracking with success/failure rates
|
||||
- Scrape quality and extraction strategy metrics
|
||||
- Parse operation tracking by type (RSS, HTML, JSON)
|
||||
- Circuit breaker state transitions
|
||||
- Rate limit and backoff tracking
|
||||
- Queue depth and concurrency monitoring
|
||||
|
||||
### 3. Structured Logging
|
||||
|
||||
**Location**: `src/logger/structured.js`
|
||||
|
||||
**Features**:
|
||||
- Winston-based structured JSON logging
|
||||
- Correlation ID support for request tracing
|
||||
- Multiple transports: console + file (combined.log, error.log)
|
||||
- Log levels: debug, info, warn, error
|
||||
- Module-based context for better filtering
|
||||
|
||||
**Log Files**:
|
||||
- `logs/combined.log` - All log levels
|
||||
- `logs/error.log` - Error level only
|
||||
|
||||
### 4. Health Endpoints
|
||||
|
||||
**Location**: `src/http/status-server.js`
|
||||
|
||||
**Endpoints**:
|
||||
- `GET /health` - JSON health status with metrics summary
|
||||
- `GET /metrics` - Full metrics export (JSON or Prometheus format)
|
||||
- `GET /` - Read-only ops landing page
|
||||
|
||||
**Health Response Includes**:
|
||||
- Service version and uptime
|
||||
- RSS listener status and last tick metrics
|
||||
- WordPress and OpenAI configuration status
|
||||
- Metrics summary (key counters and gauges)
|
||||
- Feature flags (RSS count, X queries, etc.)
|
||||
|
||||
### 5. Alerting System
|
||||
|
||||
**Location**: `src/monitoring/pipeline-alert.js`
|
||||
|
||||
**Features**:
|
||||
- Webhook-based alerting for critical pipeline failures
|
||||
- Configurable via `PIPELINE_ALERT_WEBHOOK_URL` environment variable
|
||||
- Never throws or sends secrets
|
||||
- Tracks alert firing success/failure metrics
|
||||
|
||||
**Alert Types**:
|
||||
- WordPress publish failures (both write and listen modes)
|
||||
- Pipeline errors requiring operator attention
|
||||
|
||||
## Integration Points
|
||||
|
||||
### Application Integration
|
||||
|
||||
The observability components are integrated throughout the application:
|
||||
|
||||
1. **Main Index** (`src/index.js`):
|
||||
- Article generation and publishing metrics
|
||||
- Pipeline alerting on WordPress failures
|
||||
- Quality scoring metrics
|
||||
|
||||
2. **RSS Listener** (`src/listener/rss-listener.js`):
|
||||
- Tick duration and article processing metrics
|
||||
- Filtering and topic detection metrics
|
||||
|
||||
3. **RSS Crawler** (`src/crawler/rss.js`):
|
||||
- Source fetch success/failure tracking
|
||||
- Circuit breaker metrics
|
||||
- Domain filtering metrics
|
||||
|
||||
4. **WordPress Publisher** (`src/publisher/wordpress.js`):
|
||||
- Publish duration and error metrics
|
||||
- Transport-specific metrics (REST vs XML-RPC)
|
||||
|
||||
5. **XML-RPC Client** (`src/publisher/xmlrpc-client.js`):
|
||||
- XML-RPC call metrics and error tracking
|
||||
|
||||
## Configuration
|
||||
|
||||
**Environment Variables**:
|
||||
|
||||
```bash
|
||||
# Logging
|
||||
LOG_LEVEL=info # debug, info, warn, error
|
||||
|
||||
# Metrics
|
||||
# No special configuration needed - metrics are always collected
|
||||
|
||||
# Alerting
|
||||
PIPELINE_ALERT_WEBHOOK_URL=https://your-webhook-url.com/alerts
|
||||
PIPELINE_ALERT_WEBHOOK_TIMEOUT_MS=4000
|
||||
|
||||
# HTTP Server
|
||||
HOST=0.0.0.0
|
||||
PORT=3200
|
||||
HTTP_REQUEST_TIMEOUT_MS=120000
|
||||
HTTP_HEADERS_TIMEOUT_MS=125000
|
||||
```
|
||||
|
||||
## Monitoring Stack Integration
|
||||
|
||||
### Prometheus Scraping
|
||||
|
||||
Configure Prometheus to scrape the metrics endpoint:
|
||||
|
||||
```yaml
|
||||
scrape_configs:
|
||||
- job_name: ai-news-writer
|
||||
metrics_path: /metrics?format=prometheus
|
||||
static_configs:
|
||||
- targets: ['10.10.50.23:3200'] # Adjust to LXC IP
|
||||
```
|
||||
|
||||
### Suggested Alerts
|
||||
|
||||
```yaml
|
||||
# WordPress publish failures
|
||||
- alert: AINewsWordPressPublishFailures
|
||||
expr: rate(ainews_articles_failed_total[5m]) > 0
|
||||
for: 5m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: "AI News Writer WordPress publish failures detected"
|
||||
|
||||
# Pipeline errors
|
||||
- alert: AINewsPipelineErrors
|
||||
expr: rate(ainews_pipeline_publish_errors_total[5m]) > 0
|
||||
for: 5m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: "AI News Writer pipeline errors detected"
|
||||
|
||||
# RSS listener failures
|
||||
- alert: AINewsRSSListenerFailure
|
||||
expr: ainews_rss_listener_last_tick_ok == 0
|
||||
for: 15m
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
summary: "AI News Writer RSS listener failed"
|
||||
```
|
||||
|
||||
### Log Aggregation
|
||||
|
||||
Configure log shippers (Promtail, Filebeat) to collect from:
|
||||
- `/opt/bitreport/ai-news-writer/logs/combined.log`
|
||||
- `/opt/bitreport/ai-news-writer/logs/error.log`
|
||||
|
||||
## Verification
|
||||
|
||||
### Local Testing
|
||||
|
||||
```bash
|
||||
# Start in listen mode
|
||||
npm run listen
|
||||
|
||||
# Check health endpoint
|
||||
curl -sS "http://localhost:3200/health" | jq '.metrics_summary'
|
||||
|
||||
# Check metrics endpoint (JSON)
|
||||
curl -sS "http://localhost:3200/metrics"
|
||||
|
||||
# Check metrics endpoint (Prometheus format)
|
||||
curl -sS "http://localhost:3200/metrics?format=prometheus"
|
||||
|
||||
# Check logs
|
||||
cat logs/combined.log
|
||||
```
|
||||
|
||||
### Deployment Verification
|
||||
|
||||
```bash
|
||||
# Verify deployment with smoke tests
|
||||
npm run verify:deploy -- "http://<lxc-ip>:3200"
|
||||
|
||||
# Full ops check (includes tests)
|
||||
bash tools/ops-check.sh
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
The observability foundation includes comprehensive tests:
|
||||
|
||||
- `src/monitoring/metrics.test.js` - Metrics collection and export
|
||||
- `src/monitoring/pipeline-metrics.test.js` - Pipeline-specific metrics
|
||||
- `src/monitoring/pipeline-alert.test.js` - Alerting system
|
||||
- `src/logger/structured.test.js` - Structured logging
|
||||
|
||||
Run tests with:
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
Potential improvements for future iterations:
|
||||
|
||||
1. **Distributed Tracing**: Integrate with OpenTelemetry for cross-service tracing
|
||||
2. **Advanced Alerting**: More sophisticated alert conditions and routing
|
||||
3. **Custom Dashboards**: Pre-configured Grafana dashboards for common workflows
|
||||
4. **Log Correlation**: Enhanced correlation between logs and metrics
|
||||
5. **Performance Profiling**: CPU and memory profiling endpoints
|
||||
|
||||
## References
|
||||
|
||||
- **Runbook**: `docs/runbooks/OBSERVABILITY_BIT3601.md`
|
||||
- **Architecture**: `README.md` § Architecture
|
||||
- **Deployment**: `docs/runbooks/DEPLOY_LXC.md`
|
||||
- **Backup Strategy**: `docs/BACKUP_STRATEGY.md`
|
||||
Reference in new issue
Block a user