1- .PHONY : help install dev test lint format clean docker-build docker-up docker-down migrate
1+ # Log Analysis Service - Makefile
22
3+ .PHONY : help start stop restart test clean logs status
4+
5+ # Default target
36help :
4- @echo " Log Analysis Service - Available commands:"
5- @echo " install - Install dependencies"
6- @echo " dev - Run development server"
7- @echo " test - Run tests"
8- @echo " lint - Run linters"
9- @echo " format - Format code"
10- @echo " clean - Clean generated files"
11- @echo " docker-build - Build Docker image"
12- @echo " docker-up - Start Docker services"
13- @echo " docker-down - Stop Docker services"
14- @echo " migrate - Run database migrations"
15-
16- install :
17- pip install -r requirements.txt
7+ @echo " Log Analysis Service - Available Commands:"
8+ @echo " "
9+ @echo " π Service Management:"
10+ @echo " start - Start all services with Docker Compose"
11+ @echo " stop - Stop all services"
12+ @echo " restart - Restart all services"
13+ @echo " logs - View application logs"
14+ @echo " status - Check service status"
15+ @echo " clean - Clean up containers and volumes"
16+ @echo " "
17+ @echo " π Authentication:"
18+ @echo " get-token - Generate admin authentication token"
19+ @echo " get-token-user - Generate user authentication token"
20+ @echo " get-token-admin- Generate admin authentication token"
21+ @echo " "
22+ @echo " βοΈ Configuration:"
23+ @echo " get-config - Show application configuration"
24+ @echo " "
25+ @echo " π§ͺ Testing:"
26+ @echo " test-logs - Run comprehensive log processing tests"
27+ @echo " test-critical - Test critical error scenarios"
28+ @echo " test-pattern - Test pattern detection"
29+ @echo " test-anomaly - Test anomaly detection"
30+ @echo " test-api-status - Test AI status endpoint"
31+ @echo " test-api-logs - Test logs endpoint"
32+ @echo " test-api-stats - Test stats endpoint"
33+ @echo " "
34+ @echo " π Monitoring:"
35+ @echo " check-logs-db - View recent logs in database"
36+ @echo " check-patterns - View detected patterns"
37+ @echo " check-queues - View RabbitMQ queue status"
38+ @echo " metrics - View Prometheus metrics"
39+ @echo " "
1840
19- dev :
20- uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
41+ # Start all services
42+ start :
43+ @echo " π Starting Log Analysis Service..."
44+ docker compose up -d
45+ @echo " β³ Waiting for services to be ready..."
46+ @sleep 10
47+ @echo " β
Services started! Check status with 'make status'"
48+
49+ # Stop all services
50+ stop :
51+ @echo " π Stopping services..."
52+ docker compose down
53+
54+ # Restart services
55+ restart :
56+ @echo " π Restarting services..."
57+ docker compose restart
2158
22- test :
23- pytest tests/ -v --cov=app --cov-report=html --cov-report=term
59+ restart-build :
60+ @echo " π Restarting services..."
61+ docker compose up -d --build
62+
2463
25- lint :
26- flake8 app/ tests/
27- mypy app/
64+ # View logs
65+ logs :
66+ @echo " π Viewing application logs..."
67+ docker compose logs -f log_analysis_service
2868
29- format :
30- black app/ tests/
31- isort app/ tests/
69+ # Check service status
70+ status :
71+ @echo " π Service Status:"
72+ @echo " "
73+ @echo " Docker Services:"
74+ @docker compose ps
75+ @echo " "
76+ @echo " Health Check:"
77+ @curl -s http://localhost:8000/health | jq . || echo " β Health check failed"
78+ @echo " "
79+ @echo " Readiness Check:"
80+ @curl -s http://localhost:8000/health/ready | jq . || echo " β Readiness check failed"
3281
82+ # Clean up
3383clean :
34- find . -type d -name " __pycache__" -exec rm -rf {} +
35- find . -type f -name " *.pyc" -delete
36- find . -type f -name " *.pyo" -delete
37- find . -type d -name " *.egg-info" -exec rm -rf {} +
38- rm -rf .pytest_cache .mypy_cache .coverage htmlcov/
84+ @echo " π§Ή Cleaning up..."
85+ docker compose down -v
86+ docker system prune -f
87+
88+ # Local development
89+ dev :
90+ @echo " π§ Starting for local development..."
91+ python start_app.py
92+
93+ # Initial setup
94+ setup :
95+ @echo " βοΈ Setting up Log Analysis Service..."
96+ @echo " 1. Creating .env file..."
97+ @if [ ! -f .env ]; then cp .env.example .env; echo " β
.env file created" ; else echo " β
.env file already exists" ; fi
98+ @echo " 2. Starting services..."
99+ docker compose up -d
100+ @echo " 3. Waiting for services to be ready..."
101+ @sleep 15
102+ @echo " 4. Running initial tests..."
103+ python test_all_endpoints.py
104+ @echo " β
Setup complete! Service is ready to use."
105+
106+ # Quick test
107+ quick-test :
108+ @echo " β‘ Quick API test..."
109+ @curl -s http://localhost:8000/health | jq . && echo " β
Health check passed" || echo " β Health check failed"
110+ @curl -s http://localhost:8000/health/ready | jq . && echo " β
Readiness check passed" || echo " β Readiness check failed"
111+
112+ # AI toggle commands
113+ ai-on :
114+ @echo " π€ Enabling AI processing..."
115+ @curl -s -X POST -H " Authorization: Bearer test-token" " http://localhost:8000/api/v1/ai/toggle?enable_ai=true" | jq .
116+
117+ ai-off :
118+ @echo " π Disabling AI processing..."
119+ @curl -s -X POST -H " Authorization: Bearer test-token" " http://localhost:8000/api/v1/ai/toggle?enable_ai=false" | jq .
120+
121+ ai-status :
122+ @echo " π AI Status:"
123+ @curl -s -H " Authorization: Bearer test-token" " http://localhost:8000/api/v1/ai/status" | jq .
124+
125+ # Test AI with custom message
126+ test-ai :
127+ @echo " π§ͺ Testing AI with custom message..."
128+ @curl -s -X POST -H " Authorization: Bearer test-token" " http://localhost:8000/api/v1/ai/test?test_message=Database connection timeout&service_name=test-service" | jq .
129+
130+ # View all logs
131+ logs-all :
132+ @echo " π Viewing all service logs..."
133+ docker compose logs -f
134+
135+ # Database commands
136+ db-shell :
137+ @echo " ποΈ Opening database shell..."
138+ docker compose exec postgres psql -U postgres -d log_analysis_db
139+
140+ db-tables :
141+ @echo " π Database tables:"
142+ docker compose exec postgres psql -U postgres -d log_analysis_db -c " \dt"
143+
144+ # Metrics
145+ metrics :
146+ @echo " π Prometheus metrics:"
147+ @curl -s http://localhost:8000/metrics | head -20
148+
149+ # Authentication
150+ get-token :
151+ @echo " π Generating authentication token..."
152+ @docker compose exec -T log_analysis_service python -c " from app.core.auth_external import create_test_token; print('Token:', create_test_token('test-user', ['admin']))"
153+
154+ get-token-user :
155+ @echo " π Generating user token..."
156+ @docker compose exec -T log_analysis_service python -c " from app.core.auth_external import create_test_token; print('Token:', create_test_token('user-123', ['user']))"
157+
158+ get-token-admin :
159+ @echo " π Generating admin token..."
160+ @docker compose exec -T log_analysis_service python -c " from app.core.auth_external import create_test_token; print('Token:', create_test_token('admin-456', ['admin', 'user']))"
161+
162+ # Configuration
163+ get-config :
164+ @echo " βοΈ Application Configuration:"
165+ @docker compose exec -T log_analysis_service python -c " from app.core.config import get_settings; s = get_settings(); print(f'Database URL: {s.database_url}'); print(f'RabbitMQ URL: {s.rabbitmq_url}'); print(f'Server: {s.host}:{s.port}')"
166+
167+ # Testing
168+ test-logs :
169+ @echo " π§ͺ Running comprehensive log tests..."
170+ docker compose exec -T log_analysis_service python /app/test_send_log.py --scenario all
171+
172+ test-critical :
173+ @echo " π¨ Testing critical errors..."
174+ docker compose exec -T log_analysis_service python /app/test_send_log.py --scenario critical
175+
176+ test-pattern :
177+ @echo " π‘ Testing pattern detection..."
178+ docker compose exec -T log_analysis_service python /app/test_send_log.py --scenario pattern
179+
180+ test-anomaly :
181+ @echo " β οΈ Testing anomaly detection..."
182+ docker compose exec -T log_analysis_service python /app/test_send_log.py --scenario anomaly
183+
184+ test-normal :
185+ @echo " β
Testing normal logs..."
186+ docker compose exec -T log_analysis_service python /app/test_send_log.py --scenario normal
187+
188+ test-mixed :
189+ @echo " π― Testing mixed scenario..."
190+ docker compose exec -T log_analysis_service python /app/test_send_log.py --scenario mixed
191+
192+ # API Testing (requires token)
193+ test-api-status :
194+ @echo " π Testing AI status endpoint..."
195+ @TOKEN=$$(docker compose exec -T log_analysis_service python -c "from app.core.auth_external import create_test_token; print(create_test_token('test-user', ['admin'] ) )" ); \
196+ curl -H " Authorization: Bearer $$ TOKEN" http://localhost:8000/api/v1/ai/status
39197
40- docker-build :
41- docker-compose build
198+ test-api-logs :
199+ @echo " π Testing logs endpoint..."
200+ @TOKEN=$$(docker compose exec -T log_analysis_service python -c "from app.core.auth_external import create_test_token; print(create_test_token('test-user', ['admin'] ) )" ); \
201+ curl -H " Authorization: Bearer $$ TOKEN" http://localhost:8000/api/v1/logs
42202
43- docker-up :
44- docker-compose up -d
203+ test-api-stats :
204+ @echo " π Testing stats endpoint..."
205+ @TOKEN=$$(docker compose exec -T log_analysis_service python -c "from app.core.auth_external import create_test_token; print(create_test_token('test-user', ['admin'] ) )" ); \
206+ curl -H " Authorization: Bearer $$ TOKEN" http://localhost:8000/api/v1/stats
45207
46- docker-down :
47- docker-compose down
208+ # View results
209+ check-logs-db :
210+ @echo " π Recent logs in database:"
211+ docker compose exec postgres psql -U postgres -d log_analysis_db -c " SELECT id, service_name, log_level, LEFT(message, 50) as message, timestamp FROM log_entries ORDER BY timestamp DESC LIMIT 10;"
48212
49- migrate :
50- alembic upgrade head
213+ check-patterns :
214+ @echo " π Detected patterns:"
215+ docker compose exec postgres psql -U postgres -d log_analysis_db -c " SELECT pattern_id, LEFT(template, 40) as template, occurrence_count, service_name FROM patterns WHERE is_active = true ORDER BY occurrence_count DESC LIMIT 10;"
51216
52- migrate-create :
53- @read -p " Enter migration message: " msg ; \
54- alembic revision --autogenerate -m " $$ msg "
217+ check-queues :
218+ @echo " π¬ RabbitMQ queues: "
219+ docker compose exec rabbitmq rabbitmqctl list_queues name messages
0 commit comments