Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/usage-metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
jobs:
collect-metrics:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down
2 changes: 2 additions & 0 deletions scripts/changed-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ for file in $modified_files; do
fi
elif [[ $file == modulegen/* ]]; then
modified_modules+=("\"modulegen\"")
elif [[ $file == usage-metrics/* ]]; then
modified_modules+=("\"usage-metrics\"")
else
# a file from the core module is modified, so include all modules in the list and stop the loop
# check if the file is in one of the excluded modules
Expand Down
10 changes: 9 additions & 1 deletion usage-metrics/collect-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func collectMetrics(versions []string, csvPath string) error {

metrics = append(metrics, metric)
fmt.Printf("Successfully queried: %s has %d usages on %s\n", version, count, metric.Date)

// Add delay to avoid rate limiting (30 requests/minute = 2 seconds between requests)
if len(metrics) < len(versions) {
log.Printf("Waiting 2 seconds before next query to avoid rate limiting...")
time.Sleep(2 * time.Second)
}
}

// Sort metrics by version
Expand Down Expand Up @@ -127,7 +133,9 @@ func queryGitHubUsageWithRetry(version string) (int, error) {
lastErr = err

// Check if it's a rate limit error
if strings.Contains(err.Error(), "rate limit") || strings.Contains(err.Error(), "403") {
if strings.Contains(err.Error(), "rate limit") ||
strings.Contains(err.Error(), "403") ||
strings.Contains(err.Error(), "429") {
log.Printf("Rate limit hit for version %s, will retry with backoff", version)
continue
}
Expand Down
Loading