首页 > 解决方案 > Ruby 的 Stackdriver 错误报告,在 GKE 上运行

问题描述

从 GKE 上运行的 Rails 应用收集错误需要哪些步骤?

我已将 stackdriver gem 添加到我的 Rails 应用程序中,并创建了具有errorreporting.errorEvents.create权限的自定义角色。该角色分配给Compute Engine 默认服务帐号

我解释说在 GKE 上运行时不必进行以下设置的文档:

# Add this to config/environments/*.rb
Rails.application.configure do |config|
  # Stackdriver Error Reporting specific parameters
  config.google_cloud.error_reporting.project_id = "YOUR-PROJECT-ID"
  config.google_cloud.error_reporting.keyfile    = "/path/to/service-account.json"
end

我手动创建了一个异常

这给了我宝贵的信息:

irb(main):001:0> Google::Cloud::ErrorReporting.report Exception.new(msg: "from console")
=> nil
irb(main):002:0> {:msg=>"from console"} (Exception)
Google::Cloud::PermissionDeniedError: 7:Stackdriver Error Reporting API has not been used in project NNNNN before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/clouderrorreporting.googleapis.com/overview?project=NNNN then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

启用 API 后,我收到此错误:

irb(main):004:0> {:msg=>"from console"} (Exception)
Google::Cloud::PermissionDeniedError: 7:User not authorized.

那么,我必须向哪个用户授予哪些权限才能完成这项工作?:-|

标签: ruby-on-railsstackdrivergoogle-kubernetes-enginegoogle-cloud-stackdrivergoogle-iam

解决方案


这似乎是权限问题,所以在安装和配置google-cloud-ruby之后。

然后,您需要启用 Stackdriver 错误报告 API。

然后您需要将角色“roles/errorreporting.writer”添加到默认计算服务帐户。

gcloud 容器集群创建 example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform

创建集群时,您需要为平台添加 --scope 标志,请参见上面的示例:


推荐阅读