googleapis / google-cloud-ruby

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

google-analytics-data - received '13:Internal error encountered.' when running a report, and passing an incorrect shape in the `metrics` field #19013

Open xxx opened 2 years ago

xxx commented 2 years ago

edit: Issue is resolved, but leaving this open because this error isn't being handed on the Google side. Original below:

Hi,

I'm working on porting a UA integration over to v4 / data v1, and and am running into this error for a very simple request. I've traced through the gem to ensure that the auth method is valid (which it should be, as Google::Auth::UserRefreshCredentials is a Signet::OAuth2::Client). Not sure what else it could be.

Environment details

Steps to reproduce

  1. The included script below (when filled with accurate parameters) shows the issue

Code example

client_id = 'my-client-id'
client_secret = 'my-client-secret'
access_token = 'my-access-token'
refresh_token = 'my-refresh-token'
property_id = 'my-property-id'

client = ::Google::Analytics::Data.analytics_data do |config|
  config.credentials = Google::Auth::UserRefreshCredentials.new(
    client_id: client_id,
    client_secret: client_secret,
    access_token: access_token,
    refresh_token: refresh_token,
    scope: 'https://www.googleapis.com/auth/analytics.readonly',
    expires_at: 0
  )
end

report = {
  property: "properties/#{property_id}",
  date_ranges: [{ start_date: '2022-08-03', end_date: '2022-08-10' }],
  metrics: [{ name: 'gametric', expression: 'active28DayUsers' }],
  dimensions: [{ name: 'date' }]
}

client.run_report(report)

Full backtrace

/home/mpd/.rvm/gems/ruby-3.1.0/gems/google-analytics-data-v1beta-0.5.0/lib/google/analytics/data/v1beta/analytics_data/client.rb:316:in `rescue in run_report': 13:Internal error encountered.. debug_error_string:{UNKNOWN:Error received from peer ipv6:%5B2607:f8b0:4005:802::200a%5D:443 {created_time:"2022-08-10T12:31:24.496579441-07:00", grpc_status:13, grpc_message:"Internal error encountered."}} (Google::Cloud::InternalError)
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/google-analytics-data-v1beta-0.5.0/lib/google/analytics/data/v1beta/analytics_data/client.rb:278:in `run_report'
    from /home/mpd/.config/JetBrains/RubyMine2022.2/scratches/scratch_22.rb:33:in `<main>'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/commands/runner/runner_command.rb:43:in `perform'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/command/base.rb:87:in `perform'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/command.rb:48:in `invoke'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<main>'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/mpd/git-sources/double_loop/bin/rails:4:in `<main>'
/home/mpd/.rvm/gems/ruby-3.1.0/gems/grpc-1.48.0-x86_64-linux/src/ruby/lib/grpc/generic/active_call.rb:29:in `check_status': 13:Internal error encountered.. debug_error_string:{UNKNOWN:Error received from peer ipv6:%5B2607:f8b0:4005:802::200a%5D:443 {created_time:"2022-08-10T12:31:24.496579441-07:00", grpc_status:13, grpc_message:"Internal error encountered."}} (GRPC::Internal)
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/grpc-1.48.0-x86_64-linux/src/ruby/lib/grpc/generic/active_call.rb:186:in `attach_status_results_and_complete_call'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/grpc-1.48.0-x86_64-linux/src/ruby/lib/grpc/generic/active_call.rb:382:in `request_response'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/grpc-1.48.0-x86_64-linux/src/ruby/lib/grpc/generic/client_stub.rb:174:in `block (2 levels) in request_response'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/grpc-1.48.0-x86_64-linux/src/ruby/lib/grpc/generic/interceptors.rb:170:in `intercept!'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/grpc-1.48.0-x86_64-linux/src/ruby/lib/grpc/generic/client_stub.rb:173:in `block in request_response'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/gapic-common-0.11.1/lib/gapic/grpc/service_stub/rpc_call.rb:121:in `call'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/gapic-common-0.11.1/lib/gapic/grpc/service_stub.rb:156:in `call_rpc'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/google-analytics-data-v1beta-0.5.0/lib/google/analytics/data/v1beta/analytics_data/client.rb:311:in `run_report'
    from /home/mpd/.config/JetBrains/RubyMine2022.2/scratches/scratch_22.rb:33:in `<main>'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/commands/runner/runner_command.rb:43:in `perform'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/command/base.rb:87:in `perform'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/command.rb:48:in `invoke'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<main>'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/mpd/.rvm/gems/ruby-3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/mpd/git-sources/double_loop/bin/rails:4:in `<main>'
xxx commented 2 years ago

Turns out I am passing metric incorrectly.

When passing the correct shape ([{ name: 'active28DayUsers' }]), the query works fine.

Leaving this open because the error message isn't useful.