Skip to content

Commit

Permalink
trim leading & trailing spaces for kubeparser
Browse files Browse the repository at this point in the history
  • Loading branch information
bentol committed Jul 22, 2021
1 parent 7b4cb12 commit 1ad1da8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions parser/kubeparser/kubeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubeparser

import (
"fmt"
"strings"

"github.com/satyrius/gonx"
"github.com/tidwall/gjson"
Expand All @@ -22,6 +23,8 @@ func NewKubeParser(format string) *KubeParser {
// ParseString implements the Parser interface.
func (t *KubeParser) ParseString(line string) (map[string]string, error) {
actualLogLine := gjson.Get(line, "log").String()
actualLogLine = strings.TrimSpace(actualLogLine)

entry, err := t.parser.ParseString(actualLogLine)
if err != nil {
return nil, fmt.Errorf("text log parsing err: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion parser/kubeparser/kubeparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestKubeParse(t *testing.T) {
parser := NewKubeParser(`[$time_local] $request_method "$request" $request_length $body_bytes_sent $status $request_time $upstream_response_time`)
line := `{"log": "[03/Feb/2021:11:22:33 +0800] GET \"GET /order/2145 HTTP/1.1\" 123 518 200 0.544 0.543", "stream":"stdout","time":"2021-07-21T07:26:39.102952491Z"}`
line := `{"log": "[03/Feb/2021:11:22:33 +0800] GET \"GET /order/2145 HTTP/1.1\" 123 518 200 0.544 0.543\n", "stream":"stdout","time":"2021-07-21T07:26:39.102952491Z"}`

got, err := parser.ParseString(line)
require.NoError(t, err)
Expand Down

0 comments on commit 1ad1da8

Please sign in to comment.