[英]Stackdriver logs not showing up in GKE
I am unable to see log messages that are sent from my GKE clusters using Golang. 我看不到使用Golang从我的GKE集群发送的日志消息。 They work fine when running locally but not from the container running in GKE. 它们在本地运行时可以正常运行,但不能在GKE中运行的容器中运行。 Clearly something is misconfigured in GKE but I don't see any errors but not really sure where to look. 显然,GKE中某些配置错误,但是我看不到任何错误,但不确定要在哪里查找。 Any insight or places to check would be very useful. 任何见解或检查的地方将非常有用。
Below is my code and my cluster scopes (if it helps). 以下是我的代码和集群作用域(如果有帮助的话)。
Thanks. 谢谢。
Scopes: 范围:
oauthScopes:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/compute
- https://www.googleapis.com/auth/datastore
- https://www.googleapis.com/auth/devstorage.full_control
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring
- https://www.googleapis.com/auth/monitoring.write
- https://www.googleapis.com/auth/pubsub
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/servicecontrol
- https://www.googleapis.com/auth/source.full_control
- https://www.googleapis.com/auth/sqlservice.admin
- https://www.googleapis.com/auth/trace.append
Code: 码:
func LogMessage(logLevel ReddiyoLoggingSeverity, message, domain, transactionID string) {
ctx := context.Background()
// Creates a client.
client, err := logging.NewClient(ctx, loggingData.ProjectID)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Selects the log to write to.
logger := client.Logger(loggingData.LogName)
labels := make(map[string]string)
labels["transactionID"] = transactionID
labels["domain"] = domain
var logSeverity logging.Severity
switch logLevel {
case debug:
logSeverity = logging.Debug
case info:
logSeverity = logging.Info
case warning:
logSeverity = logging.Warning
case reddiyoError:
logSeverity = logging.Error
case critical:
logSeverity = logging.Critical
case emergency:
logSeverity = logging.Emergency
default:
logSeverity = logging.Warning
}
logger.Log(logging.Entry{
Payload: message,
Severity: logSeverity,
Labels: labels})
// Closes the client and flushes the buffer to the Stackdriver Logging
// service.
if err := client.Close(); err != nil {
log.Fatalf("Failed to close client: %v", err)
}
}
See here: 看这里:
https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform
Your containerized client is unable to authenticate against the Cloud Platform Logging service. 您的容器化客户端无法针对Cloud Platform日志记录服务进行身份验证。
You don't explain how you're authenticating when running the client locally but this mechanism needs to be reproduced on Kubernetes. 您没有解释在本地运行客户端时如何进行身份验证,但是这种机制需要在Kubernetes上重现。
If you check the container's logs, these should confirm the failure to authenticate against the Logging service. 如果您检查容器的日志,这些日志应确认针对日志服务进行身份验证失败。
HTH! HTH!
So the solution was simplier than I was expecting. 因此解决方案比我预期的要简单。 I don't fully understand it yet but appears to be how stackdriver works. 我还不完全了解它,但似乎是stackdriver的工作方式。
When I run locally then my logs show up under Google Project --> Project ID --> Log Name 当我在本地运行时,我的日志显示在Google Project-> Project ID-> Log Name下
When I run in GKE then it shows up in VM Instance --> Instance ID (or all Instance) --> Log Name 当我在GKE中运行时,它会显示在VM实例->实例ID(或所有实例)->日志名称中
I would actually expect it to show up under google project all the time. 我实际上希望它一直显示在google project下。 Either it doesn't or I misconfigured Stackdriver. 要么没有,要么我配置了错误的Stackdriver。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.