Skip to content

Commit cf55c09

Browse files
authored
connect: Use klauspost/compress/gzip decompression (#3314)
* Fix missing parameter in makefile * connect: Use klauspost/compress/gzip decompression At the same time this make sures that all handlers and clients use the same compressor pool. Otherwise every new handler and client maintains its own pool.
1 parent 53f7de2 commit cf55c09

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ docker-image/pyroscope/build: frontend/build go/bin
201201
docker-image/pyroscope/push: GOOS=linux
202202
docker-image/pyroscope/push: GOARCH=amd64
203203
docker-image/pyroscope/push: frontend/build go/bin
204-
$(call docker_buildx,--push)
204+
$(call docker_buildx,--push,)
205205

206206
define UPDATER_CONFIG_JSON
207207
{

pkg/api/connect/compression.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package connectapi
2+
3+
import (
4+
"io"
5+
6+
"connectrpc.com/connect"
7+
"github.com/klauspost/compress/gzip"
8+
)
9+
10+
const (
11+
compressionGzip = "gzip"
12+
)
13+
14+
var (
15+
gzipPoolHandler = connect.WithCompression(
16+
compressionGzip,
17+
func() connect.Decompressor { return &gzip.Reader{} },
18+
func() connect.Compressor { return gzip.NewWriter(io.Discard) },
19+
)
20+
gzipPoolClient = connect.WithAcceptCompression(
21+
compressionGzip,
22+
func() connect.Decompressor { return &gzip.Reader{} },
23+
func() connect.Compressor { return gzip.NewWriter(io.Discard) },
24+
)
25+
)
26+
27+
func WithGzipHandler() connect.HandlerOption {
28+
return gzipPoolHandler
29+
}
30+
31+
func WithGzipClient() connect.ClientOption {
32+
return gzipPoolClient
33+
}

pkg/api/connect/connect.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
func DefaultClientOptions() []connect.ClientOption {
88
return []connect.ClientOption{
99
connect.WithCodec(ProtoCodec),
10+
WithGzipClient(),
1011
}
1112
}
1213

1314
func DefaultHandlerOptions() []connect.HandlerOption {
1415
return []connect.HandlerOption{
1516
connect.WithCodec(ProtoCodec),
17+
WithGzipHandler(),
1618
}
1719
}

0 commit comments

Comments
 (0)