Skip to content

[translator/azurelogs] Improve performance #39340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/azure-logs-improve-performance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Improve performance of azure logs translator.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [39340]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
9 changes: 6 additions & 3 deletions pkg/translator/azurelogs/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"go.uber.org/zap"
)

func createBuf(b *testing.B, nRecords int) []byte {
// newBuf creates an azure resource log with
// as many records as defined in nRecords
func newBuf(b *testing.B, nRecords int) []byte {
rec := azureLogRecord{
Time: "2024-04-24T12:06:12.0000000Z",
ResourceID: "/test",
Expand Down Expand Up @@ -56,11 +58,12 @@ func BenchmarkUnmarshalLogs(b *testing.B) {
Logger: zap.NewNop(),
}
for name, test := range tests {
buf := createBuf(b, test.nRecords)
buf := newBuf(b, test.nRecords)
b.Run(name, func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = u.UnmarshalLogs(buf)
_, err := u.UnmarshalLogs(buf)
require.NoError(b, err)
}
})
}
Expand Down
107 changes: 0 additions & 107 deletions pkg/translator/azurelogs/complex_conversions.go

This file was deleted.

76 changes: 0 additions & 76 deletions pkg/translator/azurelogs/complex_conversions_test.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/translator/azurelogs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
go.opentelemetry.io/collector/semconv v0.123.1-0.20250411074447-4fb7c24ebecc
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
)

require (
Expand Down
2 changes: 0 additions & 2 deletions pkg/translator/azurelogs/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 24 additions & 27 deletions pkg/translator/azurelogs/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
package azurelogs // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs"

import (
"fmt"
"strconv"
"strings"
)

func normalizeValue(key string, val any) any {
switch key {
case
"http.request.body.size",
"http.request.size",
"http.response.body.size",
"http.response.size",
"http.response.status_code",
"server.port":
return toInt(val)
case "http.server.request.duration":
return toFloat(val)
case "network.protocol.name":
return toLower(val)
func tryParseFloat64(value any) (float64, bool) {
switch v := value.(type) {
case float32:
return float64(v), true
case float64:
return v, true
case int:
return float64(v), true
case int32:
return float64(v), true
case int64:
return float64(v), true
case string:
f, err := strconv.ParseFloat(v, 64)
return f, err == nil
default:
return 0, false
}
return val
}

func toLower(value any) any {
switch v := value.(type) {
case string:
return strings.ToLower(v)
default:
return strings.ToLower(fmt.Sprint(value))
if s, ok := value.(string); ok {
return strings.ToLower(s)
}
return value
}

func toFloat(value any) any {
Expand All @@ -49,8 +48,7 @@ func toFloat(value any) any {
case int64:
return float64(v)
case string:
f, err := strconv.ParseFloat(v, 64)
if err == nil {
if f, err := strconv.ParseFloat(v, 64); err == nil {
return f
}
}
Expand All @@ -62,12 +60,11 @@ func toInt(value any) any {
case int:
return int64(v)
case int32:
return int64(int(v))
return int64(v)
case int64:
return value.(int64)
return v
case string:
i, err := strconv.ParseInt(v, 10, 64)
if err == nil {
if i, err := strconv.ParseInt(v, 10, 64); err == nil {
return i
}
}
Expand Down
Loading