Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: enhancement
summary: Remove unnecessary allocations in hot-path processors (docker metadata, kubernetes metadata, dissect, timestamp)
component: libbeat
pr:
- https://github.com/elastic/beats/pull/49761
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
// initCgroupPaths initializes a new cgroup reader. This enables
// unit testing by allowing us to stub the OS interface.
var initCgroupPaths processors.InitCgroupHandler = func(rootfsMountpoint resolve.Resolver, ignoreRootCgroups bool) (processors.CGReader, error) {
return cgroup.NewReader(rootfsMountpoint, ignoreRootCgroups)

Check failure on line 53 in libbeat/processors/add_docker_metadata/add_docker_metadata.go

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

SA1019: cgroup.NewReader is deprecated: use NewReaderOptions (staticcheck)

Check failure on line 53 in libbeat/processors/add_docker_metadata/add_docker_metadata.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA1019: cgroup.NewReader is deprecated: use NewReaderOptions (staticcheck)

Check failure on line 53 in libbeat/processors/add_docker_metadata/add_docker_metadata.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

SA1019: cgroup.NewReader is deprecated: use NewReaderOptions (staticcheck)
}

func init() {
Expand Down Expand Up @@ -218,7 +218,7 @@
_, _ = meta.Put("container.id", container.ID)
_, _ = meta.Put("container.image.name", container.Image)
_, _ = meta.Put("container.name", container.Name)
event.Fields.DeepUpdate(meta.Clone())
event.Fields.DeepUpdate(meta)
} else {
d.log.Debugf("Container not found: cid=%s", cid)
}
Expand Down Expand Up @@ -266,7 +266,7 @@
if d.cgroups != nil {
if cid := d.cgroups.Get(pid); cid != nil {
d.log.Debugf("Using cached cgroups for pid=%v", pid)
return cid.(string), nil

Check failure on line 269 in libbeat/processors/add_docker_metadata/add_docker_metadata.go

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Error return value is not checked (errcheck)

Check failure on line 269 in libbeat/processors/add_docker_metadata/add_docker_metadata.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Error return value is not checked (errcheck)

Check failure on line 269 in libbeat/processors/add_docker_metadata/add_docker_metadata.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

Error return value is not checked (errcheck)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build (linux || darwin || windows) && !integration

package add_docker_metadata

import (
"testing"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/elastic-agent-autodiscover/docker"
conf "github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp/logptest"
"github.com/elastic/elastic-agent-libs/mapstr"
)

func BenchmarkAddDockerMetadata(b *testing.B) {
cfg, err := conf.NewConfigFrom(map[string]interface{}{
"match_fields": []string{"container.id"},
})
if err != nil {
b.Fatal(err)
}

p, err := buildDockerMetadataProcessor(logptest.NewTestingLogger(b, ""), cfg, MockWatcherFactory(
map[string]*docker.Container{
"abc123": {
ID: "abc123def456",
Image: "myrepo/myimage:latest",
Name: "my-container",
Labels: map[string]string{
"app": "myapp",
"version": "v1.2.3",
"env": "production",
},
},
}, nil))
if err != nil {
b.Fatal(err)
}

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
event := &beat.Event{
Fields: mapstr.M{
"container": mapstr.M{"id": "abc123"},
"message": "test log line",
},
}
_, err := p.Run(event)
if err != nil {
b.Fatal(err)
}
}
}
Loading
Loading