Skip to content
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

libbeat: optimize asset data decoding #42180

Merged
merged 1 commit into from
Jan 2, 2025
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
6 changes: 3 additions & 3 deletions libbeat/asset/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
"bytes"
"compress/zlib"
"encoding/base64"
"io/ioutil"
"sort"

"github.com/elastic/elastic-agent-libs/iobuf"
)

// FieldsRegistry contains a list of fields.yml files
Expand Down Expand Up @@ -106,7 +107,6 @@ func EncodeData(data string) (string, error) {

// DecodeData base64 decodes the data and uncompresses it
func DecodeData(data string) ([]byte, error) {

decoded, err := base64.StdEncoding.DecodeString(data)
if err != nil {
return nil, err
Expand All @@ -119,5 +119,5 @@ func DecodeData(data string) ([]byte, error) {
}
defer r.Close()

return ioutil.ReadAll(r)
return iobuf.ReadAll(r)
}
45 changes: 45 additions & 0 deletions x-pack/filebeat/fbreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/receiver"
Expand Down Expand Up @@ -89,3 +90,47 @@ found:
err = r.Shutdown(context.Background())
assert.NoError(t, err, "Error shutting down filebeatreceiver")
}

func BenchmarkFactory(b *testing.B) {
tmpDir := b.TempDir()

cfg := &Config{
Beatconfig: map[string]interface{}{
"filebeat": map[string]interface{}{
"inputs": []map[string]interface{}{
{
"type": "benchmark",
"enabled": true,
"message": "test",
"count": 10,
},
},
},
"output": map[string]interface{}{
"otelconsumer": map[string]interface{}{},
},
"logging": map[string]interface{}{
"level": "debug",
"selectors": []string{
"*",
},
},
"path.home": tmpDir,
},
}

var zapLogs bytes.Buffer
core := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(&zapLogs),
zapcore.DebugLevel)

receiverSettings := receiver.Settings{}
receiverSettings.Logger = zap.New(core)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := NewFactory().CreateLogsReceiver(context.Background(), receiverSettings, cfg, nil)
require.NoError(b, err)
}
}
Loading