Skip to content

fix project metadata request#3893

Open
orouz wants to merge 3 commits intoelastic:mainfrom
orouz:gcp_rl_fix
Open

fix project metadata request#3893
orouz wants to merge 3 commits intoelastic:mainfrom
orouz:gcp_rl_fix

Conversation

@orouz
Copy link
Collaborator

@orouz orouz commented Jan 28, 2026

Changes

  • add rate limiting for GCP Projects API to prevent 429 quota errors
  • add singleflight to deduplicate concurrent requests for the same project metadata

Context

  • a while ago i merged a PR to cache the org name so we don't get rate limited for the org api.
  • latest errors show we're hitting rate limit errors for project api, this is what this PR fixes
googleapi: Error 429: Quota exceeded for quota metric 'Project V3 get requests' 

The quota is 600 requests per minute. with many projects and assets arriving concurrently, we could exceed this before the cache was populated.

@mergify mergify bot assigned orouz Jan 28, 2026
@mergify
Copy link

mergify bot commented Jan 28, 2026

This pull request does not have a backport label. Could you fix it @orouz? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@orouz orouz requested a review from uri-weisman January 28, 2026 16:18
projectsRateLimiter: rate.NewLimiter(rate.Every(time.Minute/600), 1),
}
wrapper.getProjectDisplayName = func(ctx context.Context, parent string) string {
if err := wrapper.projectsRateLimiter.Wait(ctx); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the only addition here

Comment on lines +110 to +114
result, _, _ := c.metadataGroup.Do(key, func() (any, error) {
metadata := c.getMetadata(ctx, orgId, projectId)
c.accountMetadataCache.Store(key, metadata)
return metadata, nil
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dedupe same key requests

@orouz orouz marked this pull request as ready for review January 28, 2026 16:25
@orouz orouz requested a review from a team as a code owner January 28, 2026 16:25
@orouz orouz requested a review from romulets January 29, 2026 09:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses GCP Projects API rate limiting errors (429 quota exceeded) by implementing two complementary solutions: rate limiting and request deduplication.

Changes:

  • Added rate limiting (600 requests/minute) for GCP Projects API calls to stay within quota
  • Added singleflight deduplication to prevent concurrent requests for the same project metadata from making duplicate API calls
  • Made golang.org/x/sync a direct dependency (was indirect)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/resources/providers/gcplib/inventory/resource_manager.go Implemented rate limiter (600 req/min) for Projects API and singleflight for deduplicating concurrent requests for same project
internal/resources/providers/gcplib/inventory/resource_manager_test.go Added unit tests for rate limiter behavior and singleflight deduplication
go.mod Changed golang.org/x/sync from indirect to direct dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant