|
| 1 | +# AI-Assisted Code Refactoring Workshop: Server Monitoring System |
| 2 | + |
| 3 | +## Workshop Overview |
| 4 | +This workshop demonstrates how AI coding assistants can help improve error handling and code maintainability in IT systems. Using a server monitoring system as our example, we'll explore common code quality issues and learn how AI can assist in identifying and fixing them. |
| 5 | + |
| 6 | +## Learning Objectives |
| 7 | +- Understand how AI can assist in identifying code quality issues |
| 8 | +- Learn to translate theoretical best practices into practical improvements |
| 9 | +- Experience real-world error handling scenarios |
| 10 | +- Bridge the gap between development and IT operations |
| 11 | + |
| 12 | +## The Scenario |
| 13 | +We're working with a server monitoring system that represents a common situation in IT: |
| 14 | +- A robust third-party tool or API (`mock_ping.py`) that we can't modify |
| 15 | +- Our own integration code (`server_availability.py`) that needs improvement |
| 16 | +- Real-world challenges like unclear error messages, poor logging, and lost context |
| 17 | + |
| 18 | +### Understanding mock_ping.py |
| 19 | +In our workshop, `mock_ping.py` represents third-party APIs or tools that IT teams commonly work with, such as: |
| 20 | +- Cloud provider APIs (AWS, Azure, GCP) |
| 21 | +- Monitoring tool APIs (Nagios, Zabbix, SolarWinds) |
| 22 | +- Network infrastructure APIs (Cisco, F5, etc.) |
| 23 | + |
| 24 | +This file serves as our "API documentation" for the AI, similar to how you might provide AWS documentation when asking AI to help with AWS integrations. |
| 25 | + |
| 26 | +## Project Structure |
| 27 | +``` |
| 28 | +IT |
| 29 | +├── server_availability_hints.py # Initial version of the server availability checker with comments on potential improvements |
| 30 | +├── server_availability.py # Unrefactored implementation of the server availability checker |
| 31 | +├── server_availability_refactored.py # Refactored version of the server availability checker with enhanced error handling and maintainability |
| 32 | +├── mock_ping.py # Mock implementation of a ping function which represents a third-party API/tool |
| 33 | +├── test-for-intial-code-notebook.ipynb # Notebook testing the unrefactored server availability checker |
| 34 | +├── test-for-refactored-code-notebook.ipynb # Notebook validating the improvements in the refactored server availability checker |
| 35 | +└── README.md # This file |
| 36 | +``` |
| 37 | + |
| 38 | +## Workshop Flow |
| 39 | +1. **Review Current State** |
| 40 | + - Examine the current `server_availability.py` |
| 41 | + - Identify common issues in error handling and logging |
| 42 | + - Run test scenarios via `test-for-intial-code-notebook.ipynb` to see problematic outputs |
| 43 | + |
| 44 | +2. **Understanding the Context** |
| 45 | + - Learn how `mock_ping.py` represents real-world APIs |
| 46 | + - See how error information gets lost in our integration |
| 47 | + - Identify where improvements are needed |
| 48 | + |
| 49 | +3. **AI-Assisted Refactoring** |
| 50 | + - Use AI to help identify improvements |
| 51 | + - Implement better error handling |
| 52 | + - Add proper logging and resource management |
| 53 | + - Maintain better error context |
| 54 | + |
| 55 | +4. **Validation** |
| 56 | + - Run the same test scenarios via `test-for-refactored-code-notebook.ipynb` |
| 57 | + - Compare output quality |
| 58 | + - Understand the improvements |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +## Workshop Materials |
| 63 | +- `mock_ping.py`: Simulates a third-party API with rich error types |
| 64 | +- `server_availability.py`: Starting point with common issues |
| 65 | +- `server-test-notebook.ipynb`: Test scenarios for before/after comparison |
| 66 | + |
| 67 | +## Expected Outcomes |
| 68 | +After this workshop, participants will: |
| 69 | +- Better understand how to work with third-party APIs |
| 70 | +- Know how to use AI to improve error handling |
| 71 | +- Be able to identify and fix common code quality issues |
| 72 | +- Understand how to maintain error context |
| 73 | +- Have practical experience with code refactoring |
0 commit comments