googleapis / google-cloud-ruby

Google Cloud Client Library for Ruby
https://googleapis.github.io/google-cloud-ruby/
Apache License 2.0
1.36k stars 550 forks source link

Support Rails7.1 #23522

Open HiroNonoyama opened 1 year ago

HiroNonoyama commented 1 year ago

Environment details

Steps to reproduce

  1. Deploy GAE production environment on Rails 7.1 and run sidekiq process

Google::Cloud::Logging::Logger#broadcast_to has to be implemented on sidekiq startup process when we use it after Rails 7.1 as here

Workaround

We changed use_logging as false, then deploy was succeeded. But we also lost informations of LogSeverity and request trace data on Cloud Logging, so I think it's desirable to set use_logging: true as default.

Code

# Procfile
rails: bin/rails s -p 8080
sidekiq: bundle exec sidekiq -C config/sidekiq.yml

Full backtrace

Step #1: Beginning deployment of service [default]...
Step #1: WARNING: Deployment of service [default] will ignore the skip_files field in the configuration file, because the image has already been built.
Step #1: Updating service [default] (this may take several minutes)...
Step #1: ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................failed.
Step #1: ERROR: (gcloud.app.deploy) Error Response: [9] An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2023-11-03T16:27:26.300Z4042.xa.2: 16:27:53 sidekiq.1 | started with pid 6
Step #1: 16:27:58 sidekiq.1 | undefined method `broadcast_to' for #<Google::Cloud::Logging::Logger:0x00007f044099af20 @writer=#<Google::Cloud::Logging::AsyncWriter:0x00007f044099afc0 @mon_data=#<Monitor:0x00007f04409e9f30>, @mon_data_owner_object_id=8160, @logging=#<Google::Cloud::Logging::Project:0x00007f04409ea818 @service=Google::Cloud::Logging::Service(project-name), @shared_async_writer=#<Google::Cloud::Logging::AsyncWriter:0x00007f044099afc0 ...>>, @max_count=10000, @max_bytes=10000000, @max_queue=100, @interval=5, @threads=10, @partial_success=false, @error_callbacks=[], @cond=#<MonitorMixin::ConditionVariable:0x00007f04409e9e40 @monitor=#<Monitor:0x00007f04409e9f30>, @cond=#<Thread::ConditionVariable:0x00007f04409e9e18>>>, @log_name="ruby_app_log", @resource=#<Google::Cloud::Logging::Resource:0x00007f04409ea4a8 @labels={:module_id=>"default", :version_id=>"20231103t162531"}, @type="gae_app">, @labels={}, @level=0, @request_info_var=#<Concurrent::ThreadLocalVar:0x00007f04409e9cb0 @default_block=nil, @default=nil, @index=27>, @closed=false, @formatter=#<Logger::Formatter:0x00007f04409e9b98 @datetime_format=nil>, @datetime_format="", @silencer=true, @project="project-name">
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/sidekiq-7.1.6/lib/sidekiq/rails.rb:62:in `block (2 levels) in <class:Rails>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/sidekiq-7.1.6/lib/sidekiq.rb:98:in `configure_server'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/sidekiq-7.1.6/lib/sidekiq/rails.rb:53:in `block in <class:Rails>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/lazy_load_hooks.rb:94:in `block in execute_hook'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/lazy_load_hooks.rb:87:in `with_execution_control'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/lazy_load_hooks.rb:92:in `execute_hook'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/lazy_load_hooks.rb:78:in `block in run_load_hooks'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/lazy_load_hooks.rb:77:in `each'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/activesupport-7.1.1/lib/active_support/lazy_load_hooks.rb:77:in `run_load_hooks'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/railties-7.1.1/lib/rails/application/finisher.rb:93:in `block in <module:Finisher>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/railties-7.1.1/lib/rails/initializable.rb:32:in `instance_exec'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/railties-7.1.1/lib/rails/initializable.rb:32:in `run'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/railties-7.1.1/lib/rails/initializable.rb:61:in `block in run_initializers'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `each'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `call'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
Step #1: 16:27:58 sidekiq.1 | /usr/local/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/railties-7.1.1/lib/rails/initializable.rb:60:in `run_initializers'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/railties-7.1.1/lib/rails/application.rb:423:in `initialize!'
Step #1: 16:27:58 sidekiq.1 | /project-name/config/environment.rb:7:in `<top (required)>'
Step #1: 16:27:58 sidekiq.1 | <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
Step #1: 16:27:58 sidekiq.1 | <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/sidekiq-7.1.6/lib/sidekiq/cli.rb:303:in `boot_application'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/sidekiq-7.1.6/lib/sidekiq/cli.rb:42:in `run'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/sidekiq-7.1.6/bin/sidekiq:31:in `<top (required)>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/bin/sidekiq:25:in `load'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/bin/sidekiq:25:in `<top (required)>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:58:in `load'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:58:in `kernel_load'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:23:in `run'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/cli.rb:492:in `exec'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/cli.rb:34:in `dispatch'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/cli.rb:28:in `start'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/exe/bundle:37:in `block in <top (required)>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/gems/bundler-2.4.19/exe/bundle:29:in `<top (required)>'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/bin/bundle:25:in `load'
Step #1: 16:27:58 sidekiq.1 | /usr/local/bundle/bin/bundle:25:in `<main>'
Step #1: 16:27:58 sidekiq.1 | exited with code 1
Step #1: 16:27:58 system    | sending SIGTERM to all processes
Step #1: 
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/google.com/cloudsdktool/cloud-sdk" failed: step exited with non-zero status: 1
leonvogt commented 1 year ago

I've run into the same problem

jgadbois commented 10 months ago

We're running into this same issue when trying to access rails c on our app engine app

cprodhomme commented 9 months ago

I have an error that looks like when launching Sidekiq:

undefined method `broadcast' for ActiveSupport::Logger:Class

/usr/local/bundle/ruby/3.2.0/gems/sidekiq-7.2.1/lib/sidekiq/rails.rb:62:in `block (2 levels) in <class:Rails>'
/usr/local/bundle/ruby/3.2.0/gems/sidekiq-7.2.1/lib/sidekiq.rb:98:in `configure_server'
/usr/local/bundle/ruby/3.2.0/gems/sidekiq-7.2.1/lib/sidekiq/rails.rb:53:in `block in <class:Rails>'

My stack :

It's very strange because i have only this error in RAILS_ENV=production, not in RAILS_ENV=staging (staging is the same of production)

gregjoy1 commented 9 months ago

We are also experiencing the same problem!

henrahmagix commented 9 months ago

I've solved this by replacing Rails.logger with a BroadcastLogger to the same logger. It's easy to add into your Rails app: just put this straight after the app is initialized =)

unless Rails.logger.respond_to?(:broadcast_to)
  Rails.logger = ActiveSupport::BroadcastLogger.new(Rails.logger)
end

e.g. in config/environment.rb

# Load the Rails application.
require_relative "application"

# Initialize the Rails application.
Rails.application.initialize!

# Rails.logger is a Google::Cloud::Logging::Logger, which does not have `broadcast_to` so
# we have to patch it in to allow activerecord/railtie to not error when opening a rails console. Thankfully we can
# just make Rails.logger a BroadcastLogger.
#
# See https://github.com/rails/rails/blob/v7.1.3/activerecord/lib/active_record/railtie.rb#L70
unless Rails.logger.respond_to?(:broadcast_to)
  Rails.logger = ActiveSupport::BroadcastLogger.new(Rails.logger)
end
florianjosefreheis commented 9 months ago

We see the same error in production with our Sidekiq workers. There is no issue when using the Rails console.

Our stack is:

gotchane commented 1 week ago

Is there any update? I want to use google-cloud-ruby with Rails 7.1+.