Skip to content

Commit 33715eb

Browse files
authored
[chore][exporter/elasticsearch] Replace json.MarshalIndent with json.… (#46494)
…Marshal <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Comparing current main (on commit b0c41a1) with this change: ``` goos: linux goarch: amd64 pkg: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles cpu: 12th Gen Intel(R) Core(TM) i7-12700H │ main-b0c41a15619a2da71ef89844966be6a4e3932891.txt │ new-36e8f74f1f4ae830272229ae13f7c8f9a4bead57.txt │ │ sec/op │ sec/op vs base │ HostResourceData_MarshalJSON/empty_data_map-20 1377.0n ± 6% 890.6n ± 8% -35.32% (p=0.000 n=10) HostResourceData_MarshalJSON/small_data_map-20 2.332µ ± 2% 1.655µ ± 9% -29.02% (p=0.000 n=10) HostResourceData_MarshalJSON/large_data_map-20 6.378µ ± 9% 4.571µ ± 6% -28.33% (p=0.000 n=10) HostResourceData_MarshalJSON/data_with_empty_values-20 2.023µ ± 4% 1.431µ ± 8% -29.27% (p=0.000 n=10) geomean 1.552µ 1.160µ -25.27% │ main-b0c41a15619a2da71ef89844966be6a4e3932891.txt │ new-36e8f74f1f4ae830272229ae13f7c8f9a4bead57.txt │ │ B/op │ B/op vs base │ HostResourceData_MarshalJSON/empty_data_map-20 841.0 ± 0% 680.0 ± 0% -19.14% (p=0.000 n=10) HostResourceData_MarshalJSON/small_data_map-20 1298.0 ± 0% 1008.0 ± 0% -22.34% (p=0.000 n=10) HostResourceData_MarshalJSON/large_data_map-20 3.240Ki ± 0% 2.486Ki ± 0% -23.27% (p=0.000 n=10) HostResourceData_MarshalJSON/data_with_empty_values-20 1121.0 ± 0% 896.0 ± 0% -20.07% (p=0.000 n=10) geomean 951.4 786.1 -17.37% ¹ all samples are equal │ main-b0c41a15619a2da71ef89844966be6a4e3932891.txt │ new-36e8f74f1f4ae830272229ae13f7c8f9a4bead57.txt │ │ allocs/op │ allocs/op vs base │ HostResourceData_MarshalJSON/empty_data_map-20 14.00 ± 0% 13.00 ± 0% -7.14% (p=0.000 n=10) HostResourceData_MarshalJSON/small_data_map-20 24.00 ± 0% 23.00 ± 0% -4.17% (p=0.000 n=10) HostResourceData_MarshalJSON/large_data_map-20 49.00 ± 0% 48.00 ± 0% -2.04% (p=0.000 n=10) HostResourceData_MarshalJSON/data_with_empty_values-20 21.00 ± 0% 20.00 ± 0% -4.76% (p=0.000 n=10) geomean 16.91 16.29 -3.65% ¹ all samples are equal ``` <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
1 parent 623b03f commit 33715eb

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,74 @@ func BenchmarkTransform(b *testing.B) {
9090
})
9191
}
9292
}
93+
94+
func BenchmarkHostResourceData_MarshalJSON(b *testing.B) {
95+
testCases := []struct {
96+
name string
97+
data HostResourceData
98+
}{
99+
{
100+
name: "empty data map",
101+
data: HostResourceData{
102+
EcsVersion: EcsVersion{V: EcsVersionString},
103+
HostID: "test-host-id-12345",
104+
Data: map[string]string{},
105+
},
106+
},
107+
{
108+
name: "small data map",
109+
data: HostResourceData{
110+
EcsVersion: EcsVersion{V: EcsVersionString},
111+
HostID: "test-host-id-12345",
112+
Data: map[string]string{
113+
"os.type": "Linux",
114+
"os.version": "5.15.0",
115+
"arch": "amd64",
116+
},
117+
},
118+
},
119+
{
120+
name: "large data map",
121+
data: HostResourceData{
122+
EcsVersion: EcsVersion{V: EcsVersionString},
123+
HostID: "test-host-id-12345",
124+
Data: map[string]string{
125+
"os.type": "Linux",
126+
"os.version": "5.15.0",
127+
"arch": "amd64",
128+
"kernel.version": "5.15.0-91-generic",
129+
"hostname": "production-server-01",
130+
"cloud.provider": "AWS",
131+
"cloud.region": "us-east-1",
132+
"cloud.zone": "us-east-1a",
133+
"cloud.instance.id": "i-1234567890abcdef0",
134+
"cloud.instance.type": "m5.xlarge",
135+
},
136+
},
137+
},
138+
{
139+
name: "data with empty values",
140+
data: HostResourceData{
141+
EcsVersion: EcsVersion{V: EcsVersionString},
142+
HostID: "test-host-id-12345",
143+
Data: map[string]string{
144+
"os.type": "Linux",
145+
"os.version": "",
146+
"arch": "amd64",
147+
"hostname": "",
148+
},
149+
},
150+
},
151+
}
152+
153+
for _, tc := range testCases {
154+
b.Run(tc.name, func(b *testing.B) {
155+
b.ReportAllocs()
156+
b.ResetTimer()
157+
158+
for b.Loop() {
159+
_, _ = tc.data.MarshalJSON()
160+
}
161+
})
162+
}
163+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (h HostResourceData) MarshalJSON() ([]byte, error) {
111111
}
112112

113113
// Marshal the combined map into JSON
114-
return json.MarshalIndent(combinedData, "", " ")
114+
return json.Marshal(combinedData)
115115
}
116116

117117
// Script written in Painless that will both create a new document (if DocID does not exist),

0 commit comments

Comments
 (0)