Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
332 changes: 104 additions & 228 deletions e2e/_suites/fleet/fleet.go

Large diffs are not rendered by default.

44 changes: 3 additions & 41 deletions e2e/_suites/fleet/ingest_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"github.com/elastic/e2e-testing/cli/config"
"github.com/elastic/e2e-testing/internal/common"
"github.com/elastic/e2e-testing/internal/deploy"
"github.com/elastic/e2e-testing/internal/installer"
"github.com/elastic/e2e-testing/internal/kibana"
"github.com/elastic/e2e-testing/internal/shell"
"github.com/elastic/e2e-testing/internal/utils"
log "github.com/sirupsen/logrus"
)

Expand All @@ -32,31 +30,17 @@ func setUpSuite() {
}

common.Provider = shell.GetEnv("PROVIDER", common.Provider)
developerMode := shell.GetEnvBool("DEVELOPER_MODE")
if developerMode {
common.DeveloperMode = shell.GetEnvBool("DEVELOPER_MODE")
if common.DeveloperMode {
log.Info("Running in Developer mode 💻: runtime dependencies between different test runs will be reused to speed up dev cycle")
}

common.InitVersions()

common.KibanaVersion = shell.GetEnv("KIBANA_VERSION", "")
if common.KibanaVersion == "" {
// we want to deploy a released version for Kibana
// if not set, let's use stackVersion
common.KibanaVersion, err = utils.GetElasticArtifactVersion(common.StackVersion)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"version": common.KibanaVersion,
}).Fatal("Failed to get kibana version, aborting")
}
}

imts = IngestManagerTestSuite{
Fleet: &FleetTestSuite{
kibanaClient: kibanaClient,
deployer: deploy.New(common.Provider),
Installers: map[string]installer.ElasticAgentInstaller{}, // do not pre-initialise the map
},
}
}
Expand All @@ -79,8 +63,6 @@ func InitializeIngestManagerTestScenario(ctx *godog.ScenarioContext) {
}

func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
developerMode := shell.GetEnvBool("DEVELOPER_MODE")

ctx.BeforeSuite(func() {
setUpSuite()

Expand Down Expand Up @@ -120,30 +102,10 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
})

ctx.AfterSuite(func() {
if !developerMode {
if !common.DeveloperMode {
log.Debug("Destroying Fleet runtime dependencies")
deployer := deploy.New(common.Provider)
deployer.Destroy()
}

installers := imts.Fleet.Installers
for k, v := range installers {
agentPath := v.BinaryPath
if _, err := os.Stat(agentPath); err == nil {
err = os.Remove(agentPath)
if err != nil {
log.WithFields(log.Fields{
"err": err,
"installer": k,
"path": agentPath,
}).Warn("Elastic Agent binary could not be removed.")
} else {
log.WithFields(log.Fields{
"installer": k,
"path": agentPath,
}).Debug("Elastic Agent binary was removed.")
}
}
}
})
}
33 changes: 14 additions & 19 deletions e2e/_suites/fleet/stand-alone.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func (fts *FleetTestSuite) thereIsNewDataInTheIndexFromAgent() error {
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
minimumHitsCount := 50

result, err := searchAgentData(fts.Hostname, fts.RuntimeDependenciesStartDate, minimumHitsCount, maxTimeout)
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName).WithFlavour(fts.Image)

manifest, _ := fts.deployer.Inspect(agentService)
result, err := searchAgentData(manifest.Hostname, fts.RuntimeDependenciesStartDate, minimumHitsCount, maxTimeout)
if err != nil {
return err
}
Expand All @@ -62,11 +65,8 @@ func (fts *FleetTestSuite) thereIsNewDataInTheIndexFromAgent() error {
}

func (fts *FleetTestSuite) theDockerContainerIsStopped(serviceName string) error {
services := []deploy.ServiceRequest{
deploy.NewServiceRequest(common.FleetProfileName),
deploy.NewServiceRequest(serviceName),
}
err := fts.deployer.Remove(services, common.ProfileEnv)
agentService := deploy.NewServiceRequest(serviceName)
err := fts.deployer.Stop(agentService)
if err != nil {
return err
}
Expand All @@ -79,7 +79,9 @@ func (fts *FleetTestSuite) thereIsNoNewDataInTheIndexAfterAgentShutsDown() error
maxTimeout := time.Duration(30) * time.Second
minimumHitsCount := 1

result, err := searchAgentData(fts.Hostname, fts.AgentStoppedDate, minimumHitsCount, maxTimeout)
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
manifest, _ := fts.deployer.Inspect(agentService)
result, err := searchAgentData(manifest.Hostname, fts.AgentStoppedDate, minimumHitsCount, maxTimeout)
if err != nil {
if strings.Contains(err.Error(), "type:index_not_found_exception") {
return err
Expand All @@ -102,14 +104,14 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, flavour string, en

useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS")
beatsLocalPath := shell.GetEnv("BEATS_LOCAL_PATH", "")

if useCISnapshots || beatsLocalPath != "" {
// load the docker images that were already:
// a. downloaded from the GCP bucket
// b. fetched from the local beats binaries
dockerInstaller := installer.GetElasticAgentInstaller("docker", image, common.BeatVersion, deployedAgentsCount)

dockerInstaller.PreInstallFn()

agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
dockerInstaller, _ := installer.Attach(fts.deployer, agentService, "docker")
dockerInstaller.Preinstall()
dockerImageTag += "-amd64"
}

Expand Down Expand Up @@ -140,14 +142,7 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, flavour string, en
return err
}

// get container hostname once
hostname, err := deploy.GetContainerHostname(containerName)
if err != nil {
return err
}

fts.Image = image
fts.Hostname = hostname

err = fts.installTestTools(containerName)
if err != nil {
Expand Down Expand Up @@ -208,7 +203,7 @@ func (fts *FleetTestSuite) installTestTools(containerName string) error {
"containerName": containerName,
}).Trace("Installing test tools ")

_, err := deploy.ExecCommandIntoContainer(context.Background(), deploy.NewServiceRequest(containerName), "root", cmd)
_, err := deploy.ExecCommandIntoContainer(context.Background(), containerName, "root", cmd)
if err != nil {
log.WithFields(log.Fields{
"command": cmd,
Expand Down
27 changes: 24 additions & 3 deletions e2e/_suites/fleet/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ type IngestManagerTestSuite struct {
}

func (imts *IngestManagerTestSuite) processStateOnTheHost(process string, state string) error {
return imts.thereAreInstancesOfTheProcessInTheState("1", process, state)
ocurrences := "1"
if state == "uninstalled" || state == "stopped" {
ocurrences = "0"
}
return imts.thereAreInstancesOfTheProcessInTheState(ocurrences, process, state)
}

func (imts *IngestManagerTestSuite) thereAreInstancesOfTheProcessInTheState(ocurrences string, process string, state string) error {
Expand All @@ -34,8 +38,9 @@ func (imts *IngestManagerTestSuite) thereAreInstancesOfTheProcessInTheState(ocur
if imts.Fleet.StandAlone {
containerName = fmt.Sprintf("%s_%s_%d", profile, common.ElasticAgentServiceName, 1)
} else {
agentInstaller := imts.Fleet.getInstaller()
containerName = imts.Fleet.getContainerName(agentInstaller)
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
manifest, _ := imts.Fleet.deployer.Inspect(agentService)
containerName = manifest.Name
}

count, err := strconv.Atoi(ocurrences)
Expand Down Expand Up @@ -100,6 +105,22 @@ func waitForProcess(deployer deploy.Deployment, service string, process string,
cmds := []string{"pgrep", "-d", ",", process}
output, err := deployer.ExecIn(serviceRequest, cmds)
if err != nil {

if !mustBePresent && ocurrences == 0 {
log.WithFields(log.Fields{
"cmds": cmds,
"desiredState": desiredState,
"elapsedTime": exp.GetElapsedTime(),
"error": err,
"service": service,
"mustBePresent": mustBePresent,
"ocurrences": ocurrences,
"process": process,
"retry": retryCount,
}).Warn("Process is not present and number of occurences is 0")
return nil
}

log.WithFields(log.Fields{
"cmds": cmds,
"desiredState": desiredState,
Expand Down
37 changes: 30 additions & 7 deletions internal/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ const FleetProfileName = "fleet"
// FleetServerAgentServiceName the name of the service for the Elastic Agent
const FleetServerAgentServiceName = "fleet-server"

// AgentStaleVersion is the version of the agent to use as a base during upgrade
// It can be overriden by ELASTIC_AGENT_STALE_VERSION env var. Using latest GA as a default.
var AgentStaleVersion = "7.13-SNAPSHOT"

// BeatVersionBase is the base version of the Beat to use
var BeatVersionBase = "7.13.0-SNAPSHOT"

// BeatVersion is the version of the Beat to use
// It can be overriden by BEAT_VERSION env var
var BeatVersion = BeatVersionBase

// AgentStaleVersion is the version of the agent to use as a base during upgrade
// It can be overriden by ELASTIC_AGENT_STALE_VERSION env var. Using latest GA as a default.
var AgentStaleVersion = "7.12-SNAPSHOT"

// StackVersion is the version of the stack to use
// It can be overriden by STACK_VERSION env var
var StackVersion = BeatVersionBase
// DeveloperMode if enabled will keep deployments around after test runs
var DeveloperMode = false

// KibanaVersion is the version of kibana to use
// It can be override by KIBANA_VERSION
Expand All @@ -54,6 +53,10 @@ var ProfileEnv map[string]string
// Provider is the deployment provider used, currently docker is supported
var Provider = "docker"

// StackVersion is the version of the stack to use
// It can be overriden by STACK_VERSION env var
var StackVersion = BeatVersionBase

// InitVersions initialise default versions. We do not want to do it in the init phase
// supporting lazy-loading the versions when needed. Basically, the CLI part does not
// need to load them
Expand Down Expand Up @@ -91,4 +94,24 @@ func InitVersions() {
}).Fatal("Failed to get stack version, aborting")
}
StackVersion = v

KibanaVersion = shell.GetEnv("KIBANA_VERSION", "")
if KibanaVersion == "" {
// we want to deploy a released version for Kibana
// if not set, let's use StackVersion
KibanaVersion, err = utils.GetElasticArtifactVersion(StackVersion)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"version": KibanaVersion,
}).Fatal("Failed to get kibana version, aborting")
}
}

log.WithFields(log.Fields{
"BeatVersionBase": BeatVersionBase,
"BeatVersion": BeatVersion,
"StackVersion": StackVersion,
"KibanaVersion": KibanaVersion,
}).Trace("Initial artifact versions defined")
}
28 changes: 28 additions & 0 deletions internal/deploy/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,47 @@ import (
// required for testing
type Deployment interface {
Add(services []ServiceRequest, env map[string]string) error // adds a service to deployment
AddFiles(service ServiceRequest, files []string) error // adds files to a service
Bootstrap(waitCB func() error) error // will bootstrap or reuse existing cluster if kubernetes is selected
Destroy() error // Teardown deployment
ExecIn(service ServiceRequest, cmd []string) (string, error) // Execute arbitrary commands in service
Inspect(service ServiceRequest) (*ServiceManifest, error) // inspects service
Logs(service ServiceRequest) error // prints logs of deployed service
Remove(services []ServiceRequest, env map[string]string) error // Removes services from deployment
Start(service ServiceRequest) error // Starts a service or container depending on Deployment
Stop(service ServiceRequest) error // Stop a service or container depending on deployment
}

// ServiceOperator represents the operations that can be performed by a service
type ServiceOperator interface {
AddFiles(files []string) error // adds files to service environment
Enroll(token string) error // handle any enrollment/registering of service
Exec(args []string) (string, error) // exec arbitrary commands in service environment
Inspect() (ServiceOperatorManifest, error) // returns manifest for package
Install() error
InstallCerts() error
Logs() error
Postinstall() error
Preinstall() error
Start() error // will start a service
Stop() error // will stop a service
Uninstall() error
}

// ServiceOperatorManifest is state information for each service operator
type ServiceOperatorManifest struct {
CommitFile string
WorkDir string
}

// ServiceManifest information about a service in a deployment
type ServiceManifest struct {
ID string
Name string
Connection string // a string representing how to connect to service
Alias string // container network aliases
Hostname string
Platform string // running in linux, macos, windows
}

// ServiceRequest represents the service to be created using the provider
Expand Down
Loading