Skip to content

Commit 8937988

Browse files
committed
upgrade elasticsearchexporter
1 parent 52dc60c commit 8937988

File tree

7 files changed

+266
-188
lines changed

7 files changed

+266
-188
lines changed

exporter/elasticsearchexporter/exporter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ func (e *elasticsearchExporter) pushProfilesData(ctx context.Context, pd pprofil
505505
// the specified mapping mode.
506506
scopeMappingModeSessions := mappingModeSessions{indexers: &e.bulkIndexers.modes}
507507
defer scopeMappingModeSessions.End()
508+
dic := pd.ProfilesDictionary()
508509

509510
var errs []error
510511
for _, rp := range pd.ResourceProfiles().All() {
@@ -526,7 +527,7 @@ func (e *elasticsearchExporter) pushProfilesData(ctx context.Context, pd pprofil
526527
scopeSchemaURL: sp.SchemaUrl(),
527528
}
528529
if err := e.pushProfileRecord(
529-
ctx, encoder, ec, profile, defaultSession, eventsSession,
530+
ctx, encoder, ec, dic, profile, defaultSession, eventsSession,
530531
stackTracesSession, stackFramesSession, executablesSession,
531532
); err != nil {
532533
if cerr := ctx.Err(); cerr != nil {
@@ -557,10 +558,11 @@ func (e *elasticsearchExporter) pushProfileRecord(
557558
ctx context.Context,
558559
encoder documentEncoder,
559560
ec encodingContext,
561+
dic pprofile.ProfilesDictionary,
560562
profile pprofile.Profile,
561563
defaultSession, eventsSession, stackTracesSession, stackFramesSession, executablesSession bulkIndexerSession,
562564
) error {
563-
return encoder.encodeProfile(ec, profile, func(buf *bytes.Buffer, docID, index string) error {
565+
return encoder.encodeProfile(ec, dic, profile, func(buf *bytes.Buffer, docID, index string) error {
564566
switch index {
565567
case otelserializer.StackTraceIndex:
566568
return stackTracesSession.Add(ctx, index, docID, "", buf, nil, docappender.ActionCreate)

exporter/elasticsearchexporter/internal/serializer/otelserializer/profile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
)
2727

2828
// SerializeProfile serializes a profile and calls the `pushData` callback for each generated document.
29-
func (s *Serializer) SerializeProfile(resource pcommon.Resource, scope pcommon.InstrumentationScope, profile pprofile.Profile, pushData func(*bytes.Buffer, string, string) error) error {
29+
func (s *Serializer) SerializeProfile(dic pprofile.ProfilesDictionary, resource pcommon.Resource, scope pcommon.InstrumentationScope, profile pprofile.Profile, pushData func(*bytes.Buffer, string, string) error) error {
3030
err := s.createLRUs()
3131
if err != nil {
3232
return err
@@ -40,7 +40,7 @@ func (s *Serializer) SerializeProfile(resource pcommon.Resource, scope pcommon.I
4040
return pushData(c, id, index)
4141
}
4242

43-
data, err := serializeprofiles.Transform(resource, scope, profile)
43+
data, err := serializeprofiles.Transform(dic, resource, scope, profile)
4444
if err != nil {
4545
return err
4646
}

exporter/elasticsearchexporter/internal/serializer/otelserializer/profile_test.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,50 @@ func basicProfiles() pprofiletest.Profiles {
6666
func TestSerializeProfile(t *testing.T) {
6767
tests := []struct {
6868
name string
69+
buildDictionary func() pprofile.ProfilesDictionary
6970
profileCustomizer func(resource pcommon.Resource, scope pcommon.InstrumentationScope, record pprofile.Profile)
7071
wantErr bool
7172
expected []map[string]any
7273
}{
7374
{
7475
name: "with a simple sample",
75-
profileCustomizer: func(_ pcommon.Resource, _ pcommon.InstrumentationScope, profile pprofile.Profile) {
76-
profile.StringTable().Append("samples", "count", "cpu", "nanoseconds")
77-
st := profile.SampleType().AppendEmpty()
78-
st.SetTypeStrindex(0)
79-
st.SetUnitStrindex(1)
80-
pt := profile.PeriodType()
81-
pt.SetTypeStrindex(2)
82-
pt.SetUnitStrindex(3)
76+
buildDictionary: func() pprofile.ProfilesDictionary {
77+
dic := pprofile.NewProfilesDictionary()
78+
dic.StringTable().Append("samples", "count", "cpu", "nanoseconds")
8379

84-
a := profile.AttributeTable().AppendEmpty()
80+
a := dic.AttributeTable().AppendEmpty()
8581
a.SetKey("process.executable.build_id.htlhash")
8682
a.Value().SetStr("600DCAFE4A110000F2BF38C493F5FB92")
87-
a = profile.AttributeTable().AppendEmpty()
83+
a = dic.AttributeTable().AppendEmpty()
8884
a.SetKey("profile.frame.type")
8985
a.Value().SetStr("native")
90-
a = profile.AttributeTable().AppendEmpty()
86+
a = dic.AttributeTable().AppendEmpty()
9187
a.SetKey("host.id")
9288
a.Value().SetStr("localhost")
9389

94-
profile.AttributeIndices().Append(2)
95-
96-
sample := profile.Sample().AppendEmpty()
97-
sample.TimestampsUnixNano().Append(0)
98-
sample.SetLocationsLength(1)
99-
100-
m := profile.MappingTable().AppendEmpty()
90+
m := dic.MappingTable().AppendEmpty()
10191
m.AttributeIndices().Append(0)
10292

103-
l := profile.LocationTable().AppendEmpty()
93+
l := dic.LocationTable().AppendEmpty()
10494
l.SetMappingIndex(0)
10595
l.SetAddress(111)
10696
l.AttributeIndices().Append(1)
97+
98+
return dic
99+
},
100+
profileCustomizer: func(_ pcommon.Resource, _ pcommon.InstrumentationScope, profile pprofile.Profile) {
101+
st := profile.SampleType().AppendEmpty()
102+
st.SetTypeStrindex(0)
103+
st.SetUnitStrindex(1)
104+
pt := profile.PeriodType()
105+
pt.SetTypeStrindex(2)
106+
pt.SetUnitStrindex(3)
107+
108+
profile.AttributeIndices().Append(2)
109+
110+
sample := profile.Sample().AppendEmpty()
111+
sample.TimestampsUnixNano().Append(0)
112+
sample.SetLocationsLength(1)
107113
},
108114
wantErr: false,
109115
expected: []map[string]any{
@@ -152,6 +158,7 @@ func TestSerializeProfile(t *testing.T) {
152158
}
153159
for _, tt := range tests {
154160
t.Run(tt.name, func(t *testing.T) {
161+
dic := tt.buildDictionary()
155162
profiles := pprofile.NewProfiles()
156163
resource := profiles.ResourceProfiles().AppendEmpty()
157164
scope := resource.ScopeProfiles().AppendEmpty()
@@ -162,7 +169,7 @@ func TestSerializeProfile(t *testing.T) {
162169
buf := []*bytes.Buffer{}
163170
ser, err := New()
164171
require.NoError(t, err)
165-
err = ser.SerializeProfile(resource.Resource(), scope.Scope(), profile, func(b *bytes.Buffer, _ string, _ string) error {
172+
err = ser.SerializeProfile(dic, resource.Resource(), scope.Scope(), profile, func(b *bytes.Buffer, _ string, _ string) error {
166173
buf = append(buf, b)
167174
return nil
168175
})
@@ -215,6 +222,6 @@ func BenchmarkSerializeProfile(b *testing.B) {
215222
b.ResetTimer()
216223

217224
for i := 0; i < b.N; i++ {
218-
_ = ser.SerializeProfile(resource.Resource(), scope.Scope(), profile, pushData)
225+
_ = ser.SerializeProfile(profiles.ProfilesDictionary(), resource.Resource(), scope.Scope(), profile, pushData)
219226
}
220227
}

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/benchmark_test.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,56 @@ import (
1212
func BenchmarkTransform(b *testing.B) {
1313
for _, bb := range []struct {
1414
name string
15+
buildDictionary func() pprofile.ProfilesDictionary
1516
buildResourceProfiles func() pprofile.ResourceProfiles
1617
}{
1718
{
1819
name: "with a basic recorded sample",
19-
buildResourceProfiles: func() pprofile.ResourceProfiles {
20-
rp := pprofile.NewResourceProfiles()
21-
22-
sp := rp.ScopeProfiles().AppendEmpty()
23-
p := sp.Profiles().AppendEmpty()
24-
25-
a := p.AttributeTable().AppendEmpty()
20+
buildDictionary: func() pprofile.ProfilesDictionary {
21+
dic := pprofile.NewProfilesDictionary()
22+
a := dic.AttributeTable().AppendEmpty()
2623
a.SetKey("profile.frame.type")
2724
a.Value().SetStr("native")
28-
a = p.AttributeTable().AppendEmpty()
25+
a = dic.AttributeTable().AppendEmpty()
2926
a.SetKey("process.executable.build_id.htlhash")
3027
a.Value().SetStr(buildIDEncoded)
31-
a = p.AttributeTable().AppendEmpty()
28+
a = dic.AttributeTable().AppendEmpty()
3229
a.SetKey("process.executable.build_id.htlhash")
3330
a.Value().SetStr(buildID2Encoded)
3431

35-
p.StringTable().Append("firefox", "libc.so", "samples", "count", "cpu", "nanoseconds")
36-
st := p.SampleType().AppendEmpty()
37-
st.SetTypeStrindex(2)
38-
st.SetUnitStrindex(3)
39-
pt := p.PeriodType()
40-
pt.SetTypeStrindex(4)
41-
pt.SetUnitStrindex(5)
32+
dic.StringTable().Append("firefox", "libc.so", "samples", "count", "cpu", "nanoseconds")
4233

43-
m := p.MappingTable().AppendEmpty()
34+
m := dic.MappingTable().AppendEmpty()
4435
m.AttributeIndices().Append(1)
4536
m.SetFilenameStrindex(0)
46-
m = p.MappingTable().AppendEmpty()
37+
m = dic.MappingTable().AppendEmpty()
4738
m.AttributeIndices().Append(2)
4839
m.SetFilenameStrindex(1)
4940

50-
l := p.LocationTable().AppendEmpty()
41+
l := dic.LocationTable().AppendEmpty()
5142
l.SetAddress(address)
5243
l.AttributeIndices().Append(0)
5344
l.SetMappingIndex(0)
54-
l = p.LocationTable().AppendEmpty()
45+
l = dic.LocationTable().AppendEmpty()
5546
l.SetAddress(address2)
5647
l.AttributeIndices().Append(0)
5748
l.SetMappingIndex(1)
5849

50+
return dic
51+
},
52+
buildResourceProfiles: func() pprofile.ResourceProfiles {
53+
rp := pprofile.NewResourceProfiles()
54+
55+
sp := rp.ScopeProfiles().AppendEmpty()
56+
p := sp.Profiles().AppendEmpty()
57+
58+
st := p.SampleType().AppendEmpty()
59+
st.SetTypeStrindex(2)
60+
st.SetUnitStrindex(3)
61+
pt := p.PeriodType()
62+
pt.SetTypeStrindex(4)
63+
pt.SetUnitStrindex(5)
64+
5965
s := p.Sample().AppendEmpty()
6066
s.TimestampsUnixNano().Append(42)
6167
s.Value().Append(1)
@@ -67,6 +73,7 @@ func BenchmarkTransform(b *testing.B) {
6773
},
6874
} {
6975
b.Run(bb.name, func(b *testing.B) {
76+
dic := bb.buildDictionary()
7077
rp := bb.buildResourceProfiles()
7178
sp := rp.ScopeProfiles().At(0)
7279
p := sp.Profiles().At(0)
@@ -75,7 +82,7 @@ func BenchmarkTransform(b *testing.B) {
7582
b.ResetTimer()
7683

7784
for i := 0; i < b.N; i++ {
78-
_, _ = Transform(rp.Resource(), sp.Scope(), p)
85+
_, _ = Transform(dic, rp.Resource(), sp.Scope(), p)
7986
}
8087
})
8188
}

0 commit comments

Comments
 (0)