从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.
那么,我必须向哪个用户授予哪些权限才能使其工作? : - |
这似乎是权限问题,因此在安装和配置google-cloud-ruby之后。
然后,您需要启用Stackdriver错误报告API。
然后,您需要将角色“roles / errorreporting.writer”添加到默认计算服务帐户。
gcloud容器集群创建example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform
创建集群时,需要为平台添加--scope标志,请参见上面的示例: