README
ΒΆ
Testcontainers-Go Usage Metrics
This directory contains the automation system for tracking testcontainers-go usage across GitHub repositories.
Overview
The system automatically collects usage metrics by querying the GitHub Code Search API for references to testcontainers-go in go.mod files across public repositories. The data is visualized in an interactive dashboard integrated into the main MkDocs documentation site at https://golang.testcontainers.org/usage-metrics/
Components
π Data Collection (scripts/)
- collect-metrics.go: Go program that queries GitHub's Code Search API
- Searches for
"testcontainers/testcontainers-go {version}"in go.mod files - Excludes forks and testcontainers organization repositories
- Stores results in CSV format with timestamps
πΎ Data Storage (docs/usage-metrics.csv)
- usage-metrics.csv: Historical usage data in CSV format
- Format:
date,version,count - Version-controlled for historical tracking
- Integrated with MkDocs site
π Website (integrated into docs/)
- docs/usage-metrics.md: Markdown page for the dashboard
- docs/js/usage-metrics.js: JavaScript for chart rendering
- docs/css/usage-metrics.css: Styles for the dashboard
- Uses Chart.js for visualizations
- Shows trends, version comparisons, and statistics
- Responsive design for mobile and desktop
π€ Automation (.github/workflows/usage-metrics.yml)
- Runs monthly on the 1st at 9 AM UTC
- Can be manually triggered with custom versions
- Automatically queries all versions from v0.13.0 to latest
- Creates pull requests for metrics updates (not direct commits)
- Data is deployed via the main MkDocs site when PR is merged
Versions Tracked
The system tracks all versions (including patch versions) from v0.13.0 to the latest release (currently v0.40.0). This includes versions like v0.34.1, v0.29.1, etc.
Usage
Manual Collection
To manually collect metrics for specific versions (queries run sequentially with automatic retry and backoff):
cd usage-metrics
go run collect-metrics.go -version v0.37.0 -version v0.38.0 -version v0.39.0 -csv ../docs/usage-metrics.csv
The collection script includes automatic retry with exponential backoff (5s, 10s, 20s, 40s, 60s) for rate limit resilience. For example, to test with a few recent versions:
cd usage-metrics
go run collect-metrics.go -version v0.38.0 -version v0.39.0 -version v0.40.0 -csv ../docs/usage-metrics.csv
Running Locally
To view the dashboard locally with the full MkDocs site:
# Serve the docs
make serve-docs
# Open http://localhost:8000/usage-metrics/
Manual Workflow Trigger
You can manually trigger the collection workflow from GitHub:
- Go to Actions β "Update Usage Metrics"
- Click "Run workflow"
- Optionally specify versions (e.g.,
v0.39.0,v0.38.0) or leave empty for all versions - Click "Run workflow"
Data Format
The CSV file has three columns:
- date: Collection date in YYYY-MM-DD format
- version: Version string (e.g., v0.27.0)
- count: Number of repositories using this version
Example:
date,version,count
2024-01-15,v0.27.0,133
2024-02-15,v0.27.0,145
Viewing the Dashboard
The dashboard is integrated into the main documentation site:
- Production: https://golang.testcontainers.org/usage-metrics/
- Local: http://localhost:8000/usage-metrics/ (when running
make serve-docs)
The dashboard displays:
- Total repositories using testcontainers-go
- Number of versions tracked
- Latest version information
- Usage trends over time (line chart)
- Version comparison (bar chart)
- Distribution by version (doughnut chart)
Rate Limiting
GitHub API rate limits:
- Unauthenticated: 10 requests/minute
- Authenticated: 30 requests/minute
The collection script queries versions sequentially with automatic retry and exponential backoff (5s, 10s, 20s, 40s, 60s) to handle rate limit errors gracefully. The script will automatically retry up to 5 times if it encounters rate limiting.
Customization
Changing Collection Frequency
Edit the cron schedule in the workflow:
schedule:
- cron: '0 9 1 * *' # Monthly on the 1st at 9 AM UTC
Customizing Charts
Edit docs/js/usage-metrics.js to modify chart types, colors, or add new visualizations.
Changing Version Range
By default, the workflow queries all versions from v0.13.0 onwards. To change this, modify the awk pattern in the workflow file.
Architecture Decisions
Why CSV?
- Simple and human-readable
- Version-controlled with Git
- Easy to import/export
- No database required
- Suitable for the data volume
Why Integrate with MkDocs?
- Single documentation site for all content
- Consistent look and feel
- Same deployment pipeline
- Easy maintenance
- No separate hosting needed
Why Go for Collection?
- Native GitHub API support
- Easy to integrate with existing Go project
- Simple deployment
- Good CSV handling
Troubleshooting
API Rate Limiting
If you hit rate limits:
- The collection script includes automatic retry with exponential backoff (5s, 10s, 20s, 40s, 60s up to 5 attempts)
- Queries run sequentially to minimize rate limit issues
- The workflow uses the
ghCLI which automatically uses GitHub's token for higher limits
CSV Not Updating
Check the workflow logs:
- Go to Actions β "Update Usage Metrics"
- Click on the latest run
- Review the "Query versions" step
Charts Not Displaying
- Ensure CSV file is properly formatted
- Check browser console for JavaScript errors
- Verify the file paths are correct
- Make sure Chart.js and PapaParse CDN links are accessible
Contributing
To add features or fix issues:
- Test changes locally with
mkdocs serve - Update this README if needed
- Submit a pull request
License
Same as the main testcontainers-go repository (MIT).
Documentation
ΒΆ
There is no documentation for this package.