Repository navigation
Add field queryProjectID to BigQueryConfiguration - #3821
Merged
ameijer merged 3 commits intoJun 8, 2026
Merged
Conversation
Fixes opencost#3428 Signed-off-by: Varshith <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for an optional QueryProjectID in the GCP BigQuery configuration, allowing queries to run under a different project than the dataset/table project.
Changes:
- Added
QueryProjectIDtoBigQueryConfiguration(JSON + sanitization + equality). - Updated BigQuery client creation to use
QueryProjectIDwith fallback toProjectID. - Expanded
Equalstests to includeQueryProjectIDcomparisons.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/cloud/gcp/bigqueryconfiguration.go | Introduces QueryProjectID, uses it for bigquery.NewClient, and handles JSON unmarshalling/sanitization/equality. |
| pkg/cloud/gcp/bigqueryconfiguration_test.go | Updates equality test fixtures and adds a case for differing QueryProjectID. |
Comments suppressed due to low confidence (1)
pkg/cloud/gcp/bigqueryconfiguration.go:184
- The error message references
StorageConfiguration, but this isBigQueryConfiguration. This is misleading for debugging/config validation; update the message to the correct type name.
authAny, ok := fmap["authorizer"]
if !ok {
return fmt.Errorf("StorageConfiguration: UnmarshalJSON: missing authorizer")
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…SON error scope Fixes opencost#3428 Signed-off-by: Varshith <[email protected]>
Comment on lines
+85
to
+88
| bqcEffective := bqc.QueryProjectID | ||
| if bqcEffective == "" { | ||
| bqcEffective = bqc.ProjectID | ||
| } |
Comment on lines
+102
to
+106
| ProjectID: bqc.ProjectID, | ||
| Dataset: bqc.Dataset, | ||
| Table: bqc.Table, | ||
| Location: bqc.Location, | ||
| QueryProjectID: bqc.QueryProjectID, |
Comment on lines
+181
to
+185
| if _, ok := fmap["queryProjectID"]; ok { | ||
| queryProjectID, err := cloud.GetInterfaceValue[string](fmap, "queryProjectID") | ||
| if err != nil { | ||
| return fmt.Errorf("BigQueryConfiguration: UnmarshalJSON: %w", err) | ||
| } |
Comment on lines
+187
to
191
| } | ||
|
|
||
| authAny, ok := fmap["authorizer"] | ||
| if !ok { | ||
| return fmt.Errorf("StorageConfiguration: UnmarshalJSON: missing authorizer") |
Comment on lines
+404
to
+405
| expected: true, | ||
| }, |
|
cgiraldo
pushed a commit
to Gradiant/opencost-old
that referenced
this pull request
Jul 2, 2026
Signed-off-by: Varshith <[email protected]> Co-authored-by: Alex Meijer <[email protected]> Signed-off-by: Carlos Giraldo <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #3428
Description
Adds optional
queryProjectIDfield toBigQueryConfigurationso the project that runs and is billed for BigQuery queries can be separated from the project that owns the billing-export table.GetBigQueryClientusesQueryProjectIDwhen set and falls back toProjectIDwhen empty, so existing configs keep working unchanged. Query SQL still referencesProjectID.Dataset.Tablefor the source table.Related Issues
Fixes #3428
User Impact
Not a breaking change. Existing configs without
queryProjectIDcontinue to useprojectIDfor both the source table and query execution, matching previous behavior.Operators whose service account holds
bigquery.dataViewerin the data project butbigquery.jobUserin a separate billing project can now express that split incloud-integration.json:{ "gcp": { "bigQuery": [ { "projectID": "<DATA_PROJECT_ID>", "dataset": "detailedbilling", "table": "gcp_billing_export_resource_v1_...", "queryProjectID": "<QUERY_BILLING_PROJECT_ID>", "authorizer": { "authorizerType": "GCPWorkloadIdentity" } } ] } }Testing
All existing cases pass. New tests:
TestBigQueryConfiguration_Equals/different_queryProjectID exercises inequality on the new field.
TestBigQueryConfiguration_Equals/matching_config now sets QueryProjectID on both sides, exercising the equality true-path.
TestBigQueryConfiguration_JSON round-trip carries queryProjectID through Marshal → Unmarshal → Equals, covering the new UnmarshalJSON branch.
Test command and Results: