From 6e05bf660d83ee7eea209dfc2de714238c864e37 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 5 Dec 2023 13:40:16 +0100 Subject: [PATCH] Do not format json --- docs/sources/configure/_index.md | 4 +++- pkg/bloomgateway/client.go | 1 + pkg/logproto/compat.go | 26 +++++++------------------- pkg/logproto/compat_test.go | 8 ++++---- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/docs/sources/configure/_index.md b/docs/sources/configure/_index.md index 15558cfa19e4b..0323f0c652538 100644 --- a/docs/sources/configure/_index.md +++ b/docs/sources/configure/_index.md @@ -1849,7 +1849,9 @@ client: # CLI flag: -bloom-gateway-client.cache.compression [compression: | default = ""] - [cache_results: ] + # Flag to control whether to cache bloom gateway client requests/responses. + # CLI flag: -bloom-gateway-client.cache_results + [cache_results: | default = false] # Number of workers to use for filtering chunks concurrently. # CLI flag: -bloom-gateway.worker-concurrency diff --git a/pkg/bloomgateway/client.go b/pkg/bloomgateway/client.go index 45c7d8b9e22fb..4ea79b207b392 100644 --- a/pkg/bloomgateway/client.go +++ b/pkg/bloomgateway/client.go @@ -117,6 +117,7 @@ func (i *ClientConfig) RegisterFlags(f *flag.FlagSet) { func (i *ClientConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { i.GRPCClientConfig.RegisterFlagsWithPrefix(prefix+"grpc", f) i.Cache.RegisterFlagsWithPrefix(f, prefix+"cache.") + f.BoolVar(&i.CacheResults, prefix+"cache_results", false, "Flag to control whether to cache bloom gateway client requests/responses.") f.BoolVar(&i.LogGatewayRequests, prefix+"log-gateway-requests", false, "Flag to control whether requests sent to the gateway should be logged or not.") } diff --git a/pkg/logproto/compat.go b/pkg/logproto/compat.go index bdb8408571f42..b248a352c9507 100644 --- a/pkg/logproto/compat.go +++ b/pkg/logproto/compat.go @@ -1,10 +1,8 @@ package logproto import ( - "bytes" stdjson "encoding/json" "fmt" - "io" "math" "sort" "strconv" @@ -369,30 +367,20 @@ func (m *FilterChunkRefRequest) GetQuery() string { // Short circuit if there are no filters. if len(m.Filters) == 0 { - return fmt.Sprintf("%d-[]", chunksHash) + return fmt.Sprintf("%d", chunksHash) } - var buf bytes.Buffer - s := jsoniter.ConfigFastest.BorrowStream(io.Writer(&buf)) - defer jsoniter.ConfigFastest.ReturnStream(s) - s.WriteArrayStart() + var sb strings.Builder for i, filter := range m.Filters { if i > 0 { - s.WriteMore() + sb.WriteString(",") } - - s.WriteObjectStart() - s.WriteObjectField("op") - s.WriteInt64(filter.Operator) - s.WriteMore() - s.WriteObjectField("match") - s.WriteString(filter.Match) - s.WriteObjectEnd() + sb.WriteString(strconv.Itoa(int(filter.Operator))) + sb.WriteString("-") + sb.WriteString(filter.Match) } - s.WriteArrayEnd() - _ = s.Flush() - return fmt.Sprintf("%d-%s", chunksHash, buf.String()) + return fmt.Sprintf("%d/%s", chunksHash, sb.String()) } // GetCachingOptions returns the caching options. diff --git a/pkg/logproto/compat_test.go b/pkg/logproto/compat_test.go index b11433f4d0e53..b0b87f2014ca0 100644 --- a/pkg/logproto/compat_test.go +++ b/pkg/logproto/compat_test.go @@ -286,7 +286,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) { }{ { desc: "empty request", - expected: `0-[]`, + expected: `0`, }, { desc: "request no filters", @@ -298,7 +298,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) { }, }, }, - expected: `10379275979514026197-[]`, + expected: `10379275979514026197`, }, { desc: "request with filters but no chunks", @@ -310,7 +310,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) { }, }, }, - expected: `0-[{"op":0,"match":"uuid"}]`, + expected: `0/0-uuid`, }, { desc: "request with filters and chunks", @@ -336,7 +336,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) { }, }, }, - expected: `8320232433975427174-[{"op":0,"match":"uuid"},{"op":1,"match":"trace"}]`, + expected: `8320232433975427174/0-uuid,1-trace`, }, } { t.Run(tc.desc, func(t *testing.T) {