Skip to content

feat: Enhanced error handling, validation, and reset endpoint#26

Open
mygithubappforkaushal[bot] wants to merge 1 commit intomainfrom
resolveai/feat-enhanced-error-handling-validation-and-reset--7fj93
Open

feat: Enhanced error handling, validation, and reset endpoint#26
mygithubappforkaushal[bot] wants to merge 1 commit intomainfrom
resolveai/feat-enhanced-error-handling-validation-and-reset--7fj93

Conversation

@mygithubappforkaushal
Copy link
Copy Markdown

Summary

This PR adds production-ready improvements to the analyser service and load testing script.

Changes Made

1. Enhanced Analyser Error Handling & Logging (analyser/app.py)

  • ✅ Added structured logging with proper log levels (INFO, WARNING, ERROR)
  • ✅ Improved /analyse endpoint with proper error handling and HTTP status codes
    • Returns 503 Service Unavailable when analyser is in failed state
    • Returns 500 Internal Server Error on processing failures
    • Added detailed logging for packet processing
  • ✅ Enhanced Pydantic models with field validation:
    • Added Field descriptors for better API documentation
    • Validation rules: non-empty strings, positive timestamps, non-empty message lists
  • ✅ Improved docstrings for all endpoints

2. New Reset Endpoint (analyser/app.py)

  • ✅ Added /internal/reset POST endpoint (addresses TODO in original comments)
    • Resets packet and message counters to zero
    • Maintains alive/dead state
    • Returns previous counts for verification
    • Useful for testing and benchmarking scenarios

3. Enhanced Load Testing Script (locustfile.py)

  • ✅ Added comprehensive module and function docstrings
  • ✅ Renamed AnalyserUserDistributorUser (more accurate naming)
  • ✅ Added DEBUG log level to test scenarios
  • ✅ Improved code readability with extracted variables

Benefits

  • Better observability: Structured logging helps with debugging and monitoring
  • Improved reliability: Proper error handling and HTTP status codes
  • Enhanced testability: Reset endpoint allows clean benchmark runs
  • Better documentation: Auto-generated OpenAPI docs will be more informative
    View Chat

Co-authored-by: Resolve AI code-agent@resolve.ai

## Summary
This PR adds production-ready improvements to the analyser service and load testing script.

## Changes Made

### 1. **Enhanced Analyser Error Handling & Logging** (`analyser/app.py`)
- ✅ Added structured logging with proper log levels (INFO, WARNING, ERROR)
- ✅ Improved `/analyse` endpoint with proper error handling and HTTP status codes
  - Returns `503 Service Unavailable` when analyser is in failed state
  - Returns `500 Internal Server Error` on processing failures
  - Added detailed logging for packet processing
- ✅ Enhanced Pydantic models with field validation:
  - Added `Field` descriptors for better API documentation
  - Validation rules: non-empty strings, positive timestamps, non-empty message lists
- ✅ Improved docstrings for all endpoints

### 2. **New Reset Endpoint** (`analyser/app.py`)
- ✅ Added `/internal/reset` POST endpoint (addresses TODO in original comments)
  - Resets packet and message counters to zero
  - Maintains alive/dead state
  - Returns previous counts for verification
  - Useful for testing and benchmarking scenarios

### 3. **Enhanced Load Testing Script** (`locustfile.py`)
- ✅ Added comprehensive module and function docstrings
- ✅ Renamed `AnalyserUser` → `DistributorUser` (more accurate naming)
- ✅ Added `DEBUG` log level to test scenarios
- ✅ Improved code readability with extracted variables

## Benefits
- **Better observability**: Structured logging helps with debugging and monitoring
- **Improved reliability**: Proper error handling and HTTP status codes
- **Enhanced testability**: Reset endpoint allows clean benchmark runs
- **Better documentation**: Auto-generated OpenAPI docs will be more informative
• [View Chat](http://localhost:3000/chat/01KM4CD6H4EBX0H5NPWRXVM2HC)

Co-authored-by: Resolve AI <code-agent@resolve.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants