Skip to content

Commit

Permalink
added logs and running all three tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaanyalti committed Dec 9, 2024
1 parent 99fa33d commit 8ccbc38
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions internal/pkg/agent/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 ===================================")

Check failure on line 212 in internal/pkg/agent/application/application.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("Agent config file: ", path)

Check failure on line 213 in internal/pkg/agent/application/application.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("Config pathld ", paths.Config())

Check failure on line 214 in internal/pkg/agent/application/application.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("=====================================================================================================")

Check failure on line 215 in internal/pkg/agent/application/application.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

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

store, err := storage.NewEncryptedDiskStore(ctx, path)
if err != nil {
return nil, nil, fmt.Errorf("error instantiating encrypted disk store: %w", err)
Expand Down
22 changes: 22 additions & 0 deletions internal/pkg/agent/application/info/agent_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func updateLogLevel(ctx context.Context, level string) error {
}

agentConfigFile := paths.AgentConfigFile()

fmt.Println("========================== AGENT CONFIG FILE updateLogLevel ==========================")

Check failure on line 59 in internal/pkg/agent/application/info/agent_id.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("Agent config file: ", agentConfigFile)

Check failure on line 60 in internal/pkg/agent/application/info/agent_id.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("Config file: ", paths.Config())

Check failure on line 61 in internal/pkg/agent/application/info/agent_id.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("======================================================================================")

Check failure on line 62 in internal/pkg/agent/application/info/agent_id.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

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

diskStore, err := storage.NewEncryptedDiskStore(ctx, agentConfigFile)
if err != nil {
return fmt.Errorf("error instantiating encrypted disk store: %w", err)
Expand All @@ -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 ====================")

Check failure on line 86 in internal/pkg/agent/application/info/agent_id.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
fmt.Println("Agent config file: ", agentConfigFile)

Check failure on line 87 in internal/pkg/agent/application/info/agent_id.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

use of `fmt.Println` forbidden by pattern `fmt.Print.*` (forbidigo)
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)
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions internal/pkg/agent/cmd/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -525,7 +532,6 @@ func enroll(streams *cli.IOStreams, cmd *cobra.Command) error {
pathConfigFile,
store,
)

if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions internal/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 6 additions & 4 deletions internal/pkg/config/operations/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions testing/integration/linux_rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
1 change: 1 addition & 0 deletions testing/integration/restrict_upgrade_rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}

0 comments on commit 8ccbc38

Please sign in to comment.