Skip to content

Logging in GKE is not using the ContainerEngineHandler #3622

@arthurdarcet

Description

@arthurdarcet

The KUBERNETES_SERVICE environment variable is not set in a pod running on GKE, so ContainerEngineHandler never actually gets selected as the default handler here

This means all the logs go directly to the "Global" section of the Logging tab in the GCloud console, instead of being parsed by the fluentd pod running on the host, and being routed to the right "GKE > cluster > container name" section. And of course no pod/host/… metadata is added to the log.

I think the checked variable should read KUBERNETES_SERVICE_HOST but i did not open a pull request because ContainerEngineHandler does not work either: When I manually add a ContainerEngineHandler handler to the logging configuration, the logging interface at console.cloud.google.com does not actually parse the JSON that is written to stderr, so the severity for instance is not set correctly (the JSON produced by ContainerEngineHandler is directly displayed as the textPayload).

And finally (not really related to this but I'm not sure where this should go): the fluentd-gcp pod that is running by default on GKE clusters is configured with this fluentd configuration:

<filter …>
  …
  format /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<log>.*)/
</filter>

which is a very weird regex:

  • it parses only one char for the severity
  • the time is parsed as YYYY followed by a space, followed by anything but a space: this does not correspond to any datetime format i can think of
  • the source attribute is followed by a ], but no matching [ is in the regex

The severity issue makes it impossible to actually use this filter since stackdriver does not accept logs with a severity outside the usual INFO|WARN|ERROR|…

--

All-in-all, this makes it really hard to log data from a python pod: logging with the CloudLogging handler goes to "Global" by default (and is missing many kubernetes-related meta), logging to stderr a JSON-formatted object is not parsed by the console.cloud UI, and the regex in the fluentd setup cannot pick up any valid input

OS: Kubernetes 1.6.6, running on GKE with cos
Python version: 3.6 or pypy 5.8
google-cloud-python version: 1.1.0

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the Cloud Logging API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions