Skip to content

Commit f425a8a

Browse files
authored
[chore][exporter/elasticsearchexporter] modernize Go (#42764)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This is an automated code change done by applying the following command: ``` go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... ``` It updates Go code according to relevant changes in the programming language. Besides style changes, it also improves performance - e.g. by changing something like `[]byte(fmt.Sprintf(..))` to `fmt.Appendf(..)`. <!-- 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 <[email protected]>
1 parent 6bdb040 commit f425a8a

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

exporter/elasticsearchexporter/exporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestExporterLogs(t *testing.T) {
130130
body := pcommon.NewValueMap()
131131
m := body.Map()
132132
s := m.PutEmptySlice("a")
133-
for i := 0; i < 2; i++ {
133+
for i := range 2 {
134134
s.AppendEmpty().SetInt(int64(i))
135135
}
136136
return body
@@ -826,7 +826,7 @@ func TestExporterLogs(t *testing.T) {
826826
cfg.Retry.InitialInterval = 1 * time.Millisecond
827827
cfg.Retry.MaxInterval = 10 * time.Millisecond
828828
})
829-
for i := 0; i < 3; i++ {
829+
for i := range 3 {
830830
logRecord := plog.NewLogRecord()
831831
logRecord.Attributes().PutInt("idx", int64(i))
832832
mustSendLogRecords(t, exporter, logRecord)

exporter/elasticsearchexporter/internal/lru/lruset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func BenchmarkLRUSetCheck(b *testing.B) {
7474
_ = cache.WithLock(func(lock LockedLRUSet) error {
7575
b.ReportAllocs()
7676
b.ResetTimer()
77-
for i := 0; i < b.N; i++ {
77+
for b.Loop() {
7878
lock.CheckAndAdd("a")
7979
}
8080

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,8 @@ func BenchmarkSerializeProfile(b *testing.B) {
234234
}
235235

236236
b.ReportAllocs()
237-
b.ResetTimer()
238237

239-
for i := 0; i < b.N; i++ {
238+
for b.Loop() {
240239
_ = ser.SerializeProfile(profiles.Dictionary(), resource.Resource(), scope.Scope(), profile, pushData)
241240
}
242241
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func BenchmarkTransform(b *testing.B) {
8484
b.ReportAllocs()
8585
b.ResetTimer()
8686

87-
for i := 0; i < b.N; i++ {
87+
for b.Loop() {
8888
_, _ = Transform(dic, rp.Resource(), sp.Scope(), p)
8989
}
9090
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func newUnixTime64(t uint64) unixTime64 {
2424
func (t unixTime64) MarshalJSON() ([]byte, error) {
2525
// Nanoseconds, ES does not support 'epoch_nanoseconds' so
2626
// we have to pass it a value formatted as 'strict_date_optional_time_nanos'.
27-
out := []byte(fmt.Sprintf("%q",
28-
time.Unix(0, int64(t)).UTC().Format(time.RFC3339Nano)))
27+
out := fmt.Appendf(nil, "%q",
28+
time.Unix(0, int64(t)).UTC().Format(time.RFC3339Nano))
2929
return out, nil
3030
}
3131

exporter/elasticsearchexporter/model_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func TestEncodeSpan_Events(t *testing.T) {
342342
t.Parallel()
343343

344344
span := ptrace.NewSpan()
345-
for i := 0; i < 4; i++ {
345+
for i := range 4 {
346346
event := span.Events().AppendEmpty()
347347
event.SetName(fmt.Sprintf("event_%d", i))
348348
}

exporter/elasticsearchexporter/partitioner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func BenchmarkGetKey(b *testing.B) {
7070
})
7171

7272
b.ReportAllocs()
73-
b.ResetTimer()
74-
for i := 0; i < b.N; i++ {
73+
74+
for b.Loop() {
7575
_ = p.GetKey(ctx, nil)
7676
}
7777
}

0 commit comments

Comments
 (0)