Skip to content

Commit 43ec50f

Browse files
committed
Add comprehensive tests, configuration files, and Prometheus setup for YokedCache
- Implemented Prometheus configuration for monitoring YokedCache metrics. - Added Redis configuration optimized for development. - Created a .dockerignore file to exclude unnecessary files from Docker context. - Developed a wait_for_redis script for ensuring Redis is ready before operations. - Added comprehensive tests for YokedCache class covering initialization, connection handling, basic operations, error handling, and advanced features. - Created CLI tests to validate CLI utility functions and command decorators. - Developed tests for decorators, including caching and dependency management. - Implemented extensive exception handling tests for YokedCache exceptions.
1 parent 8e86808 commit 43ec50f

29 files changed

+3209
-44
lines changed

.devcontainer/.dockerignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__
7+
*.pyc
8+
*.pyo
9+
*.pyd
10+
.Python
11+
env
12+
pip-log.txt
13+
pip-delete-this-directory.txt
14+
.tox
15+
.coverage
16+
.coverage.*
17+
.pytest_cache
18+
htmlcov
19+
.cache
20+
nosetests.xml
21+
coverage.xml
22+
*.cover
23+
*.log
24+
.mypy_cache
25+
.dmypy.json
26+
dmypy.json
27+
28+
# Build artifacts
29+
build
30+
dist
31+
*.egg-info
32+
.eggs
33+
34+
# Virtual environments
35+
venv
36+
env
37+
ENV
38+
.venv
39+
40+
# IDE
41+
.vscode
42+
.idea
43+
*.swp
44+
*.swo
45+
*~
46+
47+
# OS
48+
.DS_Store
49+
Thumbs.db
50+
51+
# Documentation build
52+
site
53+
docs/_build
54+
55+
# Test artifacts
56+
.pytest_cache
57+
htmlcov
58+
59+
# Temporary files
60+
*.tmp
61+
*.temp
62+
63+
# Node modules (if any)
64+
node_modules
65+
66+
# Jupyter
67+
.ipynb_checkpoints
68+
69+
# Exclude devcontainer from build context
70+
.devcontainer/docker-compose.yml
71+
.devcontainer/.dockerignore

.devcontainer/Dockerfile

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Use Python 3.11 with conda for package management
2+
FROM continuumio/miniconda3:latest
3+
4+
# Set environment variables
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
ENV PYTHONUNBUFFERED=1
7+
ENV PYTHONDONTWRITEBYTECODE=1
8+
ENV PIP_NO_CACHE_DIR=1
9+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
10+
11+
# Install system dependencies
12+
RUN apt-get update && apt-get install -y \
13+
git \
14+
curl \
15+
wget \
16+
vim \
17+
nano \
18+
build-essential \
19+
gcc \
20+
g++ \
21+
make \
22+
cmake \
23+
pkg-config \
24+
libssl-dev \
25+
libffi-dev \
26+
zlib1g-dev \
27+
libbz2-dev \
28+
libreadline-dev \
29+
libsqlite3-dev \
30+
libncurses5-dev \
31+
libncursesw5-dev \
32+
xz-utils \
33+
tk-dev \
34+
libxml2-dev \
35+
libxmlsec1-dev \
36+
libffi-dev \
37+
liblzma-dev \
38+
# Redis CLI for debugging
39+
redis-tools \
40+
# Network tools
41+
netcat-openbsd \
42+
telnet \
43+
# Process monitoring
44+
htop \
45+
# Clean up
46+
&& apt-get clean \
47+
&& rm -rf /var/lib/apt/lists/*
48+
49+
# Create conda environment with Python 3.11
50+
RUN conda create -n yokedcache python=3.11 -y
51+
SHELL ["conda", "run", "-n", "yokedcache", "/bin/bash", "-c"]
52+
53+
# Update conda and install base packages
54+
RUN conda update -n base -c defaults conda -y && \
55+
conda install -n yokedcache -c conda-forge \
56+
pip \
57+
setuptools \
58+
wheel \
59+
-y
60+
61+
# Set the conda environment as default
62+
ENV PATH /opt/conda/envs/yokedcache/bin:$PATH
63+
ENV CONDA_DEFAULT_ENV yokedcache
64+
65+
# Create workspace directory
66+
WORKDIR /workspace
67+
68+
# Copy requirements first to leverage Docker caching
69+
COPY requirements-dev.txt requirements-full.txt pyproject.toml ./
70+
71+
# Install Python dependencies
72+
RUN conda run -n yokedcache pip install --no-cache-dir -r requirements-dev.txt && \
73+
conda run -n yokedcache pip install --no-cache-dir -r requirements-full.txt
74+
75+
# Install additional development tools
76+
RUN conda run -n yokedcache pip install --no-cache-dir \
77+
ipython \
78+
jupyter \
79+
jupyterlab \
80+
pre-commit \
81+
bandit \
82+
safety \
83+
rich \
84+
typer
85+
86+
# Configure Git (will be overridden by mounted config)
87+
RUN git config --global user.name "Developer" && \
88+
git config --global user.email "dev@yokedcache.local" && \
89+
git config --global init.defaultBranch main
90+
91+
# Set up shell
92+
RUN echo "source activate yokedcache" >> ~/.bashrc
93+
RUN echo "cd /workspace" >> ~/.bashrc
94+
95+
# Expose common ports
96+
EXPOSE 58000 58080 58888
97+
98+
# Set default command
99+
CMD ["/bin/bash"]

.devcontainer/OVERVIEW.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# 🐳 YokedCache .devcontainer Setup
2+
3+
A complete containerized development environment for YokedCache with Redis, Memcached, and all development tools.
4+
5+
## 📁 Files Overview
6+
7+
```
8+
.devcontainer/
9+
├── devcontainer.json # VS Code Dev Container configuration
10+
├── docker-compose.yml # Multi-service container orchestration
11+
├── Dockerfile # Python development environment
12+
├── post-create.sh # Automated setup script
13+
├── dev.sh # Development helper script
14+
├── redis.conf # Redis server configuration
15+
├── prometheus.yml # Prometheus monitoring config
16+
├── grafana-datasources.yml # Grafana data sources
17+
├── .dockerignore # Docker build optimization
18+
├── README.md # Detailed documentation
19+
└── OVERVIEW.md # This file
20+
```
21+
22+
## 🚀 Quick Start
23+
24+
1. **Prerequisites**: Docker Desktop + VS Code + Dev Containers extension
25+
2. **Open**: `F1` → "Dev Containers: Reopen in Container"
26+
3. **Wait**: Initial build takes ~5-10 minutes
27+
4. **Develop**: Everything is ready to go!
28+
29+
## 🛠️ What You Get
30+
31+
### Core Development Environment
32+
- **Python 3.11** with conda
33+
- **Redis 7** for caching
34+
- **Memcached** for alternative backend
35+
- **All dependencies** pre-installed
36+
- **YokedCache** installed in development mode
37+
38+
### VS Code Integration
39+
- **30+ Extensions** for Python development
40+
- **Intelligent code completion** with Pylance
41+
- **Automated formatting** with Black and isort
42+
- **Type checking** with mypy
43+
- **Testing integration** with pytest
44+
- **Git integration** with GitLens
45+
46+
### Development Tools
47+
- **Pre-commit hooks** for code quality
48+
- **Coverage reporting** with pytest-cov
49+
- **Documentation building** with MkDocs
50+
- **CLI tools** for cache management
51+
- **Development helper script** (`./dev.sh`)
52+
53+
### Optional Services
54+
- **Redis Insight** - Redis GUI on port 8001
55+
- **Prometheus** - Metrics collection on port 9090
56+
- **Grafana** - Metrics visualization on port 3000
57+
58+
## 🔧 Common Commands
59+
60+
```bash
61+
# Development workflow
62+
./dev.sh setup # Install in development mode
63+
./dev.sh test # Run tests
64+
./dev.sh format # Format code
65+
./dev.sh lint # Run linting
66+
./dev.sh quality # All quality checks
67+
68+
# Cache operations
69+
./dev.sh ping # Test Redis connection
70+
./dev.sh stats # Cache statistics
71+
./dev.sh redis-cli # Connect to Redis
72+
73+
# Documentation
74+
./dev.sh docs # Build docs
75+
./dev.sh docs-serve # Serve docs with live reload
76+
77+
# Services
78+
./dev.sh monitor # Start Prometheus + Grafana
79+
./dev.sh tools # Start Redis Insight
80+
./dev.sh status # Show service status
81+
```
82+
83+
## 🌐 Service URLs
84+
85+
- **Redis**: `redis://redis:56379`
86+
- **Memcached**: `memcached:51211`
87+
- **Redis Insight**: <http://localhost:58001>
88+
- **Prometheus**: <http://localhost:59090>
89+
- **Grafana**: <http://localhost:53000> (admin/admin)
90+
- **Documentation**: <http://localhost:58080> (when serving)
91+
92+
## 📋 Environment Variables
93+
94+
Pre-configured for development:
95+
96+
```bash
97+
YOKEDCACHE_REDIS_URL=redis://redis:56379/0
98+
YOKEDCACHE_DEFAULT_TTL=300
99+
YOKEDCACHE_KEY_PREFIX=dev_yokedcache
100+
YOKEDCACHE_LOG_LEVEL=DEBUG
101+
YOKEDCACHE_ENABLE_METRICS=true
102+
YOKEDCACHE_PROMETHEUS_PORT=58000
103+
PYTHONPATH=/workspace/src
104+
```
105+
106+
## 🏗️ Architecture
107+
108+
```mermaid
109+
graph TB
110+
A[VS Code Dev Container] --> B[Python 3.11 Environment]
111+
A --> C[Redis 7]
112+
A --> D[Memcached]
113+
A --> E[Development Tools]
114+
115+
B --> F[YokedCache Source]
116+
B --> G[All Dependencies]
117+
B --> H[Testing Framework]
118+
119+
C --> I[Cache Backend]
120+
D --> J[Alternative Backend]
121+
122+
E --> K[Code Quality Tools]
123+
E --> L[Documentation Tools]
124+
E --> M[Monitoring Stack]
125+
```
126+
127+
## 🔍 Troubleshooting
128+
129+
### Container Issues
130+
```bash
131+
# Rebuild container
132+
F1 → "Dev Containers: Rebuild Container"
133+
134+
# Check Docker resources
135+
docker system df
136+
docker stats
137+
```
138+
139+
### Service Issues
140+
```bash
141+
# Check service status
142+
./dev.sh status
143+
144+
# View service logs
145+
./dev.sh logs redis
146+
./dev.sh logs memcached
147+
148+
# Restart services
149+
./dev.sh restart
150+
```
151+
152+
### Python Environment
153+
```bash
154+
# Verify environment
155+
conda info --envs
156+
python --version
157+
pip list | grep yokedcache
158+
159+
# Reinstall development package
160+
./dev.sh setup
161+
```
162+
163+
## 🚀 Advanced Usage
164+
165+
### Adding New Dependencies
166+
1. Add to `requirements-dev.txt`
167+
2. Rebuild container or run `pip install package`
168+
169+
### Custom VS Code Settings
170+
Edit `devcontainer.json``customizations.vscode.settings`
171+
172+
### Service Configuration
173+
- **Redis**: Edit `redis.conf`
174+
- **Monitoring**: Edit `prometheus.yml`
175+
- **Compose**: Edit `docker-compose.yml`
176+
177+
### Environment Customization
178+
Add environment variables to `devcontainer.json``containerEnv`
179+
180+
## 📊 Monitoring & Metrics
181+
182+
When monitoring is enabled:
183+
184+
1. **Prometheus** collects metrics from YokedCache
185+
2. **Grafana** visualizes cache performance
186+
3. **Redis Insight** provides Redis-specific monitoring
187+
188+
Access dashboards:
189+
- Prometheus: <http://localhost:59090/targets>
190+
- Grafana: <http://localhost:53000/dashboards>
191+
- Redis Insight: <http://localhost:58001>
192+
193+
## 🎯 Development Best Practices
194+
195+
1. **Use the helper script**: `./dev.sh` for common tasks
196+
2. **Run tests frequently**: `./dev.sh test`
197+
3. **Format before committing**: `./dev.sh format`
198+
4. **Check code quality**: `./dev.sh quality`
199+
5. **Monitor cache health**: `./dev.sh ping` and `./dev.sh stats`
200+
201+
## 📚 Resources
202+
203+
- [YokedCache Documentation](https://sirstig.github.io/yokedcache)
204+
- [VS Code Dev Containers](https://code.visualstudio.com/docs/remote/containers)
205+
- [Docker Compose](https://docs.docker.com/compose/)
206+
- [Redis Documentation](https://redis.io/documentation)
207+
208+
---
209+
210+
**Happy coding! 🎉** This environment provides everything you need for productive YokedCache development.

0 commit comments

Comments
 (0)