Skip to content

Commit

Permalink
Merge branch 'main' into renovate/github.com-prometheus-common-0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro authored Aug 31, 2024
2 parents 0e711e7 + 9a2921a commit 5016425
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/es-index-cleaner/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# es-index-cleaner
# jaeger-es-index-cleaner

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

```
Expand Down
18 changes: 10 additions & 8 deletions pkg/gogocodec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
gogoproto "github.com/gogo/protobuf/proto"
"google.golang.org/grpc/encoding"
"google.golang.org/grpc/encoding/proto"
"google.golang.org/grpc/mem"
)

const (
jaegerProtoGenPkgPath = "github.com/jaegertracing/jaeger/proto-gen"
jaegerModelPkgPath = "github.com/jaegertracing/jaeger/model"
)

var defaultCodec encoding.Codec
var defaultCodec encoding.CodecV2

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

func init() {
defaultCodec = encoding.GetCodec(proto.Name)
defaultCodec = encoding.GetCodecV2(proto.Name)
defaultCodec.Name() // ensure it's not nil
encoding.RegisterCodec(newCodec())
encoding.RegisterCodecV2(newCodec())
}

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

var _ encoding.Codec = (*gogoCodec)(nil)
var _ encoding.CodecV2 = (*gogoCodec)(nil)

func newCodec() *gogoCodec {
return &gogoCodec{}
Expand All @@ -55,23 +56,24 @@ func (*gogoCodec) Name() string {
}

// Marshal implements encoding.Codec
func (*gogoCodec) Marshal(v any) ([]byte, error) {
func (*gogoCodec) Marshal(v any) (mem.BufferSlice, error) {
t := reflect.TypeOf(v)
elem := t.Elem()
// use gogo proto only for Jaeger types
if useGogo(elem) {
return gogoproto.Marshal(v.(gogoproto.Message))
bytes, err := gogoproto.Marshal(v.(gogoproto.Message))
return mem.BufferSlice{mem.SliceBuffer(bytes)}, err
}
return defaultCodec.Marshal(v)
}

// Unmarshal implements encoding.Codec
func (*gogoCodec) Unmarshal(data []byte, v any) error {
func (*gogoCodec) Unmarshal(data mem.BufferSlice, v any) error {
t := reflect.TypeOf(v)
elem := t.Elem() // only for collections
// use gogo proto only for Jaeger types
if useGogo(elem) {
return gogoproto.Unmarshal(data, v.(gogoproto.Message))
return gogoproto.Unmarshal(data.Materialize(), v.(gogoproto.Message))
}
return defaultCodec.Unmarshal(data, v)
}
Expand Down
34 changes: 32 additions & 2 deletions pkg/gogocodec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
package gogocodec

import (
"os"
"reflect"
"testing"

"github.com/gogo/protobuf/jsonpb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/mem"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -54,14 +57,14 @@ func TestWireCompatibility(t *testing.T) {
require.NoError(t, err)

var goprotoMessage emptypb.Empty
err = proto.Unmarshal(data, &goprotoMessage)
err = proto.Unmarshal(data.Materialize(), &goprotoMessage)
require.NoError(t, err)

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

s2 := &model.Span{}
err = c.Unmarshal(data2, s2)
err = c.Unmarshal(mem.BufferSlice{mem.SliceBuffer(data2)}, s2)
require.NoError(t, err)
assert.Equal(t, s1, s2)
}
Expand All @@ -73,6 +76,33 @@ func TestUseGogo(t *testing.T) {
assert.True(t, useGogo(reflect.TypeOf(span)))
}

func BenchmarkCodecUnmarshal25Spans(b *testing.B) {
const fileName = "../../model/converter/thrift/jaeger/fixtures/domain_01.json"
jsonFile, err := os.Open(fileName)
require.NoError(b, err, "Failed to open json fixture file %s", fileName)
var trace model.Trace
require.NoError(b, jsonpb.Unmarshal(jsonFile, &trace), fileName)
require.NotEmpty(b, trace.Spans)
spans := make([]*model.Span, 25)
for i := 0; i < len(spans); i++ {
spans[i] = trace.Spans[0]
}
trace.Spans = spans
c := newCodec()
bytes, err := c.Marshal(&trace)
require.NoError(b, err)

b.ResetTimer()

for i := 0; i < b.N; i++ {
var trace model.Trace
err := c.Unmarshal(bytes, &trace)
if err != nil {
b.Fatal(err)
}
}
}

func TestMain(m *testing.M) {
testutils.VerifyGoLeaks(m)
}

0 comments on commit 5016425

Please sign in to comment.