loggie icon indicating copy to clipboard operation
loggie copied to clipboard

goccy/go-yaml deal with blank string uncorrectly

Open polym opened this issue 2 years ago • 5 comments

goccy/go-yaml deal with blank string uncorrectly which is introduced by #242. And I met problem with parsing default containerd log.

CODE

package main

import (
	"fmt"

	errYaml "github.com/goccy/go-yaml"
	okYaml "gopkg.in/yaml.v2"
)

func main() {
	v := struct {
		Key string
	}{
		Key: " ",
	}
	d1, _ := okYaml.Marshal(v)
	fmt.Printf("%s\n%s\n", "YES", string(d1))

	d2, _ := errYaml.Marshal(v)
	fmt.Printf("%s\n%s\n", "NO", string(d2))

}

OUTPUT

YES
key: ' '

NO
key:

In what area(s)?

/area interceptor

What version of Loggie?

v1.2.0+

Expected Behavior

Load interceptor successfully

Actual Behavior

Got warnning log. get processor error: Key: 'SplitConfig.Separator' Error:Field validation for 'Separator' failed on the 'required' tag.

Steps to Reproduce the Problem

  1. Config CRD Interceptor
    - type: normalize
      processors:
        - split:
            separator: ' '
            max: 4
            keys: [ "time", "stream", "F", "message" ]
        - drop:
            targets: [ "F", "body" ]
        - rename:
            convert:
              - from: "message"
                to: "body"
        - underRoot:
            keys:
              - kubernetes
  1. kubectl delete pod and kubectl logs pod

polym avatar Jul 20 '22 11:07 polym

@ethfoo PTAL

polym avatar Jul 21 '22 01:07 polym

Please refer to this document first when parsing the container log. The two YAML libraries do have some differences, and I'm still trying to figure out how to handle them.

ethfoo avatar Jul 21 '22 06:07 ethfoo

@ethfoo

Thanks. If I understand correctly, the document link you given seems to LogConfig. However, I use ClusterLogConfig to collect all pod's logs.

My CRD spec:

apiVersion: loggie.io/v1beta1
kind: ClusterLogConfig
metadata:
  name: all-pod-logs
spec:
  selector:
    type: cluster
    cluster: {{ .Values.config.loggie.discovery.kubernetes.cluster }}
  pipeline:
    sources: |
      - type: file
        name: container-logs
        paths:
          - /var/log/pods/**/*.log
    sinkRef: {{ .Values.sink.name }}
    interceptorRef: containerd

polym avatar Jul 21 '22 08:07 polym

I also encountered a similar problem when collecting container logs with k8s discovery enabled: if belongTo was specified explicitly, the belongTo field was not updated with the value podName/containerName/originalName. if rolling back to gopkg.in/yaml.v2, the belongTo field could be updated successfully.

apiVersion: loggie.io/v1beta1
kind: Interceptor
metadata:
  name: test
spec:
  interceptors: |
    - type: normalize
      name: test
      belongTo: ["test"]
      processors:
          ...

OliverWoo avatar Jul 23 '22 04:07 OliverWoo

https://github.com/goccy/go-yaml/issues/309

ethfoo avatar Aug 04 '22 08:08 ethfoo

Fixed: #317

ethfoo avatar Aug 10 '22 14:08 ethfoo