Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

  • chore: detect more error codes
  • chore: add delay between successful calls
  • chore: set max timeout for the workflow

Why is it important?

Testing the workflow fails, and this is something we have to test live.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner November 25, 2025 11:28
@mdelapenya mdelapenya added chore Changes that do not impact the existing functionality github_actions Pull requests that update GitHub Actions code labels Nov 25, 2025
@mdelapenya mdelapenya self-assigned this Nov 25, 2025
@netlify
Copy link

netlify bot commented Nov 25, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit cd5bfcf
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6925943ad9dac00008dba19d
😎 Deploy Preview https://deploy-preview-3499--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Summary by CodeRabbit

  • Chores
    • Extended workflow job timeout to 120 minutes for improved stability.
    • Improved metrics collection reliability by introducing request delays and enhanced rate-limit detection.
    • Updated build tooling to better track module changes in the metrics collection system.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Adds a 120-minute job timeout to the usage-metrics workflow, inserts a 2-second delay between successive successful version queries when more remain, and broadens GitHub rate-limit detection to include HTTP 429. Also marks usage-metrics as modified in the changed-modules script.

Changes

Cohort / File(s) Summary
Workflow Configuration
.github/workflows/usage-metrics.yml
Sets timeout-minutes: 120 for the collect-metrics job to extend maximum execution time.
Metrics collector (rate-limiting)
usage-metrics/collect-metrics.go
After each successful version query, waits 2s when additional metrics remain; expands rate-limit detection to treat HTTP 429 responses as retryable alongside existing checks.
Change detection script
scripts/changed-modules.sh
Adds handling so modifications under usage-metrics/* append usage-metrics to the modified_modules list.

Sequence Diagram

sequenceDiagram
    participant WF as Metrics Workflow
    participant CM as collect-metrics
    participant GH as GitHub API

    WF->>CM: start collect-metrics job
    CM->>GH: GET /repos/.../releases?per_page=100
    alt Response = 429 or rate-limited (403 / rate limit text)
        GH-->>CM: 429 / rate-limit error
        Note right of CM `#DDEBF7`: Retry with backoff
        CM->>CM: backoff wait, retry
    else 200 OK
        GH-->>CM: 200 OK (version data)
        Note right of CM `#E6F4EA`: Process result
        alt More metrics remain
            CM->>CM: wait 2s (inter-request delay)
        end
    end
    CM-->>WF: metrics processed / job continues
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Reason: small number of files but includes control-flow changes in Go plus workflow and release-detection script edits.
  • Pay special attention to:
    • Correct conditional logic ensuring the 2s delay only runs when more queries remain.
    • 429 handling alongside existing rate-limit detection (no false positives).
    • Shell script pattern matching and modifications to modified_modules.

Possibly related PRs

Poem

🐰
Delays of two seconds, gentle and neat,
Timeouts extended so metrics can meet.
429s we now politely deflect,
The collector hops on, steady and correct.
— a rabbit's nibble of code, soft and sweet.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore(metrics): properly detect rate limits' directly aligns with the main change of detecting HTTP 429 responses and rate limit errors in the metrics collection logic.
Description check ✅ Passed The description provides three bullet points that accurately reflect the changes: detecting error codes, adding delays between calls, and setting workflow timeout.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
usage-metrics/collect-metrics.go (1)

81-86: Consider using loop index to avoid unnecessary delay.

The condition len(metrics) < len(versions) attempts to skip the delay after the last version, but it counts only successful queries. If any earlier queries fail, this condition remains true even when processing the final version, causing an unnecessary 2-second delay at the end.

Apply this diff to use the loop index instead:

-	for _, version := range versions {
+	for i, version := range versions {
 		version = strings.TrimSpace(version)
 		if version == "" {
 			continue
 		}
 
 		count, err := queryGitHubUsageWithRetry(version)
 		if err != nil {
 			log.Printf("Warning: Failed to query version %s after retries: %v", version, err)
 			continue
 		}
 
 		metric := usageMetric{
 			Date:    date,
 			Version: version,
 			Count:   count,
 		}
 
 		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) {
+		if i < len(versions)-1 {
 			log.Printf("Waiting 2 seconds before next query to avoid rate limiting...")
 			time.Sleep(2 * time.Second)
 		}
 	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c31cec0 and a88d71e.

📒 Files selected for processing (2)
  • .github/workflows/usage-metrics.yml (1 hunks)
  • usage-metrics/collect-metrics.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
usage-metrics/collect-metrics.go (1)
log/logger.go (1)
  • Printf (47-49)
🔇 Additional comments (2)
usage-metrics/collect-metrics.go (1)

136-138: Good addition of HTTP 429 detection.

Adding the check for "429" properly detects the standard HTTP rate-limit status code, improving the retry logic's ability to recognize and handle rate limits.

.github/workflows/usage-metrics.yml (1)

23-23: Appropriate timeout for the enhanced metrics collection.

The 120-minute timeout aligns with the new 2-second inter-request delays and retry backoffs introduced in the Go code, providing adequate time while preventing indefinite execution.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
scripts/changed-modules.sh (1)

6-65: Consider adding a test case for usage-metrics module changes.

The documentation includes comprehensive test cases for modulegen (case #4) and other modules, but no explicit test case for usage-metrics. Adding one would improve clarity of the expected behavior when usage-metrics/* files are modified, mirroring test #4 for consistency.

Example addition to documentation:

  # 4. A Go file from the modulegen dir is modified:
  #    ALL_CHANGED_FILES="modulegen/a.go" ./scripts/changed-modules.sh
  #    The output should be: just the modulegen module.
  #
+ # 4b. A file from the usage-metrics dir is modified:
+ #    ALL_CHANGED_FILES="usage-metrics/metrics.go" ./scripts/changed-modules.sh
+ #    The output should be: just the usage-metrics module.
+ #
  # 5. A non-Go file from the core dir is modified:
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a88d71e and cd5bfcf.

📒 Files selected for processing (1)
  • scripts/changed-modules.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: lint (modules/nebulagraph) / lint: modules/nebulagraph
  • GitHub Check: lint (modules/compose) / lint: modules/compose
  • GitHub Check: lint (modules/k3s) / lint: modules/k3s
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
scripts/changed-modules.sh (1)

173-174: Correctly adds usage-metrics module detection in line with existing patterns.

The implementation properly detects changes in the usage-metrics/* directory and appends the module to the modified_modules list. It follows the same approach as the existing modulegen handler and integrates cleanly with the already-initialized usageMetricsModule variable.

@mdelapenya mdelapenya merged commit a735911 into testcontainers:main Nov 25, 2025
75 checks passed
@mdelapenya mdelapenya deleted the fix-metrics-rate-limits branch November 25, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Changes that do not impact the existing functionality github_actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant