-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON parsing from a GKE container #143
Conversation
…uld be parsed as JSON
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
CLAs look good, thanks! |
@crassirostris Doesn't JSON parsing work with GKE today? |
@igorpeshansky There are two layers of JSON currently. First is the json-file wrapping of docker. That's what performed in the input plugin in K8s, then the record goes to the plugin and if the message from container was json, it gets unwrapped second time @arthurdarcet Just set input format to json, plugin handles the rest already. See the configuration, used in GKE by default. |
@crassirostris no, the GKE default configuration is doing the JSON decode for the docker layer of log. What we have here is an app logging JSON, so the logs look like {"stream": "stderr", "time": "…", "log": "{\"some\": \"key\", \"httpRequest\": {}, \"message\": \"log msg\"}"} We can of course add another filter to the fluentd config (and this is actually what we are currently doing in production), but 1. changing the config of the default fluentd DeamonSet is not obvious (you need to update the default DeamonSet to add a |
@igorpeshansky |
@arthurdarcet Then it should work already, try installing the mentioned configuration in your cluster (instructions) and logging json to stdout/stderr, it should show up as jsonPayload in the UI |
our cluster is a regular, up to date, GKE cluster. It is already using this config |
Mik is right. It should work for GKE already.
|
OK, thanks for clarifying! Could you please describe the replication steps? A line to write by your pod, what happens, what you expect to happen |
@crassirostris Sorry for the slow response. I'm running this pod apiVersion: v1
kind: Pod
metadata:
name: arthur
spec:
restartPolicy: Never
containers:
- name: arthur
image: busybox:latest
args:
- echo
- '{"message": "nested message"}' on a Kubernetes cluster with the default fluent-gcp DeamonSet (with This logs as a
I would expect the payload to be JSON decoded, and in the |
@arthurdarcet Could you please specify what OS you're using and take a look at the JSON structure in any file under the following path on any node: |
I'm interested in the set of fields in the said file. There's a check in the current stackdriver fluentd plugin that won't allow JSON parsing to happen unless the message in the |
this is a default GKE cluster, so the OS is Container OS (cos-stable-59-9460-60-0) The corresponding log file for my pod contains:
|
@arthurdarcet What do you mean by the default GKE cluster and the default fluentd-gcp DaemonSet? Kubernetes 1.7.3, where fluentd image version was updated to 2.0.8 hasn't been released in GKE yet :) Just checked and when you perform said command on the default GKE cluster (Kubernetes 1.7.2 and fluentd 2.0.7) with Stackdriver Logging enabled, message is ingested as json:
Moreover, it also works with 2.0.8 |
ok, thank you for looking into this. To be perfectly exact:
with this, my pod logs as a Are there other components here that could change this? |
@arthurdarcet There was a problem in the past, caused by the same peculiarity mentioned in #143 (comment), when adding a field to the fluentd record in the config resulted in broken JSON parsing. More details in kubernetes/kubernetes#48139. But I think it was fixed in 1.6.6 Note, that you cannot simply change the fluentd DaemonSet in GKE cluster, it will be reverted back in a minute, it's described more in the K8s docs If you have your custom configuration, maybe you have some record transforms there? |
perfect, thank you, this was what I was missing. The tag filter was not yet added in 1.6.6 so that's what was breaking the JSON parsing. For the DeamonSet, I managed to kill the default one by adding a nodeSelector to its spec, and duplicated it to add your commit manually until we upgrade the cluster. Thanks again! |
When logging from a Kubernetes cluster on GKE, the logs received by fluentd are those sent by docker, and follow the format:
The JSON parsing done by this plugin would be a really simple way to output formatted logs directly from an application.
This PR makes the log sent by docker acceptable for optional JSON-decoding, by putting aside the stream key just like the time key and restoring it after deciding whether or not it should be JSON-decoded