简体   繁体   English

Stackdriver日志未显示在GKE中

[英]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.

相关问题 在Kubernetes / Google容器引擎(GKE)上使用Stackdriver API进行日志记录 - Logging using Stackdriver API on Kubernetes / Google Container Engine (GKE) 使用Elastic Beanstalk在AWS上转到Web应用程序,而不显示日志中的输出 - Go Web app on AWS with Elastic Beanstalk not showing output in logs 如何通过Stackdriver Logging将错误记录到Stackdriver Error Reporting - How to log a error to Stackdriver Error Reporting via Stackdriver Logging 自定义指标未显示在新文物上 - Custom metric not showing up on New Relic 自定义OpenCensus指标未显示在Stackdriver上 - Custom OpenCensus metrics not appearing on Stackdriver Docker 划痕图像未显示为 arm64 - Docker scratch image not showing up as arm64 普罗米修斯指标没有显示出来使用普罗米修斯转客户端 - Prometheus metrics not showing up using prometheus go client 如何在StackDriver ErrorReporting UI中填充响应代码 - How to populate response code in StackDriver ErrorReporting UI 如何在 Cloud Run 上使用 Stackdriver 日志记录 - How to use Stackdriver logging on Cloud Run BigQuery 流式插入在 GKE 上失败 - BigQuery streaming inserts fail on GKE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM