From 8ccbc3867af9d3e2c4663c2bae259a01696fe6a2 Mon Sep 17 00:00:00 2001 From: kaanyalti Date: Mon, 9 Dec 2024 13:40:04 -0500 Subject: [PATCH] added logs and running all three tests --- .buildkite/scripts/steps/integration_tests.sh | 2 +- internal/pkg/agent/application/application.go | 9 ++++++-- .../pkg/agent/application/info/agent_id.go | 22 +++++++++++++++++++ internal/pkg/agent/cmd/enroll.go | 10 +++++++-- internal/pkg/agent/cmd/run.go | 15 +++++++++++++ internal/pkg/config/operations/inspector.go | 10 +++++---- testing/integration/linux_rpm_test.go | 2 ++ .../integration/restrict_upgrade_rpm_test.go | 1 + 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/.buildkite/scripts/steps/integration_tests.sh b/.buildkite/scripts/steps/integration_tests.sh index d965e4970fa..d631e243564 100755 --- a/.buildkite/scripts/steps/integration_tests.sh +++ b/.buildkite/scripts/steps/integration_tests.sh @@ -18,7 +18,7 @@ fi # Run integration tests set +e -AGENT_STACK_VERSION="${STACK_VERSION}" TEST_INTEG_CLEAN_ON_EXIT=true STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true TEST_PACKAGES="rpm" TEST_GROUPS="rpm" TEST_PLATFORMS="linux/amd64" GOTEST_FLAGS='-test.run ^(TestRpmLogIngestFleetManaged|TestRpmFleetUpgrade)$' mage $MAGE_TARGET $MAGE_SUBTARGET +AGENT_STACK_VERSION="${STACK_VERSION}" TEST_INTEG_CLEAN_ON_EXIT=true STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true TEST_PACKAGES="rpm" TEST_GROUPS="rpm" TEST_PLATFORMS="linux/amd64" GOTEST_FLAGS='-test.run ^(TestRpmLogIngestFleetManaged|TestRpmFleetUpgrade|TestRestrictUpgradeRPM)$' mage $MAGE_TARGET $MAGE_SUBTARGET TESTS_EXIT_STATUS=$? set -e diff --git a/internal/pkg/agent/application/application.go b/internal/pkg/agent/application/application.go index 4e42ccca917..671cd763e4c 100644 --- a/internal/pkg/agent/application/application.go +++ b/internal/pkg/agent/application/application.go @@ -48,7 +48,6 @@ func New( disableMonitoring bool, modifiers ...component.PlatformModifier, ) (*coordinator.Coordinator, coordinator.ConfigManager, composable.Controller, error) { - err := version.InitVersionError() if err != nil { // non-fatal error, log a warning and move on @@ -122,7 +121,7 @@ func New( var configMgr coordinator.ConfigManager var managed *managedConfigManager - var compModifiers = []coordinator.ComponentsModifier{InjectAPMConfig} + compModifiers := []coordinator.ComponentsModifier{InjectAPMConfig} var composableManaged bool var isManaged bool @@ -209,6 +208,12 @@ func New( func mergeFleetConfig(ctx context.Context, rawConfig *config.Config) (storage.Store, *configuration.Configuration, error) { path := paths.AgentConfigFile() + + fmt.Println("============================== AGENT CONFIG FILE mergeFleetConfig ===================================") + fmt.Println("Agent config file: ", path) + fmt.Println("Config pathld ", paths.Config()) + fmt.Println("=====================================================================================================") + store, err := storage.NewEncryptedDiskStore(ctx, path) if err != nil { return nil, nil, fmt.Errorf("error instantiating encrypted disk store: %w", err) diff --git a/internal/pkg/agent/application/info/agent_id.go b/internal/pkg/agent/application/info/agent_id.go index 31435d02cd5..7d5f428bc97 100644 --- a/internal/pkg/agent/application/info/agent_id.go +++ b/internal/pkg/agent/application/info/agent_id.go @@ -55,6 +55,12 @@ func updateLogLevel(ctx context.Context, level string) error { } agentConfigFile := paths.AgentConfigFile() + + fmt.Println("========================== AGENT CONFIG FILE updateLogLevel ==========================") + fmt.Println("Agent config file: ", agentConfigFile) + fmt.Println("Config file: ", paths.Config()) + fmt.Println("======================================================================================") + diskStore, err := storage.NewEncryptedDiskStore(ctx, agentConfigFile) if err != nil { return fmt.Errorf("error instantiating encrypted disk store: %w", err) @@ -77,6 +83,10 @@ func generateAgentID() (string, error) { // as well as a bool indicating if agent is running in standalone mode. func getInfoFromStore(s ioStore, logLevel string) (*persistentAgentInfo, bool, error) { agentConfigFile := paths.AgentConfigFile() + fmt.Println("====================== AGENT CONFIG FILE getInfoFromStore ====================") + fmt.Println("Agent config file: ", agentConfigFile) + fmt.Println("Config file: ", paths.Config()) + fmt.Println("===========================================================") reader, err := s.Load() if err != nil { return nil, false, fmt.Errorf("failed to load from ioStore: %w", err) @@ -98,6 +108,10 @@ func getInfoFromStore(s ioStore, logLevel string) (*persistentAgentInfo, bool, e errors.TypeFilesystem) } + fmt.Println("======================= CONFIG MAP =========================") + fmt.Println(configMap) + fmt.Println("============================================================") + // check fleet config. This behavior emulates configuration.IsStandalone fleetmode, fleetExists := configMap["fleet"] isStandalone := true @@ -136,6 +150,10 @@ func getInfoFromStore(s ioStore, logLevel string) (*persistentAgentInfo, bool, e func updateAgentInfo(s ioStore, agentInfo *persistentAgentInfo) error { agentConfigFile := paths.AgentConfigFile() + fmt.Println("=================== AGENT CONFIG FILE updateAgentInfo ======================") + fmt.Println("Agent config file: ", agentConfigFile) + fmt.Println("Config path: ", paths.Config()) + fmt.Println("============================================================================") reader, err := s.Load() if err != nil { return errors.New(err, "failed loading from store", @@ -222,6 +240,10 @@ func loadAgentInfo(ctx context.Context, forceUpdate bool, logLevel string, creat defer idLock.Unlock() agentConfigFile := paths.AgentConfigFile() + fmt.Println("========================== AGENT CONFIG FILE loadAgentInfo =========================") + fmt.Println("Agent config file: ", agentConfigFile) + fmt.Println("Config file: ", paths.Config()) + fmt.Println("====================================================================================") diskStore, err := storage.NewEncryptedDiskStore(ctx, agentConfigFile) if err != nil { return nil, false, fmt.Errorf("error instantiating encrypted disk store: %w", err) diff --git a/internal/pkg/agent/cmd/enroll.go b/internal/pkg/agent/cmd/enroll.go index 924ab373f8f..57ad24f6d9c 100644 --- a/internal/pkg/agent/cmd/enroll.go +++ b/internal/pkg/agent/cmd/enroll.go @@ -508,7 +508,14 @@ func enroll(streams *cli.IOStreams, cmd *cobra.Command) error { storeOpts = append(storeOpts, storage.ReplaceOnSuccessStoreWithOwnership(*fixPermissions)) encryptOpts = append(encryptOpts, storage.EncryptedStoreWithOwnership(*fixPermissions)) } - encStore, err := storage.NewEncryptedDiskStore(ctx, paths.AgentConfigFile(), encryptOpts...) + + p := paths.AgentConfigFile() + fmt.Println("========================== AGENT CONFIG FILE enroll =======================") + fmt.Println("Agent config file: ", p) + fmt.Println("Config file: ", paths.Config()) + fmt.Println("===========================================================================") + + encStore, err := storage.NewEncryptedDiskStore(ctx, p, encryptOpts...) if err != nil { return fmt.Errorf("failed to create encrypted disk store: %w", err) } @@ -525,7 +532,6 @@ func enroll(streams *cli.IOStreams, cmd *cobra.Command) error { pathConfigFile, store, ) - if err != nil { return err } diff --git a/internal/pkg/agent/cmd/run.go b/internal/pkg/agent/cmd/run.go index 43a2ad34ee6..69882f63038 100644 --- a/internal/pkg/agent/cmd/run.go +++ b/internal/pkg/agent/cmd/run.go @@ -202,6 +202,10 @@ func runElasticAgent(ctx context.Context, cancel context.CancelFunc, override cf return logReturn(l, errors.New(err, "failed to perform delayed enrollment")) } pathConfigFile := paths.AgentConfigFile() + fmt.Println("====================== AGENT CONFIG FILE runElasticAgent ==================") + fmt.Println("Agent config file: ", pathConfigFile) + fmt.Println("Config file: ", paths.Config()) + fmt.Println("===========================================") // agent ID needs to stay empty in bootstrap mode createAgentID := true @@ -454,6 +458,12 @@ func getOverwrites(ctx context.Context, rawConfig *config.Config) error { return nil } path := paths.AgentConfigFile() + + fmt.Println("======================== AGENT CONFIG FILE getOverwrites =======================") + fmt.Println("Agent config file: ", path) + fmt.Println("Config file: ", paths.Config()) + fmt.Println("================================================================================") + store, err := storage.NewEncryptedDiskStore(ctx, path) if err != nil { return fmt.Errorf("error instantiating encrypted disk store: %w", err) @@ -534,7 +544,12 @@ func tryDelayEnroll(ctx context.Context, logger *logger.Logger, cfg *configurati // SkipDaemonRestart to true avoids running that code. options.SkipDaemonRestart = true pathConfigFile := paths.ConfigFile() + configPath := paths.AgentConfigFile() encStore, err := storage.NewEncryptedDiskStore(ctx, paths.AgentConfigFile()) + fmt.Println("================== AGENT CONFIG FILE tryDelayEnroll =================") + fmt.Println("Agent Config File: ", configPath) + fmt.Println("Config File: ", pathConfigFile) + fmt.Println("=====================================================================") if err != nil { return nil, fmt.Errorf("failed to create encrypted disk store: %w", err) } diff --git a/internal/pkg/config/operations/inspector.go b/internal/pkg/config/operations/inspector.go index 6acc202d062..e04ab61dfd1 100644 --- a/internal/pkg/config/operations/inspector.go +++ b/internal/pkg/config/operations/inspector.go @@ -19,10 +19,8 @@ import ( "github.com/elastic/elastic-agent/pkg/core/logger" ) -var ( - // ErrNoFleetConfig is returned when no configuration was retrieved from fleet just yet. - ErrNoFleetConfig = fmt.Errorf("no fleet config retrieved yet") -) +// ErrNoFleetConfig is returned when no configuration was retrieved from fleet just yet. +var ErrNoFleetConfig = fmt.Errorf("no fleet config retrieved yet") // LoadFullAgentConfig load agent config based on provided paths and defined capabilities. // In case fleet is used, config from policy action is returned. @@ -82,6 +80,10 @@ func loadConfig(ctx context.Context, configPath string, unprivileged bool) (*con } path := paths.AgentConfigFile() + fmt.Println("======================== AGENT CONFIG FILE loadConfig =========================") + fmt.Println("Agent config file: ", path) + fmt.Println("Config path: ", paths.Config()) + fmt.Println("===============================================================================") store, err := storage.NewEncryptedDiskStore(ctx, path, storage.WithUnprivileged(unprivileged)) if err != nil { diff --git a/testing/integration/linux_rpm_test.go b/testing/integration/linux_rpm_test.go index b76313cd33b..a60abb9ca01 100644 --- a/testing/integration/linux_rpm_test.go +++ b/testing/integration/linux_rpm_test.go @@ -96,6 +96,7 @@ func TestRpmLogIngestFleetManaged(t *testing.T) { t.Run("Normal logs with flattened data_stream are shipped", func(t *testing.T) { testFlattenedDatastreamFleetPolicy(t, ctx, info, policy) }) + require.True(t, false, "forcing failure") } func TestRpmFleetUpgrade(t *testing.T) { @@ -191,4 +192,5 @@ func TestRpmFleetUpgrade(t *testing.T) { t.Logf("Got Agent version %s != %s", newVersion, noSnapshotVersion) return false }, 5*time.Minute, time.Second) + require.True(t, false, "forcing failure") } diff --git a/testing/integration/restrict_upgrade_rpm_test.go b/testing/integration/restrict_upgrade_rpm_test.go index 5b1d8e31607..8743d06cd90 100644 --- a/testing/integration/restrict_upgrade_rpm_test.go +++ b/testing/integration/restrict_upgrade_rpm_test.go @@ -55,5 +55,6 @@ func TestRestrictUpgradeRPM(t *testing.T) { out, err := fixture.Exec(ctx, []string{"upgrade", "1.0.0"}) require.Error(t, err) require.Contains(t, string(out), coordinator.ErrNotUpgradable.Error()) + require.True(t, false, "forcing failure") }) }