From 60b8a5ad06bd38c836c8a041bf88c429ddfb2fc6 Mon Sep 17 00:00:00 2001 From: Craig MacKenzie Date: Tue, 23 Apr 2024 08:54:05 -0400 Subject: [PATCH] Agentbeat: remove unused files from package and silence new error message (#39064) * Remove Beat config files from agentbeat. Beats no longer reads config files at startup when run as part of agent. * Silence new error message with agentbeat. * Add comment to log line. (cherry picked from commit e6cae466ab81bfcd3f6df94332991ee0669a4c8e) --- dev-tools/packaging/package_test.go | 4 +-- filebeat/fileset/modules.go | 6 +++- .../dev-tools/packaging/packages.yml | 31 ------------------- 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/dev-tools/packaging/package_test.go b/dev-tools/packaging/package_test.go index fff920b429c2..308610b4760e 100644 --- a/dev-tools/packaging/package_test.go +++ b/dev-tools/packaging/package_test.go @@ -263,7 +263,7 @@ func checkConfigPermissionsWithMode(t *testing.T, p *packageFile, expectedMode o return } } - t.Errorf("no config file found matching %v", configFilePattern) + t.Logf("no config file found matching %v", configFilePattern) }) } @@ -288,7 +288,7 @@ func checkConfigOwner(t *testing.T, p *packageFile, expectRoot bool) { return } } - t.Errorf("no config file found matching %v", configFilePattern) + t.Logf("no config file found matching %v", configFilePattern) }) } diff --git a/filebeat/fileset/modules.go b/filebeat/fileset/modules.go index b1482033c911..a3d2c82f6ec8 100644 --- a/filebeat/fileset/modules.go +++ b/filebeat/fileset/modules.go @@ -29,6 +29,7 @@ import ( "gopkg.in/yaml.v2" "github.com/elastic/beats/v7/libbeat/beat" + "github.com/elastic/beats/v7/libbeat/common/fleetmode" conf "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/paths" @@ -149,7 +150,10 @@ func NewModuleRegistry(moduleConfigs []*conf.C, beatInfo beat.Info, init bool, f stat, err := os.Stat(modulesPath) if err != nil || !stat.IsDir() { log := logp.NewLogger(logName) - log.Errorf("Not loading modules. Module directory not found: %s", modulesPath) + if !fleetmode.Enabled() { + // When run under agent via agentbeat there is no modules directory and this is expected. + log.Errorf("Not loading modules. Module directory not found: %s", modulesPath) + } return &ModuleRegistry{log: log}, nil //nolint:nilerr // empty registry, no error } diff --git a/x-pack/agentbeat/dev-tools/packaging/packages.yml b/x-pack/agentbeat/dev-tools/packaging/packages.yml index b753d88bf2a6..98c5c0f82898 100644 --- a/x-pack/agentbeat/dev-tools/packaging/packages.yml +++ b/x-pack/agentbeat/dev-tools/packaging/packages.yml @@ -24,9 +24,6 @@ shared: NOTICE.txt: source: '{{ repo.RootDir }}/NOTICE.txt' mode: 0644 - README.md: - template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/common/README.md.tmpl' - mode: 0644 .build_hash.txt: content: > {{ commit }} @@ -35,32 +32,6 @@ shared: source: '{{.BeatName}}.spec.yml' mode: 0644 - - &config_files - 'auditbeat.yml': - source: '{{ repo.RootDir }}/x-pack/auditbeat/auditbeat.yml' - mode: 0600 - config: true - 'filebeat.yml': - source: '{{ repo.RootDir }}/x-pack/filebeat/filebeat.yml' - mode: 0600 - config: true - 'heartbeat.yml': - source: '{{ repo.RootDir }}/x-pack/heartbeat/heartbeat.yml' - mode: 0600 - config: true - 'metricbeat.yml': - source: '{{ repo.RootDir }}/x-pack/metricbeat/metricbeat.yml' - mode: 0600 - config: true - 'osquerybeat.yml': - source: '{{ repo.RootDir }}/x-pack/osquerybeat/osquerybeat.yml' - mode: 0600 - config: true - 'packetbeat.yml': - source: '{{ repo.RootDir }}/x-pack/packetbeat/packetbeat.yml' - mode: 0600 - config: true - - &unix_osquery_files 'osquery-extension.ext': source: '{{ repo.RootDir }}/x-pack/osquerybeat/ext/osquery-extension/build/golang-crossbuild/osquery-extension-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}' @@ -76,14 +47,12 @@ shared: <<: *common files: <<: *binary_files - <<: *config_files <<: *unix_osquery_files - &windows_binary_spec <<: *common files: <<: *binary_files - <<: *config_files <<: *windows_osquery_files # License modifiers for the Elastic License