Skip to content

Commit 01f5883

Browse files
renovate-botyurishkuro
authored andcommitted
Update grpc to v1.66.0 and switch to CodecV2 (jaegertracing#5900)
gRPC v1.66.0 introduced CodecV2 that supports buffer pooling. The old V1 codecs no longer work (just the upgrade itself was causing panic, see grpc/grpc-go@cfd14ba#r145974307) This PR contains the following updates: * Upgrade `pkg/gogocodec/codec.go` to implement CodecV2 API. * Translate `mem.BufferSlice` into `[]byte` as needed (introduces a very small performance hit and increase in allocations) | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google.golang.org/grpc](https://togithub.com/grpc/grpc-go) | `v1.65.0` -> `v1.66.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/google.golang.org%2fgrpc/v1.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/google.golang.org%2fgrpc/v1.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/google.golang.org%2fgrpc/v1.65.0/v1.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/google.golang.org%2fgrpc/v1.65.0/v1.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | ## Performance differences Before ``` $ go test -benchmem -run=^$ -bench ^BenchmarkCodec github.com/jaegertracing/jaeger/pkg/gogocodec goos: darwin goarch: arm64 pkg: github.com/jaegertracing/jaeger/pkg/gogocodec cpu: Apple M1 Pro BenchmarkCodecUnmarshal25Spans-10 30015 39020 ns/op 108616 B/op 1082 allocs/op ``` After ``` goos: darwin goarch: arm64 pkg: github.com/jaegertracing/jaeger/pkg/gogocodec cpu: Apple M1 Pro BenchmarkCodecUnmarshal25Spans-10 29352 39752 ns/op 119496 B/op 1083 allocs/op ``` --- ### Release Notes <details> <summary>grpc/grpc-go (google.golang.org/grpc)</summary> ### [`v1.66.0`](https://togithub.com/grpc/grpc-go/releases/tag/v1.66.0): Release 1.66.0 [Compare Source](https://togithub.com/grpc/grpc-go/compare/v1.65.0...v1.66.0) ### New Features - metadata: stabilize `ValueFromIncomingContext` ([#&#8203;7368](https://togithub.com/grpc/grpc-go/issues/7368)) - Special Thanks: [@&#8203;KarthikReddyPuli](https://togithub.com/KarthikReddyPuli) - client: stabilize the `WaitForStateChange` and `GetState` methods, which were previously experimental. ([#&#8203;7425](https://togithub.com/grpc/grpc-go/issues/7425)) - xds: Implement ADS flow control mechanism ([#&#8203;7458](https://togithub.com/grpc/grpc-go/issues/7458)) - See [https://github.com/grpc/grpc/issues/34099](https://togithub.com/grpc/grpc/issues/34099) for context. - balancer/rls: Add metrics for data cache and picker internals ([#&#8203;7484](https://togithub.com/grpc/grpc-go/issues/7484), [#&#8203;7495](https://togithub.com/grpc/grpc-go/issues/7495)) - xds: LRS load reports now include the `total_issued_requests` field. ([#&#8203;7544](https://togithub.com/grpc/grpc-go/issues/7544)) ### Bug Fixes - grpc: Clients now return status code INTERNAL instead of UNIMPLEMENTED when the server uses an unsupported compressor. This is consistent with the [gRPC compression spec](https://togithub.com/grpc/grpc/blob/master/doc/compression.md#compression-method-asymmetry-between-peers). ([#&#8203;7461](https://togithub.com/grpc/grpc-go/issues/7461)) - Special Thanks: [@&#8203;Gayathri625](https://togithub.com/Gayathri625) - transport: Fix a bug which could result in writes busy looping when the underlying `conn.Write` returns errors ([#&#8203;7394](https://togithub.com/grpc/grpc-go/issues/7394)) - Special Thanks: [@&#8203;veshij](https://togithub.com/veshij) - client: fix race that could lead to orphaned connections and associated resources. ([#&#8203;7390](https://togithub.com/grpc/grpc-go/issues/7390)) - xds: use locality from the connected address for load reporting with pick_first ([#&#8203;7378](https://togithub.com/grpc/grpc-go/issues/7378)) - without this fix, if a priority contains multiple localities with pick_first, load was reported for the wrong locality - client: prevent hanging during ClientConn.Close() when the network is unreachable ([#&#8203;7540](https://togithub.com/grpc/grpc-go/issues/7540)) ### Performance Improvements - transport: double buffering is avoided when using an http connect proxy and the target server waits for client to send the first message. ([#&#8203;7424](https://togithub.com/grpc/grpc-go/issues/7424)) - codec: Implement a new `Codec` which uses buffer recycling for encoded message ([#&#8203;7356](https://togithub.com/grpc/grpc-go/issues/7356)) - introduce a `mem` package to facilitate buffer reuse ([#&#8203;7432](https://togithub.com/grpc/grpc-go/issues/7432)) - Special Thanks: [@&#8203;PapaCharlie](https://togithub.com/PapaCharlie) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/jaegertracing/jaeger). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41Ni4wIiwidXBkYXRlZEluVmVyIjoiMzguNTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiY2hhbmdlbG9nOmRlcGVuZGVuY2llcyJdfQ==--> --------- Signed-off-by: Mend Renovate <[email protected]> Signed-off-by: Yuri Shkuro <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]> Signed-off-by: Mahad Zaryab <[email protected]>
1 parent 3e987f5 commit 01f5883

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

cmd/es-index-cleaner/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# es-index-cleaner
1+
# jaeger-es-index-cleaner
22

33
It is common to only keep observability data for a limited time.
44
However, Elasticsearch does no support expiring of old data via TTL.
5-
To help with this task, `es-index-cleaner` can be used to purge
5+
To help with this task, `jaeger-es-index-cleaner` can be used to purge
66
old Jaeger indices. For example, to delete indixes older than 14 days:
77

88
```

pkg/gogocodec/codec.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111
gogoproto "github.com/gogo/protobuf/proto"
1212
"google.golang.org/grpc/encoding"
1313
"google.golang.org/grpc/encoding/proto"
14+
"google.golang.org/grpc/mem"
1415
)
1516

1617
const (
1718
jaegerProtoGenPkgPath = "github.com/jaegertracing/jaeger/proto-gen"
1819
jaegerModelPkgPath = "github.com/jaegertracing/jaeger/model"
1920
)
2021

21-
var defaultCodec encoding.Codec
22+
var defaultCodec encoding.CodecV2
2223

2324
// CustomType is an interface that Gogo expects custom types to implement.
2425
// https://github.com/gogo/protobuf/blob/master/custom_types.md
@@ -34,16 +35,16 @@ type CustomType interface {
3435
}
3536

3637
func init() {
37-
defaultCodec = encoding.GetCodec(proto.Name)
38+
defaultCodec = encoding.GetCodecV2(proto.Name)
3839
defaultCodec.Name() // ensure it's not nil
39-
encoding.RegisterCodec(newCodec())
40+
encoding.RegisterCodecV2(newCodec())
4041
}
4142

4243
// gogoCodec forces the use of gogo proto marshalling/unmarshalling for
4344
// Jaeger proto types (package jaeger/gen-proto).
4445
type gogoCodec struct{}
4546

46-
var _ encoding.Codec = (*gogoCodec)(nil)
47+
var _ encoding.CodecV2 = (*gogoCodec)(nil)
4748

4849
func newCodec() *gogoCodec {
4950
return &gogoCodec{}
@@ -55,23 +56,24 @@ func (*gogoCodec) Name() string {
5556
}
5657

5758
// Marshal implements encoding.Codec
58-
func (*gogoCodec) Marshal(v any) ([]byte, error) {
59+
func (*gogoCodec) Marshal(v any) (mem.BufferSlice, error) {
5960
t := reflect.TypeOf(v)
6061
elem := t.Elem()
6162
// use gogo proto only for Jaeger types
6263
if useGogo(elem) {
63-
return gogoproto.Marshal(v.(gogoproto.Message))
64+
bytes, err := gogoproto.Marshal(v.(gogoproto.Message))
65+
return mem.BufferSlice{mem.SliceBuffer(bytes)}, err
6466
}
6567
return defaultCodec.Marshal(v)
6668
}
6769

6870
// Unmarshal implements encoding.Codec
69-
func (*gogoCodec) Unmarshal(data []byte, v any) error {
71+
func (*gogoCodec) Unmarshal(data mem.BufferSlice, v any) error {
7072
t := reflect.TypeOf(v)
7173
elem := t.Elem() // only for collections
7274
// use gogo proto only for Jaeger types
7375
if useGogo(elem) {
74-
return gogoproto.Unmarshal(data, v.(gogoproto.Message))
76+
return gogoproto.Unmarshal(data.Materialize(), v.(gogoproto.Message))
7577
}
7678
return defaultCodec.Unmarshal(data, v)
7779
}

pkg/gogocodec/codec_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
package gogocodec
55

66
import (
7+
"os"
78
"reflect"
89
"testing"
910

11+
"github.com/gogo/protobuf/jsonpb"
1012
"github.com/stretchr/testify/assert"
1113
"github.com/stretchr/testify/require"
14+
"google.golang.org/grpc/mem"
1215
"google.golang.org/protobuf/proto"
1316
"google.golang.org/protobuf/types/known/emptypb"
1417
"google.golang.org/protobuf/types/known/timestamppb"
@@ -54,14 +57,14 @@ func TestWireCompatibility(t *testing.T) {
5457
require.NoError(t, err)
5558

5659
var goprotoMessage emptypb.Empty
57-
err = proto.Unmarshal(data, &goprotoMessage)
60+
err = proto.Unmarshal(data.Materialize(), &goprotoMessage)
5861
require.NoError(t, err)
5962

6063
data2, err := proto.Marshal(&goprotoMessage)
6164
require.NoError(t, err)
6265

6366
s2 := &model.Span{}
64-
err = c.Unmarshal(data2, s2)
67+
err = c.Unmarshal(mem.BufferSlice{mem.SliceBuffer(data2)}, s2)
6568
require.NoError(t, err)
6669
assert.Equal(t, s1, s2)
6770
}
@@ -73,6 +76,33 @@ func TestUseGogo(t *testing.T) {
7376
assert.True(t, useGogo(reflect.TypeOf(span)))
7477
}
7578

79+
func BenchmarkCodecUnmarshal25Spans(b *testing.B) {
80+
const fileName = "../../model/converter/thrift/jaeger/fixtures/domain_01.json"
81+
jsonFile, err := os.Open(fileName)
82+
require.NoError(b, err, "Failed to open json fixture file %s", fileName)
83+
var trace model.Trace
84+
require.NoError(b, jsonpb.Unmarshal(jsonFile, &trace), fileName)
85+
require.NotEmpty(b, trace.Spans)
86+
spans := make([]*model.Span, 25)
87+
for i := 0; i < len(spans); i++ {
88+
spans[i] = trace.Spans[0]
89+
}
90+
trace.Spans = spans
91+
c := newCodec()
92+
bytes, err := c.Marshal(&trace)
93+
require.NoError(b, err)
94+
95+
b.ResetTimer()
96+
97+
for i := 0; i < b.N; i++ {
98+
var trace model.Trace
99+
err := c.Unmarshal(bytes, &trace)
100+
if err != nil {
101+
b.Fatal(err)
102+
}
103+
}
104+
}
105+
76106
func TestMain(m *testing.M) {
77107
testutils.VerifyGoLeaks(m)
78108
}

0 commit comments

Comments
 (0)