From b1172187c43f86a0bb766be3d2e99a1e18ac248a Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 13 May 2026 15:47:03 -0700 Subject: [PATCH] fix(error_reporting): Honor quota_project configuration and fallback to project_id Fixes the bug where the `project_id` option passed to `Google::Cloud::ErrorReporting.new` was ignored for billing/quota checks in favor of the quota project found in Application Default Credentials (ADC). - Updated `Service#error_reporting` to explicitly set `quota_project` on the low-level GAPIC client. - Added fallback to the target `project_id` if no global `quota_project` is configured, allowing `new(project_id: '...')` to effectively work for quota checks as users expect. - Added a unit test to verify that the configuration is correctly passed to the GAPIC client. --- google-cloud-error_reporting/Gemfile | 4 +++- .../google/cloud/error_reporting/service.rb | 1 + .../test/google-cloud-error_reporting_test.rb | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/google-cloud-error_reporting/Gemfile b/google-cloud-error_reporting/Gemfile index 5491c548bf1f..f12cb73b30e5 100644 --- a/google-cloud-error_reporting/Gemfile +++ b/google-cloud-error_reporting/Gemfile @@ -24,11 +24,13 @@ local_dependencies.each do |name| gem name, path: "../#{name}" end -gem "google-style", "~> 1.30.1" +gem "benchmark", "~> 0.5.0" +gem "google-style", "~> 1.32.0" gem "minitest", "~> 5.14" gem "minitest-autotest", "~> 1.0" gem "minitest-focus", "~> 1.1" gem "minitest-rg", "~> 5.2" +gem "ostruct", "~> 0.6.3" gem "rack", ">= 0.1" gem "railties", ">= 5.0", "< 7.1.4" gem "rake" diff --git a/google-cloud-error_reporting/lib/google/cloud/error_reporting/service.rb b/google-cloud-error_reporting/lib/google/cloud/error_reporting/service.rb index ef43277e5aa8..bc9ffa1ea56b 100644 --- a/google-cloud-error_reporting/lib/google/cloud/error_reporting/service.rb +++ b/google-cloud-error_reporting/lib/google/cloud/error_reporting/service.rb @@ -48,6 +48,7 @@ def error_reporting config.endpoint = host if host config.lib_name = "gccl" config.lib_version = Google::Cloud::ErrorReporting::VERSION + config.quota_project = Google::Cloud.configure.error_reporting.quota_project || project end end attr_accessor :mocked_error_reporting diff --git a/google-cloud-error_reporting/test/google-cloud-error_reporting_test.rb b/google-cloud-error_reporting/test/google-cloud-error_reporting_test.rb index 94cfbec5bec9..56fb70dfff28 100644 --- a/google-cloud-error_reporting/test/google-cloud-error_reporting_test.rb +++ b/google-cloud-error_reporting/test/google-cloud-error_reporting_test.rb @@ -118,3 +118,25 @@ end end end + +describe Google::Cloud::ErrorReporting do + describe ".new" do + # Stubs Client.new and yields a dummy config to capture assignments without creating a real client. + def stub_client_new *args + @yielded_config = OpenStruct.new + yield @yielded_config + "fake-gapic-client" + end + + it "sets quota_project on the low-level client" do + er = Google::Cloud::ErrorReporting.new project_id: "test-project-id" + service = er.service + + Google::Cloud::ErrorReporting::V1beta1::ReportErrorsService::Client.stub :new, method(:stub_client_new) do + service.error_reporting + end + + _(@yielded_config.quota_project).must_equal "test-project-id" + end + end +end