2
votes

I'm having an issue logging to Stackdriver from my golang api. My configuration:

  • GKE cluster running on three compute engine instances
  • Logging and monitoring enabled on GKE container cluster
  • Go service behind ESP
  • There are three nodes in the kube-system namespace running the fluentd image. Names as fluentd-cloud-logging-xxx-xxx-xxx-default-pool-nnnnnn.
  • When I run my service locally (generated using go-swagger) text entries are sent to the global stackdriver log. Nothing when I deploy to my k8s cluster though.

Code I'm using is like:

    api.Logger = func(text string, args ...interface{}) {
    ctx := context.Background()

    // Sets your Google Cloud Platform project ID.
    projectID := "my-project-name"

    // Creates a client.
    client, err := logging.NewClient(ctx, projectID)
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }

    // Sets the name of the log to write to.
    logName := "tried.various.different.names.with.no.luck"

    // Selects the log to write to.
    logger := client.Logger(logName)

    // Sets the data to log.
    textL := fmt.Sprintf(text, args...)

    // Adds an entry to the log buffer.
    logger.Log(logging.Entry{Payload: textL, Severity: logging.Critical})

    // 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)
    }

    fmt.Printf("Logged: %v\n", textL)

}

I don't need error reporting at the moment as I'm just evaluating - I'd be happy with just sending unstructured text. But it's not clear whether I need to do something like Boris' discussion on error reporting/stack traces from Kubernetes pods just to get that?

2
Are you getting any errors from the API when you run your code?Igor Peshansky
I don't believe so. It's been a month now and I moved on. Definitely wasn't getting the log created (logName line above). At one point I thought maybe the code deployed to the k8s cluster was logging to 'global' but I'm not sure as that might have been coming from my local development environment. I've decommissioned that cluster now so I can't check.Dominic Tracey
Have a look in the 'GCE VM Instance' category group. I most likely had the same issue: stackoverflow.com/questions/45022651/…Sylvain

2 Answers

2
votes

Log entries created with the Stackdriver logging client does not seem to be categorized under any of the predefined categories, making it very difficult to find in Logs Viewer's basic mode.

Try to access Logs Viewer "advanced filter interface" by converting the query to a advanced filter and create the following filter:

logName:"projects/my-project-name/logs/tried.various.different.names.with.no.luck"

That worked for me at least.

0
votes

Had similar issue with Golang app in Cloud Run.
To find stackdriver logs you have to specify filter resource.type = "project" in Logs Viewer