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

Add new agentbeat with all beats shipped with Elastic Agent as a single beat #38183

Merged
merged 27 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7b5d784
Add new agentbeat.
blakerouse Mar 4, 2024
3cc5471
Merge remote-tracking branch 'upstream/main' into agentbeat
blakerouse Mar 4, 2024
19eead4
Fix auditbeat test.
blakerouse Mar 4, 2024
ee5310c
Fix imports.
blakerouse Mar 4, 2024
3350b24
Fix moduleName in audit/system/package.
blakerouse Mar 5, 2024
c17068c
Fix imports on osquerybeat.
blakerouse Mar 5, 2024
777e720
Add agentbeat.spec.yml.
blakerouse Mar 5, 2024
2a3f1d5
Adjust metrics registration to not collide.
blakerouse Apr 4, 2024
a108161
Merge branch 'main' into agentbeat
blakerouse Apr 4, 2024
14bcf16
Fix issue with management.ConfigTransform.SetTransform.
blakerouse Apr 4, 2024
3605950
Fix lint in metricbeat.
blakerouse Apr 4, 2024
8221cb4
Merge remote-tracking branch 'upstream/main' into agentbeat
blakerouse Apr 4, 2024
01840af
Merge remote-tracking branch 'upstream/main' into agentbeat
blakerouse Apr 5, 2024
116c9bc
Work on enabling system tests.
blakerouse Apr 8, 2024
6643c76
Add go integration tests for agentbeat.
blakerouse Apr 9, 2024
2ba6dec
Fix imports.
blakerouse Apr 9, 2024
4d0b8b6
Fix kubernetes provider to work with agentbeat.
blakerouse Apr 10, 2024
9f2e860
Adjustments for auditbeat.
blakerouse Apr 10, 2024
a8164a2
Adjust auditbeat.
blakerouse Apr 10, 2024
80075fa
Adjust initialization.
blakerouse Apr 11, 2024
8447872
More cleanup.
blakerouse Apr 11, 2024
10f58fc
Merge branch 'main' into agentbeat
blakerouse Apr 11, 2024
88c8fcc
More adjustments.
blakerouse Apr 11, 2024
466b2b4
Fix auditbeat show command.
blakerouse Apr 11, 2024
94a7ab4
Fix include list.
blakerouse Apr 11, 2024
bdc194c
Fix auditbeat login test.
blakerouse Apr 11, 2024
9edf3ac
More auditbeat test fixes.
blakerouse Apr 11, 2024
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
8 changes: 7 additions & 1 deletion filebeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (

"github.com/elastic/beats/v7/filebeat/beater"

cmd "github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/filebeat/fileset"
"github.com/elastic/beats/v7/filebeat/input"
"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd/instance"

// Import processors.
Expand All @@ -47,6 +49,10 @@ func FilebeatSettings() instance.Settings {
RunFlags: runFlags,
Name: Name,
HasDashboards: true,
RegisterMetrics: func() {
fileset.RegisterMonitoringModules()
input.RegisterMonitoringInputs()
},
}
}

Expand Down
9 changes: 7 additions & 2 deletions filebeat/fileset/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package fileset

import (
"fmt"
"sync"

"github.com/gofrs/uuid"
"github.com/mitchellh/hashstructure"
Expand All @@ -33,9 +34,13 @@ import (
)

var moduleList = monitoring.NewUniqueList()
var moduleListMetricsOnce sync.Once

func init() {
monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "module", moduleList.Report, monitoring.Report)
// RegisterMonitoringModules registers the modules list with the monitoring system.
func RegisterMonitoringModules() {
moduleListMetricsOnce.Do(func() {
monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "module", moduleList.Report, monitoring.Report)
})
}

// Factory for modules
Expand Down
8 changes: 6 additions & 2 deletions filebeat/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ import (
)

var inputList = monitoring.NewUniqueList()
var inputListMetricsOnce sync.Once

func init() {
monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "input", inputList.Report, monitoring.Report)
// RegisterMonitoringInputs registers the inputs list with the monitoring system.
func RegisterMonitoringInputs() {
inputListMetricsOnce.Do(func() {
monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "input", inputList.Report, monitoring.Report)
})
}

// Input is the interface common to all input
Expand Down
9 changes: 7 additions & 2 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func Run(settings Settings, bt beat.Creator) error {

// NewInitializedBeat creates a new beat where all information and initialization is derived from settings
func NewInitializedBeat(settings Settings) (*Beat, error) {
b, err := NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed)
b, err := NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed, settings.RegisterMetrics)
if err != nil {
return nil, err
}
Expand All @@ -235,7 +235,12 @@ func NewInitializedBeat(settings Settings) (*Beat, error) {
}

// NewBeat creates a new beat instance
func NewBeat(name, indexPrefix, v string, elasticLicensed bool) (*Beat, error) {
func NewBeat(name, indexPrefix, v string, elasticLicensed bool, registerMetrics func()) (*Beat, error) {
// first thing always register the internal metrics
if registerMetrics != nil {
registerMetrics()
}

if v == "" {
v = version.GetDefaultVersion()
}
Expand Down
16 changes: 8 additions & 8 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

func TestNewInstance(t *testing.T) {
b, err := NewBeat("testbeat", "testidx", "0.9", false)
b, err := NewBeat("testbeat", "testidx", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand All @@ -51,7 +51,7 @@ func TestNewInstance(t *testing.T) {
assert.Equal(t, 36, len(b.Info.ID.String()))

// indexPrefix set to name if empty
b, err = NewBeat("testbeat", "", "0.9", false)
b, err = NewBeat("testbeat", "", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand All @@ -61,7 +61,7 @@ func TestNewInstance(t *testing.T) {
}

func TestNewInstanceUUID(t *testing.T) {
b, err := NewBeat("testbeat", "", "0.9", false)
b, err := NewBeat("testbeat", "", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand All @@ -75,7 +75,7 @@ func TestNewInstanceUUID(t *testing.T) {
}

func TestInitKibanaConfig(t *testing.T) {
b, err := NewBeat("filebeat", "testidx", "0.9", false)
b, err := NewBeat("filebeat", "testidx", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestInitKibanaConfig(t *testing.T) {
}

func TestEmptyMetaJson(t *testing.T) {
b, err := NewBeat("filebeat", "testidx", "0.9", false)
b, err := NewBeat("filebeat", "testidx", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand All @@ -139,7 +139,7 @@ func TestEmptyMetaJson(t *testing.T) {
}

func TestMetaJsonWithTimestamp(t *testing.T) {
firstBeat, err := NewBeat("filebeat", "testidx", "0.9", false)
firstBeat, err := NewBeat("filebeat", "testidx", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand All @@ -155,7 +155,7 @@ func TestMetaJsonWithTimestamp(t *testing.T) {
err = firstBeat.loadMeta(metaPath)
assert.Equal(t, nil, err, "Unable to load meta file properly")

secondBeat, err := NewBeat("filebeat", "testidx", "0.9", false)
secondBeat, err := NewBeat("filebeat", "testidx", "0.9", false, nil)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestSanitizeIPs(t *testing.T) {

func TestReloader(t *testing.T) {
t.Run("updates the output configuration on the beat", func(t *testing.T) {
b, err := NewBeat("testbeat", "testidx", "0.9", false)
b, err := NewBeat("testbeat", "testidx", "0.9", false, nil)
require.NoError(t, err)

cfg := `
Expand Down
3 changes: 3 additions & 0 deletions libbeat/cmd/instance/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ type Settings struct {
// publisher pipeline. This is only useful when the Beat plans to use
// beat.DropIfFull PublishMode. Leave as zero for default.
InputQueueSize int

// RegisterMetrics function that is called to register any metrics that the beat provides.
RegisterMetrics func()
}
2 changes: 1 addition & 1 deletion libbeat/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func genSetupCmd(settings instance.Settings, beatCreator beat.Creator) *cobra.Co
* ILM policy (for Elasticsearch 6.5 and newer).
`,
Run: func(cmd *cobra.Command, args []string) {
beat, err := instance.NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed)
beat, err := instance.NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed, settings.RegisterMetrics)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/cmd/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GenTestConfigCmd(settings instance.Settings, beatCreator beat.Creator) *cob
Use: "config",
Short: "Test configuration settings",
Run: func(cmd *cobra.Command, args []string) {
b, err := instance.NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed)
b, err := instance.NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed, settings.RegisterMetrics)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
Short: "Show current version info",
Run: cli.RunWith(
func(_ *cobra.Command, args []string) error {
beat, err := instance.NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed)
beat, err := instance.NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed, settings.RegisterMetrics)
if err != nil {
return fmt.Errorf("error initializing beat: %s", err)

Check failure on line 40 in libbeat/cmd/version.go

View workflow job for this annotation

GitHub Actions / lint (windows)

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)

Check failure on line 40 in libbeat/cmd/version.go

View workflow job for this annotation

GitHub Actions / lint (linux)

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

buildTime := "unknown"
if bt := version.BuildTime(); !bt.IsZero() {
buildTime = bt.String()
}
fmt.Printf("%s version %s (%s), libbeat %s [%s built %s]\n",

Check failure on line 47 in libbeat/cmd/version.go

View workflow job for this annotation

GitHub Actions / lint (windows)

use of `fmt.Printf` forbidden by pattern `fmt.Print.*` (forbidigo)

Check failure on line 47 in libbeat/cmd/version.go

View workflow job for this annotation

GitHub Actions / lint (linux)

use of `fmt.Printf` forbidden by pattern `fmt.Print.*` (forbidigo)
beat.Info.Beat, beat.Info.Version, runtime.GOARCH, version.GetDefaultVersion(),
version.Commit(), buildTime)
return nil
Expand Down
7 changes: 6 additions & 1 deletion metricbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (

"github.com/spf13/pflag"

"github.com/elastic/elastic-agent-libs/mapstr"

"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd/instance"
"github.com/elastic/beats/v7/libbeat/ecs"
"github.com/elastic/beats/v7/libbeat/publisher/processing"
"github.com/elastic/beats/v7/metricbeat/beater"
"github.com/elastic/beats/v7/metricbeat/cmd/test"
"github.com/elastic/elastic-agent-libs/mapstr"
"github.com/elastic/beats/v7/metricbeat/mb/module"

// import modules
_ "github.com/elastic/beats/v7/metricbeat/include"
Expand Down Expand Up @@ -59,6 +61,9 @@ func MetricbeatSettings() instance.Settings {
Name: Name,
HasDashboards: true,
Processing: processing.MakeDefaultSupport(true, nil, withECSVersion, processing.WithHost, processing.WithAgentMeta()),
RegisterMetrics: func() {
module.RegisterMonitoringModules()
},
}
}

Expand Down
13 changes: 7 additions & 6 deletions metricbeat/mb/module/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (
"github.com/elastic/elastic-agent-libs/monitoring"
)

var (
moduleList *monitoring.UniqueList
)
var moduleList = monitoring.NewUniqueList()
var moduleListMetricsOnce sync.Once

func init() {
moduleList = monitoring.NewUniqueList()
monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "module", moduleList.Report, monitoring.Report)
// RegisterMonitoringModules registers the modules list with the monitoring system.
func RegisterMonitoringModules() {
moduleListMetricsOnce.Do(func() {
monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "module", moduleList.Report, monitoring.Report)
})
}

// Runner is a facade for a Wrapper that provides a simple interface
Expand Down
14 changes: 9 additions & 5 deletions packetbeat/scripts/mage/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import (
// GolangCrossBuild build the Beat binary inside of the golang-builder.
// Do not use directly, use crossBuild instead.
func GolangCrossBuild() error {
return multierr.Combine(
devtools.GolangCrossBuild(GolangCrossBuildArgs()),
devtools.TestLinuxForCentosGLIBC(),
)
}

// GolangCrossBuildArgs returns the correct build arguments for golang-crossbuild.
func GolangCrossBuildArgs() devtools.BuildArgs {
params := devtools.DefaultGolangCrossBuildArgs()
if flags, found := libpcapLDFLAGS[devtools.Platform.Name]; found {
params.Env = map[string]string{
Expand All @@ -35,11 +43,7 @@ func GolangCrossBuild() error {
if flags, found := libpcapCFLAGS[devtools.Platform.Name]; found {
params.Env["CGO_CFLAGS"] = flags
}

return multierr.Combine(
devtools.GolangCrossBuild(params),
devtools.TestLinuxForCentosGLIBC(),
)
return params
}

// -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions x-pack/agentbeat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ES_BEATS ?= ../..

include $(ES_BEATS)/dev-tools/make/mage.mk
Loading
Loading