Skip to content

Commit

Permalink
Do not format json
Browse files Browse the repository at this point in the history
  • Loading branch information
salvacorts committed Dec 5, 2023
1 parent 58d1bfa commit 6e05bf6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
4 changes: 3 additions & 1 deletion docs/sources/configure/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,9 @@ client:
# CLI flag: -bloom-gateway-client.cache.compression
[compression: <string> | default = ""]
[cache_results: <boolean>]
# Flag to control whether to cache bloom gateway client requests/responses.
# CLI flag: -bloom-gateway-client.cache_results
[cache_results: <boolean> | default = false]
# Number of workers to use for filtering chunks concurrently.
# CLI flag: -bloom-gateway.worker-concurrency
Expand Down
1 change: 1 addition & 0 deletions pkg/bloomgateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand Down
26 changes: 7 additions & 19 deletions pkg/logproto/compat.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package logproto

import (
"bytes"
stdjson "encoding/json"
"fmt"
"io"
"math"
"sort"
"strconv"
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pkg/logproto/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) {
}{
{
desc: "empty request",
expected: `0-[]`,
expected: `0`,
},
{
desc: "request no filters",
Expand All @@ -298,7 +298,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) {
},
},
},
expected: `10379275979514026197-[]`,
expected: `10379275979514026197`,
},
{
desc: "request with filters but no chunks",
Expand All @@ -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",
Expand All @@ -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) {
Expand Down

0 comments on commit 6e05bf6

Please sign in to comment.