Skip to content

Commit

Permalink
Set independent Elastic Agents as default for system tests (#1959)
Browse files Browse the repository at this point in the history
Set independent Elastic Agents as default for system tests, and
updated CI pipelines accordingly.
  • Loading branch information
mrodm authored Jul 10, 2024
1 parent 2eb5600 commit 24c5fb3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 80 deletions.
21 changes: 13 additions & 8 deletions .buildkite/pipeline.trigger.integration.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ CHECK_PACKAGES_TESTS=(
for independent_agent in false true ; do
for test in "${CHECK_PACKAGES_TESTS[@]}"; do
label_suffix=""
if [[ "$independent_agent" == "true" ]]; then
label_suffix=" (independent agent)"
if [[ "$independent_agent" == "false" ]]; then
label_suffix=" (stack agent)"
fi
test_name=${test#"test-check-packages-"}
echo " - label: \":go: Integration test: ${test_name}${label_suffix}\""
Expand All @@ -63,7 +63,7 @@ for test in "${CHECK_PACKAGES_TESTS[@]}"; do
if [[ $test =~ with-kind$ ]]; then
echo " - build/kubectl-dump.txt"
fi
if [[ "${independent_agent}" == "true" ]]; then
if [[ "${independent_agent}" == "false" ]]; then
echo " env:"
echo " ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT: ${independent_agent}"
fi
Expand Down Expand Up @@ -92,15 +92,20 @@ pushd test/packages/parallel > /dev/null
for independent_agent in false true; do
for package in $(find . -maxdepth 1 -mindepth 1 -type d) ; do
label_suffix=""
if [[ "$independent_agent" == "true" ]]; then
label_suffix=" (independent agent)"
if [[ "$independent_agent" == "false" ]]; then
label_suffix=" (stack agent)"
fi
package_name=$(basename "${package}")
if [[ "$independent_agent" == "false" && "$package_name" == "oracle" ]]; then
echoerr "Package \"${package_name}\" skipped: not supported with Elastic Agent running in the stack (missing required software)."
continue
fi

if [[ "$independent_agent" == "false" && "$package_name" == "auditd_manager" ]]; then
echoerr "Package \"${package_name}\" skipped: not supported with Elastic Agent running in the stack (missing capabilities)."
continue
fi

if [[ "$independent_agent" == "false" && "$package_name" == "custom_entrypoint" ]]; then
echoerr "Package \"${package_name}\" skipped: not supported with Elastic Agent running in the stack (missing required files deployed in provisioning)."
continue
Expand All @@ -111,7 +116,7 @@ for package in $(find . -maxdepth 1 -mindepth 1 -type d) ; do
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-packages-parallel -p ${package_name}"
echo " env:"
echo " UPLOAD_SAFE_LOGS: 1"
if [[ "${independent_agent}" == "true" ]]; then
if [[ "${independent_agent}" == "false" ]]; then
echo " ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT: ${independent_agent}"
fi
echo " agents:"
Expand Down Expand Up @@ -152,8 +157,8 @@ echo " - build/elastic-stack-dump/install-zip-shellinit/logs/*.log"

for independent_agent in false true; do
label_suffix=""
if [[ "$independent_agent" == "true" ]]; then
label_suffix=" (independent agent)"
if [[ "$independent_agent" == "false" ]]; then
label_suffix=" (stack agent)"
fi
echo " - label: \":go: Integration test: system-flags${label_suffix}\""
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-system-test-flags"
Expand Down
33 changes: 16 additions & 17 deletions cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,23 +561,22 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
}

runner := system.NewSystemTestRunner(system.SystemTestRunnerOptions{
Profile: profile,
PackageRootPath: packageRootPath,
KibanaClient: kibanaClient,
API: esClient.API,
ConfigFilePath: configFileFlag,
RunSetup: runSetup,
RunTearDown: runTearDown,
RunTestsOnly: runTestsOnly,
DataStreams: dataStreams,
ServiceVariant: variantFlag,
FailOnMissingTests: failOnMissing,
GenerateTestResult: generateTestResult,
DeferCleanup: deferCleanup,
RunIndependentElasticAgent: false,
GlobalTestConfig: globalTestConfig.System,
WithCoverage: testCoverage,
CoverageType: testCoverageFormat,
Profile: profile,
PackageRootPath: packageRootPath,
KibanaClient: kibanaClient,
API: esClient.API,
ConfigFilePath: configFileFlag,
RunSetup: runSetup,
RunTearDown: runTearDown,
RunTestsOnly: runTestsOnly,
DataStreams: dataStreams,
ServiceVariant: variantFlag,
FailOnMissingTests: failOnMissing,
GenerateTestResult: generateTestResult,
DeferCleanup: deferCleanup,
GlobalTestConfig: globalTestConfig.System,
WithCoverage: testCoverage,
CoverageType: testCoverageFormat,
})

logger.Debugf("Running suite...")
Expand Down
88 changes: 42 additions & 46 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ type runner struct {
dataStreams []string
serviceVariant string

globalTestConfig testrunner.GlobalRunnerTestConfig
failOnMissingTests bool
generateTestResult bool
runIndependentElasticAgent bool
deferCleanup time.Duration
withCoverage bool
coverageType string
globalTestConfig testrunner.GlobalRunnerTestConfig
failOnMissingTests bool
deferCleanup time.Duration
generateTestResult bool
withCoverage bool
coverageType string

configFilePath string
runSetup bool
Expand Down Expand Up @@ -68,33 +67,31 @@ type SystemTestRunnerOptions struct {

GlobalTestConfig testrunner.GlobalRunnerTestConfig

FailOnMissingTests bool
GenerateTestResult bool
RunIndependentElasticAgent bool
DeferCleanup time.Duration
WithCoverage bool
CoverageType string
FailOnMissingTests bool
GenerateTestResult bool
DeferCleanup time.Duration
WithCoverage bool
CoverageType string
}

func NewSystemTestRunner(options SystemTestRunnerOptions) *runner {
r := runner{
packageRootPath: options.PackageRootPath,
kibanaClient: options.KibanaClient,
esAPI: options.API,
profile: options.Profile,
dataStreams: options.DataStreams,
serviceVariant: options.ServiceVariant,
configFilePath: options.ConfigFilePath,
runSetup: options.RunSetup,
runTestsOnly: options.RunTestsOnly,
runTearDown: options.RunTearDown,
failOnMissingTests: options.FailOnMissingTests,
generateTestResult: options.GenerateTestResult,
runIndependentElasticAgent: options.RunIndependentElasticAgent,
deferCleanup: options.DeferCleanup,
globalTestConfig: options.GlobalTestConfig,
withCoverage: options.WithCoverage,
coverageType: options.CoverageType,
packageRootPath: options.PackageRootPath,
kibanaClient: options.KibanaClient,
esAPI: options.API,
profile: options.Profile,
dataStreams: options.DataStreams,
serviceVariant: options.ServiceVariant,
configFilePath: options.ConfigFilePath,
runSetup: options.RunSetup,
runTestsOnly: options.RunTestsOnly,
runTearDown: options.RunTearDown,
failOnMissingTests: options.FailOnMissingTests,
generateTestResult: options.GenerateTestResult,
deferCleanup: options.DeferCleanup,
globalTestConfig: options.GlobalTestConfig,
withCoverage: options.WithCoverage,
coverageType: options.CoverageType,
}

r.resourcesManager = resources.NewManager()
Expand Down Expand Up @@ -244,22 +241,21 @@ func (r *runner) GetTests(ctx context.Context) ([]testrunner.Tester, error) {
for _, config := range cfgFiles {
logger.Debugf("System runner: data stream %q config file %q variant %q", t.DataStream, config, variant)
tester, err := NewSystemTester(SystemTesterOptions{
Profile: r.profile,
PackageRootPath: r.packageRootPath,
KibanaClient: r.kibanaClient,
API: r.esAPI,
TestFolder: t,
ServiceVariant: variant,
GenerateTestResult: r.generateTestResult,
DeferCleanup: r.deferCleanup,
RunSetup: r.runSetup,
RunTestsOnly: r.runTestsOnly,
RunTearDown: r.runTearDown,
ConfigFileName: config,
RunIndependentElasticAgent: r.runIndependentElasticAgent,
GlobalTestConfig: r.globalTestConfig,
WithCoverage: r.withCoverage,
CoverageType: r.coverageType,
Profile: r.profile,
PackageRootPath: r.packageRootPath,
KibanaClient: r.kibanaClient,
API: r.esAPI,
TestFolder: t,
ServiceVariant: variant,
GenerateTestResult: r.generateTestResult,
DeferCleanup: r.deferCleanup,
RunSetup: r.runSetup,
RunTestsOnly: r.runTestsOnly,
RunTearDown: r.runTearDown,
ConfigFileName: config,
GlobalTestConfig: r.globalTestConfig,
WithCoverage: r.withCoverage,
CoverageType: r.coverageType,
})
if err != nil {
return nil, fmt.Errorf(
Expand Down
10 changes: 1 addition & 9 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ type SystemTesterOptions struct {
API *elasticsearch.API
KibanaClient *kibana.Client

RunIndependentElasticAgent bool

DeferCleanup time.Duration
ServiceVariant string
ConfigFileName string
Expand All @@ -198,7 +196,6 @@ func NewSystemTester(options SystemTesterOptions) (*tester, error) {
generateTestResult: options.GenerateTestResult,
esAPI: options.API,
kibanaClient: options.KibanaClient,
runIndependentElasticAgent: options.RunIndependentElasticAgent,
deferCleanup: options.DeferCleanup,
serviceVariant: options.ServiceVariant,
configFileName: options.ConfigFileName,
Expand All @@ -208,6 +205,7 @@ func NewSystemTester(options SystemTesterOptions) (*tester, error) {
globalTestConfig: options.GlobalTestConfig,
withCoverage: options.WithCoverage,
coverageType: options.CoverageType,
runIndependentElasticAgent: true,
}
r.resourcesManager = resources.NewManager()
r.resourcesManager.RegisterProvider(resources.DefaultKibanaProviderName, &resources.KibanaProvider{Client: r.kibanaClient})
Expand Down Expand Up @@ -248,12 +246,6 @@ func NewSystemTester(options SystemTesterOptions) (*tester, error) {
return nil, fmt.Errorf("reading data stream manifest failed: %w", err)
}

// Temporarily until independent Elastic Agents are enabled by default,
// enable independent Elastic Agents if package defines that requires root privileges
if pkg, ds := r.pkgManifest, r.dataStreamManifest; pkg.Agent.Privileges.Root || (ds != nil && ds.Agent.Privileges.Root) {
r.runIndependentElasticAgent = true
}

// If the environment variable is present, it always has preference over the root
// privileges value (if any) defined in the manifest file
v, ok := os.LookupEnv(enableIndependentAgents)
Expand Down

0 comments on commit 24c5fb3

Please sign in to comment.