Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.
Closed
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
77 changes: 71 additions & 6 deletions e2e/_suites/fleet/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"github.com/google/uuid"

"github.com/cenkalti/backoff/v4"
"github.com/cucumber/godog"
"github.com/elastic/e2e-testing/internal/common"
Expand Down Expand Up @@ -41,10 +43,21 @@ type FleetTestSuite struct {
Installers map[string]installer.ElasticAgentInstaller
Integration kibana.IntegrationPackage // the installed integration
Policy kibana.Policy
<<<<<<< HEAD
FleetPolicy kibana.Policy
=======
>>>>>>> 82380ced... chore: remove unused code (#1119)
PolicyUpdatedAt string // the moment the policy was updated
FleetServerPolicy kibana.Policy
Version string // current elastic-agent version
kibanaClient *kibana.Client
<<<<<<< HEAD
=======

// date controls for queries
AgentStoppedDate time.Time
RuntimeDependenciesStartDate time.Time
>>>>>>> 82380ced... chore: remove unused code (#1119)
}

// afterScenario destroys the state created by a scenario
Expand Down Expand Up @@ -96,6 +109,7 @@ func (fts *FleetTestSuite) afterScenario() {
}).Warn("The enrollment token could not be deleted")
}

<<<<<<< HEAD
// Cleanup all package policies
packagePolicies, err := fts.kibanaClient.ListPackagePolicies()
if err != nil {
Expand All @@ -116,12 +130,19 @@ func (fts *FleetTestSuite) afterScenario() {
}
}
}
=======
fts.kibanaClient.DeleteAllPolicies()
>>>>>>> 82380ced... chore: remove unused code (#1119)

// clean up fields
fts.CurrentTokenID = ""
fts.CurrentToken = ""
fts.Image = ""
fts.Hostname = ""
<<<<<<< HEAD
=======
fts.StandAlone = false
>>>>>>> 82380ced... chore: remove unused code (#1119)
}

// beforeScenario creates the state needed by a scenario
Expand All @@ -139,6 +160,7 @@ func (fts *FleetTestSuite) beforeScenario() {

}
fts.Policy = policy
<<<<<<< HEAD

fleetPolicy, err := fts.kibanaClient.GetDefaultPolicy(true)
if err != nil {
Expand All @@ -148,6 +170,8 @@ func (fts *FleetTestSuite) beforeScenario() {
}
fts.FleetPolicy = fleetPolicy

=======
>>>>>>> 82380ced... chore: remove unused code (#1119)
}

func (fts *FleetTestSuite) contributeSteps(s *godog.ScenarioContext) {
Expand Down Expand Up @@ -296,15 +320,14 @@ func (fts *FleetTestSuite) agentInVersion(version string) error {

// supported installers: tar, systemd
func (fts *FleetTestSuite) anAgentIsDeployedToFleetWithInstaller(image string, installerType string) error {
return fts.anAgentIsDeployedToFleetWithInstallerAndFleetServer(image, installerType, false)
return fts.anAgentIsDeployedToFleetWithInstallerAndFleetServer(image, installerType)
}

func (fts *FleetTestSuite) anAgentIsDeployedToFleetWithInstallerAndFleetServer(image string, installerType string, bootstrapFleetServer bool) error {
func (fts *FleetTestSuite) anAgentIsDeployedToFleetWithInstallerAndFleetServer(image string, installerType string) error {
log.WithFields(log.Fields{
"bootstrapFleetServer": bootstrapFleetServer,
"image": image,
"installer": installerType,
}).Trace("Deploying an agent to Fleet with base image and fleet server")
"image": image,
"installer": installerType,
}).Trace("Deploying an agent to Fleet with base image using an already bootstrapped Fleet Server")

fts.Image = image
fts.InstallerType = installerType
Expand All @@ -313,19 +336,28 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleetWithInstallerAndFleetServer(i

profile := agentInstaller.Profile // name of the runtime dependencies compose file

<<<<<<< HEAD
serviceName := common.ElasticAgentServiceName // name of the service
containerName := fmt.Sprintf("%s_%s_%s_%d", profile, fts.Image+"-systemd", serviceName, 1) // name of the container

// enroll the agent with a new token
enrollmentKey, err := fts.kibanaClient.CreateEnrollmentAPIKey(fts.FleetPolicy)
=======
// enroll the agent with a new token
enrollmentKey, err := fts.kibanaClient.CreateEnrollmentAPIKey(fts.Policy)
>>>>>>> 82380ced... chore: remove unused code (#1119)
if err != nil {
return err
}
fts.CurrentToken = enrollmentKey.APIKey
fts.CurrentTokenID = enrollmentKey.ID

var fleetConfig *kibana.FleetConfig
<<<<<<< HEAD
fleetConfig, err = deployAgentToFleet(agentInstaller, containerName, fts.CurrentToken, bootstrapFleetServer)
=======
fleetConfig, err = deployAgentToFleet(agentInstaller, containerName, fts.CurrentToken)
>>>>>>> 82380ced... chore: remove unused code (#1119)

fts.Cleanup = true
if err != nil {
Expand All @@ -351,6 +383,10 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleetWithInstallerAndFleetServer(i
}

func (fts *FleetTestSuite) getInstaller() installer.ElasticAgentInstaller {
<<<<<<< HEAD
=======
key := fmt.Sprintf("%s-%s-%s", fts.Image, fts.InstallerType, fts.Version)
>>>>>>> 82380ced... chore: remove unused code (#1119)
// check if the agent is already cached
if i, exists := fts.Installers[fts.Image+"-"+fts.InstallerType+"-"+fts.Version]; exists {
return i
Expand Down Expand Up @@ -646,7 +682,11 @@ func (fts *FleetTestSuite) theAgentIsReenrolledOnTheHost() error {
// during an unenroll the fleet server exits as there is no longer
// and agent id associated with the enrollment. When fleet server
// restarts it needs a new agent to associate with the boostrap
<<<<<<< HEAD
cfg, err := kibana.NewFleetConfig(fts.CurrentToken, true, false)
=======
cfg, err := kibana.NewFleetConfig(fts.CurrentToken)
>>>>>>> 82380ced... chore: remove unused code (#1119)
if err != nil {
return err
}
Expand Down Expand Up @@ -678,6 +718,7 @@ func (fts *FleetTestSuite) theEnrollmentTokenIsRevoked() error {
return nil
}

<<<<<<< HEAD
func (fts *FleetTestSuite) thePolicyShowsTheDatasourceAdded(packageName string) error {
log.WithFields(log.Fields{
"policyID": fts.FleetPolicy.ID,
Expand Down Expand Up @@ -712,6 +753,10 @@ func (fts *FleetTestSuite) thePolicyShowsTheDatasourceAdded(packageName string)
}

return nil
=======
func (fts *FleetTestSuite) theIntegrationIsOperatedInThePolicy(packageName string, action string) error {
return theIntegrationIsOperatedInThePolicy(fts.kibanaClient, fts.Policy, packageName, action)
>>>>>>> 82380ced... chore: remove unused code (#1119)
}

func (fts *FleetTestSuite) theIntegrationIsOperatedInThePolicy(packageName string, action string) error {
Expand Down Expand Up @@ -937,7 +982,11 @@ func (fts *FleetTestSuite) thePolicyIsUpdatedToHaveMode(name string, mode string
return godog.ErrPending
}

<<<<<<< HEAD
packageDS, err := fts.kibanaClient.GetIntegrationFromAgentPolicy("endpoint", fts.FleetPolicy)
=======
packageDS, err := fts.kibanaClient.GetIntegrationFromAgentPolicy("endpoint", fts.Policy)
>>>>>>> 82380ced... chore: remove unused code (#1119)

if err != nil {
return err
Expand Down Expand Up @@ -971,7 +1020,11 @@ func (fts *FleetTestSuite) thePolicyWillReflectTheChangeInTheSecurityApp() error
return err
}

<<<<<<< HEAD
pkgPolicy, err := fts.kibanaClient.GetIntegrationFromAgentPolicy("endpoint", fts.FleetPolicy)
=======
pkgPolicy, err := fts.kibanaClient.GetIntegrationFromAgentPolicy("endpoint", fts.Policy)
>>>>>>> 82380ced... chore: remove unused code (#1119)
if err != nil {
return err
}
Expand Down Expand Up @@ -1039,7 +1092,11 @@ func (fts *FleetTestSuite) anAttemptToEnrollANewAgentFails() error {

containerName := fmt.Sprintf("%s_%s_%s_%d", profile, fts.Image+"-systemd", common.ElasticAgentServiceName, 2) // name of the new container

<<<<<<< HEAD
fleetConfig, err := deployAgentToFleet(agentInstaller, containerName, fts.CurrentToken, false)
=======
fleetConfig, err := deployAgentToFleet(agentInstaller, containerName, fts.CurrentToken)
>>>>>>> 82380ced... chore: remove unused code (#1119)
// the installation process for TAR includes the enrollment
if agentInstaller.InstallerType != "tar" {
if err != nil {
Expand Down Expand Up @@ -1177,7 +1234,11 @@ func (fts *FleetTestSuite) checkDataStream() error {
return err
}

<<<<<<< HEAD
func deployAgentToFleet(agentInstaller installer.ElasticAgentInstaller, containerName string, token string, bootstrapFleetServer bool) (*kibana.FleetConfig, error) {
=======
func deployAgentToFleet(agentInstaller installer.ElasticAgentInstaller, containerName string, token string) (*kibana.FleetConfig, error) {
>>>>>>> 82380ced... chore: remove unused code (#1119)
profile := agentInstaller.Profile // name of the runtime dependencies compose file
service := agentInstaller.Service // name of the service
serviceTag := agentInstaller.Tag // docker tag of the service
Expand Down Expand Up @@ -1208,7 +1269,11 @@ func deployAgentToFleet(agentInstaller installer.ElasticAgentInstaller, containe
return nil, err
}

<<<<<<< HEAD
cfg, cfgError := kibana.NewFleetConfig(token, bootstrapFleetServer, false)
=======
cfg, cfgError := kibana.NewFleetConfig(token)
>>>>>>> 82380ced... chore: remove unused code (#1119)
if cfgError != nil {
return nil, cfgError
}
Expand Down
33 changes: 33 additions & 0 deletions e2e/_suites/fleet/stand-alone.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func (sats *StandAloneTestSuite) afterScenario() {
if log.IsLevelEnabled(log.DebugLevel) {
_ = sats.getContainerLogs()
}
<<<<<<< HEAD
=======

fts.FleetServerPolicy = fleetPolicy
return fts.startStandAloneAgent(image, "", map[string]string{"fleetServerMode": "1"})
}
>>>>>>> 82380ced... chore: remove unused code (#1119)

developerMode := shell.GetEnvBool("DEVELOPER_MODE")
if !developerMode {
Expand Down Expand Up @@ -157,11 +164,37 @@ func (sats *StandAloneTestSuite) startAgent(image string, env map[string]string)
return nil
}

<<<<<<< HEAD
func (sats *StandAloneTestSuite) getContainerLogs() error {
serviceManager := compose.NewServiceManager()

profile := common.FleetProfileName
serviceName := common.ElasticAgentServiceName
=======
func (fts *FleetTestSuite) thePolicyShowsTheDatasourceAdded(packageName string) error {
log.WithFields(log.Fields{
"policyID": fts.Policy.ID,
"package": packageName,
}).Trace("Checking if the policy shows the package added")

maxTimeout := time.Minute
retryCount := 1

exp := common.GetExponentialBackOff(maxTimeout)

configurationIsPresentFn := func() error {
packagePolicy, err := fts.kibanaClient.GetIntegrationFromAgentPolicy(packageName, fts.Policy)
if err != nil {
log.WithFields(log.Fields{
"packagePolicy": packagePolicy,
"policy": fts.Policy,
"retry": retryCount,
"error": err,
}).Warn("The integration was not found in the policy")
retryCount++
return err
}
>>>>>>> 82380ced... chore: remove unused code (#1119)

composes := []string{
profile, // profile name
Expand Down
4 changes: 4 additions & 0 deletions internal/installer/elasticagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func GetElasticAgentInstaller(image string, installerType string, version string
log.WithFields(log.Fields{
"image": image,
"installer": installerType,
<<<<<<< HEAD
=======
"version": version,
>>>>>>> 82380ced... chore: remove unused code (#1119)
}).Debug("Configuring installer for the agent")

var installer ElasticAgentInstaller
Expand Down
4 changes: 4 additions & 0 deletions internal/installer/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (i *TARPackage) WithVersion(version string) *TARPackage {
// newTarInstaller returns an instance of the Debian installer for a specific version
func newTarInstaller(image string, tag string, version string) (ElasticAgentInstaller, error) {
dockerImage := image + "-systemd" // we want to consume systemd boxes
<<<<<<< HEAD
=======

>>>>>>> 82380ced... chore: remove unused code (#1119)
service := dockerImage
profile := common.FleetProfileName

Expand Down
31 changes: 28 additions & 3 deletions internal/kibana/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package kibana
import (
"fmt"

"github.com/elastic/e2e-testing/internal/common"
log "github.com/sirupsen/logrus"
)

Expand All @@ -21,6 +20,7 @@ type FleetConfig struct {
KibanaURI string
FleetServerPort int
FleetServerURI string
<<<<<<< HEAD
// server
BootstrapFleetServer bool
ServerPolicyID string
Expand All @@ -32,15 +32,21 @@ type FleetConfig struct {
// If the 'fleetServerMode' flag is true, the it will create the config for an agent using an existing Fleet
// Server to connect to Fleet. It will also retrieve the default policy ID for fleet server
func NewFleetConfig(token string, bootstrapFleetServer bool, fleetServerMode bool) (*FleetConfig, error) {
=======
}

// NewFleetConfig builds a new configuration for the fleet agent, defaulting fleet-server host, ES credentials, URI and port.
func NewFleetConfig(token string) (*FleetConfig, error) {
>>>>>>> 82380ced... chore: remove unused code (#1119)
cfg := &FleetConfig{
BootstrapFleetServer: bootstrapFleetServer,
EnrollmentToken: token,
ElasticsearchCredentials: "elastic:changeme",
ElasticsearchPort: 9200,
ElasticsearchURI: "elasticsearch",
KibanaPort: 5601,
KibanaURI: "kibana",
FleetServerPort: 8220,
<<<<<<< HEAD
FleetServerURI: "localhost",
}

Expand All @@ -64,12 +70,23 @@ func NewFleetConfig(token string, bootstrapFleetServer bool, fleetServerMode boo
"token": cfg.EnrollmentToken,
}).Debug("Fleet Server config created")
}
=======
FleetServerURI: "fleet-server",
}

log.WithFields(log.Fields{
"elasticsearch": cfg.ElasticsearchURI,
"elasticsearchPort": cfg.ElasticsearchPort,
"token": cfg.EnrollmentToken,
}).Debug("Fleet Server config created")
>>>>>>> 82380ced... chore: remove unused code (#1119)

return cfg, nil
}

// Flags bootstrap flags for fleet server
func (cfg FleetConfig) Flags() []string {
<<<<<<< HEAD
if cfg.BootstrapFleetServer {
// TO-DO: remove all code to calculate the fleet-server policy, because it's inferred by the fleet-server
return []string{
Expand All @@ -78,6 +95,8 @@ func (cfg FleetConfig) Flags() []string {
}
}

=======
>>>>>>> 82380ced... chore: remove unused code (#1119)
/*
// agent using an already bootstrapped fleet-server
fleetServerHost := "https://hostname_of_the_bootstrapped_fleet_server:8220"
Expand All @@ -89,14 +108,20 @@ func (cfg FleetConfig) Flags() []string {
}
*/

<<<<<<< HEAD
baseFlags := []string{"-e", "-v", "--force", "--insecure", "--enrollment-token=" + cfg.EnrollmentToken}
if common.AgentVersionBase == "7.13.0-SNAPSHOT" {
return append(baseFlags, "--url", fmt.Sprintf("http://%s@%s:%d", cfg.ElasticsearchCredentials, cfg.FleetServerURI, cfg.FleetServerPort))
}

if cfg.ServerPolicyID != "" {
baseFlags = append(baseFlags, "--fleet-server-insecure-http", "--fleet-server", fmt.Sprintf("http://%s@%s:%d", cfg.ElasticsearchCredentials, cfg.ElasticsearchURI, cfg.ElasticsearchPort), "--fleet-server-host=http://0.0.0.0", "--fleet-server-policy", cfg.ServerPolicyID)
=======
flags := []string{
"-e", "-v", "--force", "--insecure", "--enrollment-token=" + cfg.EnrollmentToken,
"--url", fmt.Sprintf("http://%s:%d", cfg.FleetServerURI, cfg.FleetServerPort),
>>>>>>> 82380ced... chore: remove unused code (#1119)
}

return append(baseFlags, "--kibana-url", fmt.Sprintf("http://%s@%s:%d", cfg.ElasticsearchCredentials, cfg.KibanaURI, cfg.KibanaPort))
return flags
}
Loading