使用Stackdriver API在Kubernetes / Google Container Engine (GKE)上进行日志记录

huangapple go评论84阅读模式
英文:

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

问题

我有一个使用Google Cloud Logging API的Go应用程序。

相关的代码与他们文档中的示例相同:https://github.com/GoogleCloudPlatform/golang-samples/blob/master/logging/logging_quickstart/main.go

在使用minikube进行检查后(我的负载出现在日志查看器的“全局”类别中),我将应用程序部署到了Google容器引擎(GKE)上。

一旦在GKE上部署,我就无法看到应用程序通过日志API发送的日志。写入std的日志出现在“GKE容器”类别中,但是我使用API发送的条目没有任何痕迹。

我的集群启用了Stackdriver日志API(仅写入),默认服务帐号是Editor(甚至尝试过Owner),我还尝试过使用专用服务帐号(使用环境变量GOOGLE_APPLICATION_CREDENTIALS)具有日志编写者或所有者访问权限,但我无法看到日志,并且客户端库没有报告任何错误。

可能是什么原因,或者我应该从哪里开始调试这个问题?

谢谢。

英文:

I have a go application that leverages Google Cloud Logging API.

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

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).

Once deployed there, I can no longer see the logs the app sends through the logging API.
The logs written to std appears in the GKE container category, but no trace of the entries I send using the 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.

What could be the cause or where could I start debugging such issue?

Thank you,

答案1

得分: 4

原来日志确实存在,只是不在我预期的位置。

使用gcloud CLI,我可以看到这些日志的资源类型为gce_instance,因此出现在GCE VM Instance类别中。

为了找出这个问题:

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

然后

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

注意typegce_instance

英文:

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

To figure this out:

  $ gcloud beta logging logs list
  projects/&lt;PROJECT&gt;/logs/&lt;LOG_NAME&gt;
  ...

then

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

Note type being gce_instance

huangapple
  • 本文由 发表于 2017年7月11日 06:32:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/45022651.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定