我看不到使用Golang从我的GKE集群发送的日志消息。它们在本地运行时可以正常运行,但不能在GKE中运行的容器中运行。显然,GKE中某些配置错误,但是我看不到任何错误,但不确定要在哪里查找。任何见解或检查地点都将非常有用。
下面是我的代码和集群作用域(如果有帮助的话)。
谢谢。
范围:
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
代码:
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)
}
}
答案 0 :(得分:0)
查看此处:
https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform
您的容器化客户端无法针对Cloud Platform日志记录服务进行身份验证。
您没有解释在本地运行客户端时如何进行身份验证,但是这种机制需要在Kubernetes上重现。
如果您检查容器的日志,则这些日志应确认针对日志记录服务进行身份验证失败。
HTH!
答案 1 :(得分:0)
因此,解决方案比我预期的要简单。我还不完全了解,但似乎是stackdriver的工作方式。
当我在本地运行时,我的日志显示在Google Project-> Project ID-> Log Name
下当我在GKE中运行时,它会显示在VM实例->实例ID(或所有实例)->日志名称
中我实际上希望它一直显示在google project下。要么没有,要么我配置了错误的Stackdriver。