Complete guide for testing the extension in a local Docker-based Directus environment.
- Docker & Docker Compose installed
- Node.js 18.x or higher
- npm 9.x or higher
# Install dependencies
npm install
# Build the extension (creates dist/ folder)
npm run buildExpected Output:
dist/api.js(~79KB) - Backend endpointdist/app.js(~244KB) - Frontend module
Note: The build process automatically converts @shared/constants imports to relative paths for Docker compatibility.
# Start all services (PostgreSQL + Directus)
docker-compose up -d
# Watch logs
docker-compose logs -f directusWait for:
directus-app | Server started at http://0.0.0.0:8055
- Open browser: http://localhost:8055
- Login credentials:
- Email:
admin@example.com - Password:
admin123
- Email:
- Navigate to Settings (gear icon in sidebar)
- Scroll down to find Usage Analytics in the settings menu
- Click to open the analytics dashboard
Tab: Collection Storage
- View collection list - Should show all Directus collections
- Row count accuracy - Verify row counts match actual data
- Bar chart visualization - Chart should display correctly
- Top 10 toggle - Enable/disable to filter largest collections
- Percentage calculations - Should sum to ~100%
- Refresh button - Should reload data without page refresh
- Loading states - Show spinner while fetching
- Error handling - Disconnect database to test error display
- Responsive design - Test on mobile/tablet viewport sizes
- Dark/Light mode - Toggle Directus theme and verify styling
API Endpoint:
# Test direct API call
curl http://localhost:8055/usage-analytics/collections?limit=10Expected Response:
{
"collections": [
{ "collection": "directus_users", "row_count": 1, "percentage": 5.0 },
{ "collection": "directus_files", "row_count": 0, "percentage": 0.0 }
],
"total_collections": 20,
"total_rows": 100,
"cached": false,
"query_time_ms": 45,
"timestamp": "2025-01-20T10:00:00.000Z"
}Tab: API Activity
- Date range filter - Test all presets (24h, 7d, 30d, 90d)
- Activity by collection - Verify most-requested collections
- Activity by action - See read/create/update/delete breakdown
- Action color coding - Verify colors (green=read, blue=create, orange=update, red=delete)
- Chart type toggle - Switch between bar and pie charts
- Data type toggle - Switch between collection and action grouping
- Top 10 filter - Test enabling/disabling
- Statistics cards - Verify total requests, unique users, unique IPs
- Percentage bars - Visual representation in tables
- Cache indicator - Should show "Cached data" after 2nd request
- Refresh button - Should bust cache and reload
Generate Test Data (in Directus):
# Create some test collections and data
# Perform various operations: create items, read lists, update fields, delete items
# This will populate directus_activity tableAPI Endpoint:
# Test activity API
curl "http://localhost:8055/usage-analytics/activity?start_date=2025-01-01T00:00:00Z&end_date=2025-01-20T23:59:59Z&limit=10"Expected Response:
{
"total_requests": 150,
"unique_users": 3,
"unique_ips": 5,
"date_range": {
"start": "2025-01-01T00:00:00Z",
"end": "2025-01-20T23:59:59Z"
},
"by_collection": [
{ "collection": "products", "count": 50, "percentage": 33.3 },
{ "collection": "users", "count": 30, "percentage": 20.0 }
],
"by_action": [
{ "action": "read", "count": 80, "percentage": 53.3 },
{ "action": "create", "count": 40, "percentage": 26.7 }
],
"cached": false,
"query_time_ms": 120,
"timestamp": "2025-01-20T10:00:00.000Z"
}Tab: API Activity (with IP filtering)
- IP filter dropdown - Should populate with top IPs
- IP selection - Filter activity by specific IP address
- IP indicator badge - Show active IP filter with clear button
- IP-specific stats - Verify data changes when IP selected
- Clear IP filter - Return to all activity view
- IPv4 support - Test with IPv4 addresses
- IPv6 support - Test with IPv6 addresses (if available)
- Top IPs list - Shows most active IP addresses
- Request counts per IP - Accurate counting
- Percentage distribution - Verify calculations
API Endpoints:
# Get top IPs
curl "http://localhost:8055/usage-analytics/activity/ips?start_date=2025-01-01T00:00:00Z&limit=10"
# Get activity for specific IP
curl "http://localhost:8055/usage-analytics/activity/ips/192.168.1.100?start_date=2025-01-01T00:00:00Z"
# Get time-series data
curl "http://localhost:8055/usage-analytics/activity/timeseries?start_date=2025-01-01T00:00:00Z&granularity=day"Expected Top IPs Response:
{
"ips": [
{ "ip": "192.168.1.100", "count": 50, "percentage": 33.3 },
{ "ip": "10.0.0.5", "count": 30, "percentage": 20.0 }
],
"query_time_ms": 80,
"timestamp": "2025-01-20T10:00:00.000Z"
}For optimal performance with large directus_activity tables:
-- Connect to PostgreSQL
docker exec -it directus-db psql -U directus
-- Create indexes
CREATE INDEX idx_activity_timestamp_collection ON directus_activity(timestamp, collection);
CREATE INDEX idx_activity_timestamp_action ON directus_activity(timestamp, action);
CREATE INDEX idx_activity_timestamp_ip ON directus_activity(timestamp, ip);
-- Verify indexes
\di idx_activity_*# Generate test activity (use Directus API or custom script)
# Perform 1000+ operations across different collections
# Then test query performance in Usage Analytics modulePerformance Targets:
- Collection query: <100ms for <50 collections
- Activity query: <300ms for <10,000 records
- IP query: <200ms for <1,000 unique IPs
- Chart rendering: <500ms for all visualizations
Test in the following browsers:
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
Features to verify:
- Chart.js rendering
- Vue component reactivity
- Directus design system compatibility
- Responsive layout
Symptom: Usage Analytics not visible in Settings menu
Solutions:
-
Verify build output exists:
ls -lh dist/ # Should show api.js and app.js -
Check Docker volume mount:
docker exec -it directus-app ls -la /directus/extensions/ # Should show directus-extension-usage-analytics/
-
Restart Directus with clean cache:
docker-compose down docker-compose up -d
-
Check Directus logs:
docker-compose logs directus | grep -i extension docker-compose logs directus | grep -i error
Symptom: Charts render but show "No data"
Solutions:
-
Verify database has data:
docker exec -it directus-db psql -U directus -c "SELECT COUNT(*) FROM directus_activity;"
-
Check API endpoints directly:
curl http://localhost:8055/usage-analytics/collections curl http://localhost:8055/usage-analytics/activity
-
Open browser console (F12) and check for errors
Symptom: Slow query times or timeouts
Solutions:
- Create recommended database indexes (see above)
- Reduce date range (test with 24 hours instead of 90 days)
- Enable Redis caching:
- Uncomment Redis service in
docker-compose.yml - Uncomment Redis environment variables in Directus service
- Restart:
docker-compose up -d
- Uncomment Redis service in
Symptom: Charts not displaying or layout broken
Solutions:
-
Check Chart.js version in browser console:
Chart.version // Should be "4.x.x"
-
Verify no CSS conflicts with Directus theme
-
Test with different chart types (bar ↔ pie)
-
Check browser console for JavaScript errors
The extension supports PostgreSQL, MySQL, SQLite, and MSSQL.
Edit docker-compose.yml:
database:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: directus
MYSQL_USER: directus
MYSQL_PASSWORD: directus
directus:
environment:
DB_CLIENT: 'mysql'
DB_HOST: 'database'
DB_PORT: '3306'Edit docker-compose.yml:
directus:
environment:
DB_CLIENT: 'sqlite3'
DB_FILENAME: '/directus/database/data.db'
volumes:
- directus-db-data:/directus/databasedocker-compose downdocker-compose down -v
# This deletes database, uploads, and Redis datanpm run build
docker-compose restart directusRun the test suite:
# Unit tests
npm run test
# Type checking
npm run typecheck
# Linting
npm run lintCoverage Target: ≥80% for all test types
The extension is working correctly when:
✅ All 3 user stories are functional ✅ No console errors in browser ✅ API endpoints return valid JSON ✅ Charts render without issues ✅ All filters work as expected ✅ Performance meets targets (<300ms query times) ✅ Responsive design works on all screen sizes ✅ Dark/light mode both look correct ✅ Extension survives Directus restart
After successful testing:
- Optional screenshots for README (T068)
- Final quality check before npm publish (T079)
- Publish to npm when ready (T080)
# Publish to npm (when ready)
npm publish --access publicFor issues during testing:
- Check Directus logs:
docker-compose logs -f directus - Check database logs:
docker-compose logs -f database - Review Directus Extension Documentation
- Open an issue on GitHub
Happy Testing! 🎉