从运行在GKE上的Rails应用程序收集错误需要采取哪些步骤?
我已将stackdriver gem添加到我的Rails应用中,并创建了一个具有errorreporting.errorEvents.create
权限的自定义角色。
该角色已授予 Compute Engine默认服务帐户
我认为the docs表示,在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.
那么,我必须授予哪个用户才能执行此工作? :-|
答案 0 :(得分:1)
这似乎是权限问题,因此在安装和配置google-cloud-ruby之后。
然后,您需要启用Stackdriver Error Reporting API。
然后,您需要将角色“ roles / errorreporting.writer”添加到默认的计算服务帐户。
gcloud容器集群创建example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform
创建集群时,需要为平台添加--scope标志,请参见上面的示例: