Skip to content

fix(gcp): allow getting project ID from credentials#220

Merged
dmitsh merged 1 commit into
mainfrom
ds-gcp
Mar 2, 2026
Merged

fix(gcp): allow getting project ID from credentials#220
dmitsh merged 1 commit into
mainfrom
ds-gcp

Conversation

@dmitsh
Copy link
Copy Markdown
Collaborator

@dmitsh dmitsh commented Feb 27, 2026

No description provided.

Comment thread pkg/providers/gcp/provider.go Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Feb 27, 2026

Greptile Summary

Refactored GCP project ID determination from runtime lookup to initialization-time resolution with a clear fallback chain.

Key Changes:

  • Moved project ID lookup to provider initialization instead of per-API-call
  • Implemented priority order: request params → GOOGLE_APPLICATION_CREDENTIALS file → metadata API
  • Changed Client.ProjectID() interface from error-returning to simple string getter
  • Added comprehensive unit tests covering all scenarios and error paths
  • Documented the project ID override mechanism for users

Benefits:

  • Fail-fast error handling at startup rather than during API calls
  • Eliminates redundant metadata lookups on every request
  • Provides users flexibility to override project ID via request parameters
  • Maintains backward compatibility with existing deployments

Confidence Score: 5/5

  • This PR is safe to merge with no concerns
  • The refactoring is well-designed with comprehensive test coverage. All changes are backward compatible, error handling is robust, and the new initialization-time approach is more efficient and maintainable than the previous runtime lookup pattern
  • No files require special attention

Important Files Changed

Filename Overview
pkg/providers/gcp/instance_topology.go Simplified to use client.ProjectID() directly, removing error-prone runtime lookups
pkg/providers/gcp/provider.go Refactored project ID determination to initialization with proper fallback chain
pkg/providers/gcp/provider_test.go New comprehensive unit tests covering all getProjectID scenarios and error paths

Last reviewed commit: b915dc7

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread pkg/providers/gcp/provider.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 28, 2026

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.91%. Comparing base (0fb6f58) to head (b915dc7).

Files with missing lines Patch % Lines
pkg/providers/gcp/provider.go 69.56% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #220      +/-   ##
==========================================
+ Coverage   65.90%   65.91%   +0.01%     
==========================================
  Files          82       82              
  Lines        4520     4536      +16     
==========================================
+ Hits         2979     2990      +11     
- Misses       1423     1428       +5     
  Partials      118      118              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 1, 2026

Additional Comments (2)

docs/providers/gcp.md, line 85
parameter name uses hyphen but code expects underscore

      "project_id": "your-project-id"

pkg/providers/gcp/provider.go, line 113
error message says "is not a file" but the actual condition is "does not exist" - consider rewording for accuracy

			return "", fmt.Errorf("GOOGLE_APPLICATION_CREDENTIALS file does not exist: %v", err)

Signed-off-by: Dmitry Shmulevich <dshmulevich@nvidia.com>
@NVIDIA NVIDIA deleted a comment from greptile-apps Bot Mar 2, 2026
@dmitsh dmitsh merged commit fdd9e82 into main Mar 2, 2026
6 checks passed
@dmitsh dmitsh deleted the ds-gcp branch March 2, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants