Skip to content

Commit f748575

Browse files
mdelapenyaCopilot
andauthored
docs(metrics): automate usage metrics collection and publish it in the docs site (#3495)
* Initial plan * feat: implement usage metrics collection and visualization - Create Go script to query GitHub Code Search API for usage metrics - Add CSV storage for historical data (all versions from v0.13.0 to v0.39.0) - Integrate usage metrics dashboard into MkDocs documentation - Add interactive charts (trend, version comparison, distribution) - Create GitHub Actions workflow for automated weekly collection - Support manual workflow trigger with custom version queries Co-authored-by: mdelapenya <951580+mdelapenya@users.noreply.github.com> * chore: submit a pull request for every update * docs: update readme * chore: refine * modulegen: update type * docs: include github stars * chore(ci): bump setup docker action * fix: backoff * fix: pre-allocate metrics * chore: simplify string concatenation * chore: simplify int concatenation * chore: use errors.As * chore: use proper hex number * chore: run module on its separate runner * deps: use 1.24 for go toolchain * fix: avoid zero-value metrics written to CSV with skipped versions * fix: do not discard flush errors * chore: avoid shell string interpolation --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mdelapenya <951580+mdelapenya@users.noreply.github.com>
1 parent 615ad22 commit f748575

File tree

14 files changed

+1774
-2
lines changed

14 files changed

+1774
-2
lines changed

.github/workflows/ci-test-go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
steps:
5656
- name: Setup rootless Docker
5757
if: ${{ inputs.rootless-docker }}
58-
uses: docker/setup-docker-action@b60f85385d03ac8acfca6d9996982511d8620a19 # v4
58+
uses: docker/setup-docker-action@efe9e3891a4f7307e689f2100b33a155b900a608 # v4.5.0
5959
with:
6060
rootless: true
6161

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Update Usage Metrics
2+
3+
on:
4+
schedule:
5+
# Run monthly on the 1st at 9 AM UTC
6+
- cron: '0 9 1 * *'
7+
workflow_dispatch:
8+
inputs:
9+
versions:
10+
description: 'Comma-separated versions to query (leave empty for all versions)'
11+
required: false
12+
default: ''
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
collect-metrics:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
26+
with:
27+
go-version-file: 'usage-metrics/go.mod'
28+
29+
- name: Query versions
30+
id: query
31+
working-directory: usage-metrics
32+
run: |
33+
# Get versions to query
34+
VERSIONS="${{ github.event.inputs.versions }}"
35+
if [ -z "$VERSIONS" ]; then
36+
# Get all versions from v0.13.0 to latest from the main repository
37+
VERSIONS=$(git ls-remote --tags https://github.com/testcontainers/testcontainers-go.git | \
38+
grep -E 'refs/tags/v0\.[0-9]+\.[0-9]+$' | \
39+
sed 's|.*refs/tags/||' | \
40+
sort -V | \
41+
awk '/v0.13.0/,0' | \
42+
tr '\n' ',' | \
43+
sed 's/,$//')
44+
fi
45+
46+
echo "Querying versions: $VERSIONS"
47+
48+
# Build version flags
49+
VERSION_FLAGS=""
50+
IFS=',' read -ra VERSION_ARRAY <<< "$VERSIONS"
51+
for version in "${VERSION_ARRAY[@]}"; do
52+
version=$(echo "$version" | xargs) # trim whitespace
53+
if [ -z "$version" ]; then
54+
continue
55+
fi
56+
VERSION_FLAGS="$VERSION_FLAGS -version $version"
57+
done
58+
59+
# Query all versions in a single command
60+
go run collect-metrics.go $VERSION_FLAGS -csv "../../docs/usage-metrics.csv"
61+
62+
- name: Create Pull Request
63+
run: |
64+
git config user.name "github-actions[bot]"
65+
git config user.email "github-actions[bot]@users.noreply.github.com"
66+
git add docs/usage-metrics.csv
67+
68+
if git diff --staged --quiet; then
69+
echo "No changes to commit"
70+
exit 0
71+
fi
72+
73+
# Create a new branch for the PR
74+
DATE=$(date +%Y-%m-%d)
75+
BRANCH_NAME="chore/update-usage-metrics-$DATE"
76+
git checkout -b "$BRANCH_NAME"
77+
78+
git commit -m "chore(metrics): update usage metrics ($DATE)"
79+
git push -u origin "$BRANCH_NAME"
80+
81+
# Create PR using gh CLI
82+
gh pr create \
83+
--title "chore: update usage metrics ($DATE)" \
84+
--body "Automated update of usage metrics data. This PR updates the usage metrics CSV file with the latest GitHub usage data for testcontainers-go versions." \
85+
--base main

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ TEST-*.xml
2323

2424
# Coverage files
2525
coverage.out
26+
27+
# Usage metrics script binary
28+
usage-metrics/scripts/collect-metrics

docs/css/usage-metrics.css

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/* Usage Metrics Dashboard Styles */
2+
3+
/* Expand content to use full available width - only on usage metrics page */
4+
body:has(#content.usage-metrics) .md-content__inner,
5+
body:has(.stats-grid) .md-content__inner {
6+
max-width: none !important;
7+
margin: 0 !important;
8+
}
9+
10+
body:has(#content.usage-metrics) .md-content__inner > article,
11+
body:has(.stats-grid) .md-content__inner > article {
12+
padding: 0 2rem;
13+
}
14+
15+
@media screen and (min-width: 76.25em) {
16+
body:has(#content.usage-metrics) .md-content__inner > article,
17+
body:has(.stats-grid) .md-content__inner > article {
18+
padding: 0 4rem;
19+
}
20+
}
21+
22+
@media screen and (min-width: 100em) {
23+
body:has(#content.usage-metrics) .md-content__inner > article,
24+
body:has(.stats-grid) .md-content__inner > article {
25+
padding: 0 6rem;
26+
}
27+
}
28+
29+
.stats-grid {
30+
display: grid;
31+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
32+
gap: 20px;
33+
margin-bottom: 40px;
34+
}
35+
36+
.stat-card {
37+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
38+
color: white;
39+
padding: 25px;
40+
border-radius: 15px;
41+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
42+
}
43+
44+
.stat-label {
45+
font-size: 0.9rem;
46+
opacity: 0.9;
47+
margin-bottom: 5px;
48+
}
49+
50+
.stat-value {
51+
font-size: 2.5rem;
52+
font-weight: bold;
53+
}
54+
55+
.chart-container {
56+
background: white;
57+
border-radius: 15px;
58+
padding: 30px;
59+
margin-bottom: 30px;
60+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
61+
}
62+
63+
.chart-title {
64+
font-size: 1.5rem;
65+
color: #333;
66+
margin-bottom: 20px;
67+
font-weight: 600;
68+
}
69+
70+
.chart-container canvas {
71+
max-height: 400px;
72+
}
73+
74+
.loading {
75+
text-align: center;
76+
padding: 40px;
77+
color: #666;
78+
font-size: 1.2rem;
79+
}
80+
81+
.error {
82+
background: #fee;
83+
border: 1px solid #fcc;
84+
border-radius: 10px;
85+
padding: 20px;
86+
color: #c33;
87+
margin: 20px 0;
88+
}
89+
90+
.metrics-info {
91+
text-align: center;
92+
margin-top: 40px;
93+
padding-top: 20px;
94+
border-top: 1px solid #eee;
95+
color: #666;
96+
font-size: 0.9rem;
97+
}
98+
99+
.metrics-info p {
100+
margin: 5px 0;
101+
}
102+
103+
@media (max-width: 768px) {
104+
.stat-value {
105+
font-size: 2rem;
106+
}
107+
108+
.chart-container {
109+
padding: 20px;
110+
}
111+
}

0 commit comments

Comments
 (0)