简体   繁体   English

在Kubernetes / Google容器引擎(GKE)上使用Stackdriver API进行日志记录

[英]Logging using Stackdriver API on Kubernetes / Google Container Engine (GKE)

I have a go application that leverages Google Cloud Logging API. 我有一个利用Google Cloud Logging API的go应用程序。

The relevant code is the same as this sample from their documentation: https://github.com/GoogleCloudPlatform/golang-samples/blob/master/logging/logging_quickstart/main.go 相关代码与他们的文档中的该示例相同: https : //github.com/GoogleCloudPlatform/golang-samples/blob/master/logging/logging_quickstart/main.go

After checking it works with minikube (my payload appears in the Global category of my logs viewer), I deploy the app on Google Container Engine (GKE). 在检查它是否适用于minikube(我的有效负载出现在日志查看器的“ Global类别中)之后,我将应用程序部署到了Google容器引擎(GKE)上。

Once deployed there, I can no longer see the logs the app sends through the logging API. 一旦部署到那里,我将不再看到应用程序通过日志记录API发送的日志。 The logs written to std appears in the GKE container category, but no trace of the entries I send using the API. 写入std的日志显示在GKE container类别中,但没有跟踪使用API​​发送的条目。

My cluster has Stackdriver logging API enabled / write only, the default service account is Editor (even tried with Owner), I also tried with a dedicated service account (using the env GOOGLE_APPLICATION_CREDENTIALS ) with log writer or even owner access, I can't see the logs and no error are reported from the client library. 我的集群启用了Stackdriver Logging API /仅写,默认服务帐户是Editor(甚至与Owner一起尝试过),我也尝试了具有日志记录器甚至所有者访问权限的专用服务帐户(使用env GOOGLE_APPLICATION_CREDENTIALS ),我无法查看日志,并且客户端库未报告任何错误。

What could be the cause or where could I start debugging such issue? 可能是什么原因,或者在哪里可以开始调试此类问题?

Thank you, 谢谢,

So turns out the log were there but not where I'd expect them. 因此,事实证明日志在那儿,但不在我期望的地方。

Using the gcloud CLI I could see those logs got the resource type gce_instance and therefore appears in the GCE VM Instance category 使用gcloud CLI,我可以看到这些日志的资源类型为gce_instance ,因此出现在GCE VM Instance类别中

To figure this out: 要弄清楚这一点:

  $ gcloud beta logging logs list
  projects/<PROJECT>/logs/<LOG_NAME>
  ...

then 然后

$ gcloud beta logging read projects/<PROJECT>/logs/<LOG_NAME>
---
insertId: ...
jsonPayload:
   ...
logName: ...
receiveTimestamp: ...
resource:
  labels:
    instance_id: ...
    project_id: ...
    zone: ...
  type: gce_instance
timestamp: ...

Note type being gce_instance 笔记typegce_instance

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Go 在 Google Container/Compute Engine 中登录到 Google Cloud - Logging to the Google Cloud in Google Container/Compute Engine with Go Go + MySql:迁移到GKE(Google云容器引擎)有多容易? - Go+MySql: how easy is to migrate to GKE (Google Cloud Container Engine)? 如何使用Go Client查询kubernetes定制api(networking.gke.io/v1beta1)? - How to query kubernetes custom api (networking.gke.io/v1beta1) using go client? Stackdriver日志未显示在GKE中 - Stackdriver logs not showing up in GKE 带有Google App Engine Go 1.11运行时的Stackdriver Trace - Stackdriver Trace with Google App Engine Go 1.11 runtime 无法使用默认服务帐户和Google云库从Google Kubernetes Engine访问Google Cloud Storage - Unable to access Google Cloud Storage from Google Kubernetes Engine using default service account and google cloud libraries Google Stackdriver 日志条目记录字段 logging.googleapis.com/severity vs severity - Google Stackdriver log entry record field logging.googleapis.com/severity vs severity 如何通过Stackdriver Logging将错误记录到Stackdriver Error Reporting - How to log a error to Stackdriver Error Reporting via Stackdriver Logging Google App Engine Flex 容器部署问题 - Google App Engine Flex Container Deployment Issues 如何创建新的客户端证书/令牌,以便以编程方式访问GKE上托管的Kubernetes API? - How to create new client certificates / tokens for programmatic access to the Kubernetes API hosted on GKE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM