From b34c2b0bd35e742057ede230e42305ec79f11c1b Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Mon, 2 Dec 2019 09:11:17 -0500 Subject: [PATCH] Move to jsoniter instead of default json package (#1249) * Move to jsoniter instead of default json package Signed-off-by: Cyril Tovena * Removes jsoniter on the logcli output Signed-off-by: Cyril Tovena --- pkg/canary/reader/reader.go | 7 +++---- pkg/logcli/client/client.go | 8 +++----- pkg/logcli/query/query.go | 9 ++++----- pkg/logentry/stages/json.go | 4 +--- pkg/loghttp/query.go | 2 +- pkg/loghttp/tail.go | 2 +- pkg/logql/engine_test.go | 2 +- pkg/logql/marshal/legacy/marshal.go | 3 +-- pkg/logql/marshal/legacy/marshal_test.go | 2 +- pkg/logql/marshal/marshal.go | 3 +-- pkg/logql/marshal/marshal_test.go | 8 +++----- pkg/logql/unmarshal/legacy/unmarshal.go | 2 +- pkg/logql/unmarshal/unmarshal.go | 3 +-- pkg/promtail/api/entry_parser.go | 2 +- 14 files changed, 23 insertions(+), 34 deletions(-) diff --git a/pkg/canary/reader/reader.go b/pkg/canary/reader/reader.go index f139bb2d2d..8191683a9b 100644 --- a/pkg/canary/reader/reader.go +++ b/pkg/canary/reader/reader.go @@ -2,7 +2,6 @@ package reader import ( "encoding/base64" - "encoding/json" "fmt" "io" "io/ioutil" @@ -14,12 +13,12 @@ import ( "time" "github.com/gorilla/websocket" + loghttp "github.com/grafana/loki/pkg/loghttp/legacy" + "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - - loghttp "github.com/grafana/loki/pkg/loghttp/legacy" - "github.com/grafana/loki/pkg/logproto" ) var ( diff --git a/pkg/logcli/client/client.go b/pkg/logcli/client/client.go index d9e91b5b1b..d7d00248ce 100644 --- a/pkg/logcli/client/client.go +++ b/pkg/logcli/client/client.go @@ -2,7 +2,6 @@ package client import ( "encoding/base64" - "encoding/json" "fmt" "io/ioutil" "log" @@ -11,13 +10,12 @@ import ( "strings" "time" + "github.com/gorilla/websocket" "github.com/grafana/loki/pkg/loghttp" + "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/util" - - "github.com/gorilla/websocket" + json "github.com/json-iterator/go" "github.com/prometheus/common/config" - - "github.com/grafana/loki/pkg/logproto" ) const ( diff --git a/pkg/logcli/query/query.go b/pkg/logcli/query/query.go index ca8f56c78f..cd54297dfa 100644 --- a/pkg/logcli/query/query.go +++ b/pkg/logcli/query/query.go @@ -1,7 +1,6 @@ package query import ( - "encoding/json" "fmt" "log" "sort" @@ -9,13 +8,13 @@ import ( "time" "github.com/fatih/color" - "github.com/grafana/loki/pkg/loghttp" - "github.com/grafana/loki/pkg/logql" - "github.com/prometheus/prometheus/promql" - "github.com/grafana/loki/pkg/logcli/client" "github.com/grafana/loki/pkg/logcli/output" + "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" + "github.com/grafana/loki/pkg/logql" + json "github.com/json-iterator/go" + "github.com/prometheus/prometheus/promql" ) type streamEntryPair struct { diff --git a/pkg/logentry/stages/json.go b/pkg/logentry/stages/json.go index 46b453ca6c..888e80f2de 100644 --- a/pkg/logentry/stages/json.go +++ b/pkg/logentry/stages/json.go @@ -1,15 +1,13 @@ package stages import ( - "encoding/json" - //"encoding/json" - //"fmt" "reflect" "time" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/jmespath/go-jmespath" + json "github.com/json-iterator/go" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/prometheus/common/model" diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index b5818f55cc..bb05c5ef73 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -1,7 +1,6 @@ package loghttp import ( - "encoding/json" "errors" "fmt" "net/http" @@ -9,6 +8,7 @@ import ( "time" "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" "github.com/prometheus/common/model" ) diff --git a/pkg/loghttp/tail.go b/pkg/loghttp/tail.go index d6ef5f2c9c..22fbe6d80a 100644 --- a/pkg/loghttp/tail.go +++ b/pkg/loghttp/tail.go @@ -1,13 +1,13 @@ package loghttp import ( - "encoding/json" "fmt" "net/http" "strconv" "time" "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" ) const ( diff --git a/pkg/logql/engine_test.go b/pkg/logql/engine_test.go index 27788cfdba..92026ce3f9 100644 --- a/pkg/logql/engine_test.go +++ b/pkg/logql/engine_test.go @@ -2,13 +2,13 @@ package logql import ( "context" - "encoding/json" "fmt" "testing" "time" "github.com/grafana/loki/pkg/iter" "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/promql" "github.com/stretchr/testify/assert" diff --git a/pkg/logql/marshal/legacy/marshal.go b/pkg/logql/marshal/legacy/marshal.go index a59987ce2d..32353e92c5 100644 --- a/pkg/logql/marshal/legacy/marshal.go +++ b/pkg/logql/marshal/legacy/marshal.go @@ -3,15 +3,14 @@ package marshal import ( - "encoding/json" "fmt" "io" "github.com/gorilla/websocket" loghttp "github.com/grafana/loki/pkg/loghttp/legacy" "github.com/grafana/loki/pkg/logproto" - "github.com/grafana/loki/pkg/logql" + json "github.com/json-iterator/go" "github.com/prometheus/prometheus/promql" ) diff --git a/pkg/logql/marshal/legacy/marshal_test.go b/pkg/logql/marshal/legacy/marshal_test.go index 236a06788f..ef7896c418 100644 --- a/pkg/logql/marshal/legacy/marshal_test.go +++ b/pkg/logql/marshal/legacy/marshal_test.go @@ -2,7 +2,6 @@ package marshal import ( "bytes" - "encoding/json" "log" "testing" "time" @@ -10,6 +9,7 @@ import ( loghttp "github.com/grafana/loki/pkg/loghttp/legacy" "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql" + json "github.com/json-iterator/go" "github.com/stretchr/testify/require" ) diff --git a/pkg/logql/marshal/marshal.go b/pkg/logql/marshal/marshal.go index 3be38b5621..aafc7a7392 100644 --- a/pkg/logql/marshal/marshal.go +++ b/pkg/logql/marshal/marshal.go @@ -3,14 +3,13 @@ package marshal import ( - "encoding/json" "io" "github.com/gorilla/websocket" "github.com/grafana/loki/pkg/loghttp" legacy "github.com/grafana/loki/pkg/loghttp/legacy" - "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" "github.com/prometheus/prometheus/promql" ) diff --git a/pkg/logql/marshal/marshal_test.go b/pkg/logql/marshal/marshal_test.go index a4b1936560..8e79513a53 100644 --- a/pkg/logql/marshal/marshal_test.go +++ b/pkg/logql/marshal/marshal_test.go @@ -2,18 +2,16 @@ package marshal import ( "bytes" - "encoding/json" "testing" "time" "github.com/grafana/loki/pkg/loghttp" legacy "github.com/grafana/loki/pkg/loghttp/legacy" - - "github.com/prometheus/prometheus/pkg/labels" - "github.com/prometheus/prometheus/promql" - "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql" + json "github.com/json-iterator/go" + "github.com/prometheus/prometheus/pkg/labels" + "github.com/prometheus/prometheus/promql" "github.com/stretchr/testify/require" ) diff --git a/pkg/logql/unmarshal/legacy/unmarshal.go b/pkg/logql/unmarshal/legacy/unmarshal.go index 065aef0e6b..70ecd34938 100644 --- a/pkg/logql/unmarshal/legacy/unmarshal.go +++ b/pkg/logql/unmarshal/legacy/unmarshal.go @@ -1,10 +1,10 @@ package unmarshal import ( - "encoding/json" "io" "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" ) // DecodePushRequest directly decodes json to a logproto.PushRequest diff --git a/pkg/logql/unmarshal/unmarshal.go b/pkg/logql/unmarshal/unmarshal.go index fecaa17815..12597bbea8 100644 --- a/pkg/logql/unmarshal/unmarshal.go +++ b/pkg/logql/unmarshal/unmarshal.go @@ -1,12 +1,11 @@ package unmarshal import ( - "encoding/json" "io" "github.com/grafana/loki/pkg/loghttp" - "github.com/grafana/loki/pkg/logproto" + json "github.com/json-iterator/go" ) // DecodePushRequest directly decodes json to a logproto.PushRequest diff --git a/pkg/promtail/api/entry_parser.go b/pkg/promtail/api/entry_parser.go index b501cc20aa..58f33675da 100644 --- a/pkg/promtail/api/entry_parser.go +++ b/pkg/promtail/api/entry_parser.go @@ -1,12 +1,12 @@ package api import ( - "encoding/json" "fmt" "regexp" "strings" "time" + json "github.com/json-iterator/go" "github.com/prometheus/common/model" )