Skip to content

Commit 3e48af2

Browse files
committed
Merge branch 'main' into ottl-xml-rename
2 parents 28b03fe + f02bdf9 commit 3e48af2

File tree

39 files changed

+151
-17
lines changed

39 files changed

+151
-17
lines changed

.chloggen/ottl-faster-json.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/ottl
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Improved JSON unmarshaling performance by 10-20% by switching dependencies.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35130]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

connector/countconnector/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/go-logr/stdr v1.2.2 // indirect
3232
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
3333
github.com/gobwas/glob v0.2.3 // indirect
34+
github.com/goccy/go-json v0.10.3 // indirect
3435
github.com/gogo/protobuf v1.3.2 // indirect
3536
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3637
github.com/google/uuid v1.6.0 // indirect

connector/countconnector/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connector/routingconnector/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
github.com/go-logr/stdr v1.2.2 // indirect
2727
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
2828
github.com/gobwas/glob v0.2.3 // indirect
29+
github.com/goccy/go-json v0.10.3 // indirect
2930
github.com/gogo/protobuf v1.3.2 // indirect
3031
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3132
github.com/google/uuid v1.6.0 // indirect

connector/routingconnector/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connector/sumconnector/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
github.com/go-logr/stdr v1.2.2 // indirect
2828
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
2929
github.com/gobwas/glob v0.2.3 // indirect
30+
github.com/goccy/go-json v0.10.3 // indirect
3031
github.com/gogo/protobuf v1.3.2 // indirect
3132
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3233
github.com/google/uuid v1.6.0 // indirect

connector/sumconnector/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/honeycombmarkerexporter/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ require (
3434
github.com/go-logr/stdr v1.2.2 // indirect
3535
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
3636
github.com/gobwas/glob v0.2.3 // indirect
37+
github.com/goccy/go-json v0.10.3 // indirect
3738
github.com/gogo/protobuf v1.3.2 // indirect
3839
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3940
github.com/golang/snappy v0.0.4 // indirect

exporter/honeycombmarkerexporter/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/filter/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/go-logr/stdr v1.2.2 // indirect
3131
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
3232
github.com/gobwas/glob v0.2.3 // indirect
33+
github.com/goccy/go-json v0.10.3 // indirect
3334
github.com/gogo/protobuf v1.3.2 // indirect
3435
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3536
github.com/google/uuid v1.6.0 // indirect

internal/filter/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ottl/expression.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strconv"
1414
"time"
1515

16-
jsoniter "github.com/json-iterator/go"
16+
"github.com/goccy/go-json"
1717
"go.opentelemetry.io/collector/pdata/pcommon"
1818

1919
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon"
@@ -429,22 +429,25 @@ func (g StandardStringLikeGetter[K]) Get(ctx context.Context, tCtx K) (*string,
429429
case []byte:
430430
result = hex.EncodeToString(v)
431431
case pcommon.Map:
432-
result, err = jsoniter.MarshalToString(v.AsRaw())
432+
resultBytes, err := json.Marshal(v.AsRaw())
433433
if err != nil {
434434
return nil, err
435435
}
436+
result = string(resultBytes)
436437
case pcommon.Slice:
437-
result, err = jsoniter.MarshalToString(v.AsRaw())
438+
resultBytes, err := json.Marshal(v.AsRaw())
438439
if err != nil {
439440
return nil, err
440441
}
442+
result = string(resultBytes)
441443
case pcommon.Value:
442444
result = v.AsString()
443445
default:
444-
result, err = jsoniter.MarshalToString(v)
446+
resultBytes, err := json.Marshal(v)
445447
if err != nil {
446448
return nil, TypeError(fmt.Sprintf("unsupported type: %T", v))
447449
}
450+
result = string(resultBytes)
448451
}
449452
return &result, nil
450453
}

pkg/ottl/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ require (
88
github.com/antchfx/xpath v1.3.1
99
github.com/elastic/go-grok v0.3.1
1010
github.com/gobwas/glob v0.2.3
11+
github.com/goccy/go-json v0.10.3
1112
github.com/google/uuid v1.6.0
1213
github.com/iancoleman/strcase v0.3.0
13-
github.com/json-iterator/go v1.1.12
1414
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.109.0
1515
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.109.0
1616
github.com/stretchr/testify v1.9.0
@@ -35,6 +35,7 @@ require (
3535
github.com/gogo/protobuf v1.3.2 // indirect
3636
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3737
github.com/hashicorp/golang-lru v0.5.4 // indirect
38+
github.com/json-iterator/go v1.1.12 // indirect
3839
github.com/magefile/mage v1.15.0 // indirect
3940
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4041
github.com/modern-go/reflect2 v1.0.2 // indirect

pkg/ottl/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ottl/ottlfuncs/func_parse_json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88
"fmt"
99

10-
jsoniter "github.com/json-iterator/go"
10+
"github.com/goccy/go-json"
1111
"go.opentelemetry.io/collector/pdata/pcommon"
1212

1313
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
@@ -47,7 +47,7 @@ func parseJSON[K any](target ottl.StringGetter[K]) ottl.ExprFunc[K] {
4747
return nil, err
4848
}
4949
var parsedValue any
50-
err = jsoniter.UnmarshalFromString(targetVal, &parsedValue)
50+
err = json.Unmarshal([]byte(targetVal), &parsedValue)
5151
if err != nil {
5252
return nil, err
5353
}

pkg/ottl/ottlfuncs/func_parse_json_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,63 @@ func Test_ParseJSON_Error(t *testing.T) {
201201
_, err := exprFunc(context.Background(), nil)
202202
assert.Error(t, err)
203203
}
204+
205+
const benchData = `{
206+
"_id": "667cb0db02f4dfc7648b0f6b",
207+
"index": 0,
208+
"guid": "2e419732-8214-4e36-a158-d3ced0217ab6",
209+
"isActive": true,
210+
"balance": "$1,105.05",
211+
"picture": "http://example.com/1",
212+
"age": 22,
213+
"eyeColor": "blue",
214+
"name": "Vincent Knox",
215+
"gender": "male",
216+
"company": "ANIVET",
217+
"email": "[email protected]",
218+
"phone": "+1 (914) 599-2454",
219+
"address": "483 Gerritsen Avenue, Succasunna, Massachusetts, 7803",
220+
"about": "Elit aliqua qui amet duis esse eiusmod cillum proident quis amet elit tempor dolor exercitation. Eu ut tempor exercitation excepteur est. Lorem ad elit sit reprehenderit quis ad sunt laborum amet veniam commodo sit sunt aliqua. Sint incididunt eu ut est magna amet mollit qui deserunt nostrud labore ad. Nostrud officia proident occaecat et irure ut quis culpa mollit veniam. Laboris labore ea reprehenderit veniam mollit enim et proident ipsum id. In qui sit officia laborum.\r\nIn ad consectetur duis ad nisi proident. Non in officia do mollit amet sint voluptate minim nostrud voluptate elit. Veniam Lorem cillum fugiat adipisicing qui ea commodo irure tempor ipsum pariatur sit voluptate. Eiusmod cillum occaecat excepteur cillum aliquip laboris velit aute proident amet.\r\nIpsum sunt eiusmod do ut voluptate sit anim. Consequat nisi nisi consequat amet excepteur ea ad incididunt pariatur veniam exercitation eu ex in. Incididunt sint tempor pariatur Lorem do. Occaecat laborum ad ad id enim dolor deserunt ipsum amet Lorem Lorem. Cillum veniam labore eu do duis.\r\nCillum dolor eiusmod sit amet commodo voluptate pariatur ex irure eu culpa sunt. Incididunt non exercitation est pariatur est. Incididunt mollit Lorem velit ullamco excepteur esse quis id magna et ullamco labore. Laboris consequat tempor est ea amet enim et nisi amet officia dolore magna veniam. Nostrud officia consectetur ea culpa laborum et ut Lorem laboris.\r\nDeserunt labore ullamco dolor exercitation laboris consectetur nulla cupidatat duis. Occaecat quis velit deserunt culpa nostrud eiusmod elit fugiat nulla duis deserunt Lorem do. Proident anim proident aute amet pariatur et do irure. Ad magna qui elit consequat sit exercitation sit. Magna adipisicing id esse aliqua officia magna. Et veniam aliqua minim reprehenderit in culpa. Adipisicing quis eu do Lorem cupidatat consequat ad aute quis.\r\nIn aliquip ea laborum esse dolor reprehenderit qui sit culpa occaecat. Consectetur Lorem dolore adipisicing amet incididunt. Dolor veniam Lorem nulla ex. Eiusmod amet tempor sit eiusmod do reprehenderit proident sit commodo elit cupidatat.\r\nNulla nulla consequat cillum mollit tempor eiusmod irure deserunt amet et voluptate. Fugiat et veniam culpa eiusmod minim ex pariatur. Eiusmod adipisicing pariatur pariatur adipisicing in consequat cillum ut qui veniam amet incididunt ullamco anim.\r\nDolor nulla laborum tempor adipisicing qui id. Exercitation labore aliqua ut laborum velit cupidatat officia. Est qui dolor sint laboris aliqua ea nulla culpa.\r\nAute reprehenderit nulla elit nisi reprehenderit pariatur officia veniam dolore ea occaecat nostrud sunt fugiat. Cillum consequat labore nostrud veniam nisi ea proident est officia incididunt adipisicing qui sint nisi. Ad enim reprehenderit minim labore minim irure dolor. Voluptate commodo dolor excepteur est tempor dolor sunt esse fugiat ea eu et.\r\nIpsum sit velit deserunt aliqua eu labore ad esse eu. Duis eiusmod non exercitation consequat nulla. Enim elit consectetur pariatur sunt labore sunt dolore non do. Sint consequat aliqua tempor consectetur veniam minim. Veniam eu aute occaecat consectetur dolore ullamco dolore officia.\r\n",
221+
"registered": "2023-06-08T12:29:06 +07:00",
222+
"latitude": -59.802339,
223+
"longitude": -160.473187,
224+
"tags": [
225+
"pariatur",
226+
"anim",
227+
"id",
228+
"duis",
229+
"fugiat",
230+
"qui",
231+
"veniam"
232+
],
233+
"friends": [
234+
{
235+
"id": 0,
236+
"name": "Hester Bruce"
237+
},
238+
{
239+
"id": 1,
240+
"name": "Laurel Mcknight"
241+
},
242+
{
243+
"id": 2,
244+
"name": "Wynn Moses"
245+
}
246+
],
247+
"greeting": "Hello, Vincent Knox! You have 1 unread messages.",
248+
"favoriteFruit": "apple"
249+
}`
250+
251+
func BenchmarkParseJSON(b *testing.B) {
252+
ctx := context.Background()
253+
b.ReportAllocs()
254+
b.ResetTimer()
255+
for i := 0; i < b.N; i++ {
256+
_, err := parseJSON(ottl.StandardStringGetter[any]{
257+
Getter: func(_ context.Context, _ any) (any, error) {
258+
return benchData, nil
259+
},
260+
})(ctx, nil)
261+
require.NoError(b, err)
262+
}
263+
}

pkg/ottl/ottlfuncs/func_remove_xml.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func createRemoveXMLFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments
3333
return removeXML(args.Target, args.XPath), nil
3434
}
3535

36-
// removeXML returns a `pcommon.String` that is a result of renaming the target XML or s
36+
// removeXML returns a `pcommon.String` that is a result of removing all matching nodes from the target XML.
37+
// This currently supports removal of elements, attributes, text values, comments, and CharData.
3738
func removeXML[K any](target ottl.StringGetter[K], xPath string) ottl.ExprFunc[K] {
3839
return func(ctx context.Context, tCtx K) (any, error) {
3940
targetVal, err := target.Get(ctx, tCtx)

processor/attributesprocessor/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ require (
3232
github.com/go-logr/stdr v1.2.2 // indirect
3333
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
3434
github.com/gobwas/glob v0.2.3 // indirect
35+
github.com/goccy/go-json v0.10.3 // indirect
3536
github.com/gogo/protobuf v1.3.2 // indirect
3637
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3738
github.com/google/uuid v1.6.0 // indirect

processor/attributesprocessor/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/filterprocessor/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/go-logr/stdr v1.2.2 // indirect
3737
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
3838
github.com/gobwas/glob v0.2.3 // indirect
39+
github.com/goccy/go-json v0.10.3 // indirect
3940
github.com/gogo/protobuf v1.3.2 // indirect
4041
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4142
github.com/google/uuid v1.6.0 // indirect

processor/filterprocessor/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/routingprocessor/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require (
3939
github.com/go-logr/stdr v1.2.2 // indirect
4040
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
4141
github.com/gobwas/glob v0.2.3 // indirect
42+
github.com/goccy/go-json v0.10.3 // indirect
4243
github.com/gogo/protobuf v1.3.2 // indirect
4344
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4445
github.com/golang/snappy v0.0.4 // indirect

processor/routingprocessor/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/spanprocessor/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/go-logr/stdr v1.2.2 // indirect
3131
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
3232
github.com/gobwas/glob v0.2.3 // indirect
33+
github.com/goccy/go-json v0.10.3 // indirect
3334
github.com/gogo/protobuf v1.3.2 // indirect
3435
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3536
github.com/google/uuid v1.6.0 // indirect

0 commit comments

Comments
 (0)