google-cloud-platform - Google.Cloud.Diagnostics.AspNetCore 3.0.0-beta13 不适用于 GKE
问题描述
目的
在 .net core 2.2 REST API 上使用 Google Cloud Diagnostics,在两种可能的情况下进行日志记录、跟踪和错误报告:
- Visual Studio 2017 上的本地执行
- 部署在 Docker 容器上并在 GCP Kubernetes Engine 上运行
环境细节
- .NET 版本:2.2.0
- 包名和版本:Google.Cloud.Diagnostics.AspNetCore 3.0.0-beta13
描述
为了配置 Google Cloud Diagnostics,使用了两个文档源:
基于上述文档,使用了 IWebHostBuilder 上的 UseGoogleDiagnostics 扩展方法,因为它配置了日志记录、跟踪和错误报告中间件。
根据 2) 链接,下表显示了使用 UseGoogleDiagnostics 方法时所需的信息:
- 对于本地执行 => 需要 project_id、module_id 和 version_id,
- 对于 GKE => module_id 和 version_id
.net 核心配置文件用于为每个部署提供上述信息:
应用设置.json
{
"GCP": {
"ServiceID": "my-service",
"VersionID": "v1"
}
}
appsettings.Development.json
{
"GCP": {
"ID": "my-id"
}
}
基本上,上面将呈现以下配置:
- 本地执行
return WebHost.CreateDefaultBuilder(args)
.UseGoogleDiagnostics("my-id", "my-service", "v1")
.UseStartup<Startup>();
- 在 GKE 上
return WebHost.CreateDefaultBuilder(args)
.UseGoogleDiagnostics(null, "my-service", "v1")
.UseStartup<Startup>();
为了保证我使用的是正确的信息,我在 GCP UI 上使用了两个地方来验证:
- 在端点列表中,检查了服务详细信息:
Service name: my-service Active version: v1
- 检查端点日志,以获取特定的 API POST 端点
{
insertId: "e6a63a28-1451-4132-ad44-a4447c33a4ac@a1"
jsonPayload: {…}
logName: "projects/xxx%2Fendpoints_log"
receiveTimestamp: "2019-07-11T21:03:34.851569606Z"
resource: {
labels: {
location: "us-central1-a"
method: "v1.xxx.ApiOCRPost"
project_id: "my-id"
service: "my-service"
version: "v1"
}
type: "api"
}
severity: "INFO"
timestamp: "2019-07-11T21:03:27.397632588Z"
}
我做错了什么还是 Google.Cloud.Diagnostics.AspNetCore 3.0.0-beta13 上的错误?
在执行服务端点时,对于每个特定部署,Google Cloud 诊断的行为都不同:
- 在本地执行 (VS2017) => 记录、跟踪和错误报告按预期工作,所有内容都显示在 GCP UI 中
- 在 GKE 部署中 => 日志记录、跟踪和错误报告不起作用,GCP UI 中没有显示任何内容
我尝试了几种变体,直接在代码中硬编码值等,但无论我做什么,谷歌云诊断在 GKE 中部署时都不起作用:
- 直接硬编码值
return WebHost.CreateDefaultBuilder(args)
.UseGoogleDiagnostics(null, "my-service", "v1")
.UseStartup<Startup>();
- 版本中没有 v
return WebHost.CreateDefaultBuilder(args)
.UseGoogleDiagnostics(null, "my-service", "1")
.UseStartup<Startup>();
解决方案
推荐阅读
- forms - 如何使用 TypoScript 覆盖 TYPO3 表单框架的 YAML 设置?
- r - 如何删除序列中包含两个或多个单词(彼此之后)的行?
- c# - 如何在不同的网站(不同的服务器)之间共享会话
- android - 线性渐变(作为背景)不适用于chrome(android)
- reactjs - React redux connect 函数返回了意外的东西
- r - R中的结构XML问题
- python - 使用 Python 的 API 将文件上传到谷歌驱动器时出现问题
- php - 使用 Stripe 如何将 PaymentIntent 的客户端密码传递给表单?
- pdf - 使用 postscript 从 pdf 流中获取 pdf Mediabox
- jpa - 错误 ”
不能被选为标准的根,因为它不是一个实体”