繁体   English   中英

Stackdriver日志未显示在GKE中

[英]Stackdriver logs not showing up in GKE

我看不到使用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)
    }
}

看这里:

https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform

您的容器化客户端无法针对Cloud Platform日志记录服务进行身份验证。

您没有解释在本地运行客户端时如何进行身份验证,但是这种机制需要在Kubernetes上重现。

如果您检查容器的日志,这些日志应确认针对日志服务进行身份验证失败。

HTH!

因此解决方案比我预期的要简单。 我还不完全了解它,但似乎是stackdriver的工作方式。

当我在本地运行时,我的日志显示在Google Project-> Project ID-> Log Name下

当我在GKE中运行时,它会显示在VM实例->实例ID(或所有实例)->日志名称中

我实际上希望它一直显示在google project下。 要么没有,要么我配置了错误的Stackdriver。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM