Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 4c3d3eb

Browse files
authored
feat: simplify the initialisation of versions (#1159)
* chore: use fixed version in shell scripts * chore: move retry to utils We could move it to its own package, but at this moment it's very small * chore: initialise stackVesion at one single place * chore: initialise agent version base at one single place * chore: initialise agent version at one single place * chore: reduce the number of requests to Elastic's artifacts endpoint * chore: rename AgentVersionBase variable to BeatVersionBase * chore: rename AgentVersion variable to BeatVersion * chore: use Beat version in metricbeat test suite * chore: check if the version must use the fallback after coming from a Git SHA
1 parent 8bd01f1 commit 4c3d3eb

24 files changed

Lines changed: 179 additions & 191 deletions

File tree

.ci/scripts/clean-docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -euxo pipefail
99
# Build and test the app using the install and test make goals.
1010
#
1111

12-
readonly VERSION="8.0.0-SNAPSHOT"
12+
readonly VERSION="$(cat $(pwd)/.stack-version)"
1313

1414
main() {
1515
# refresh docker images

.ci/scripts/fleet-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ set -euxo pipefail
99
# Run the functional tests for fleets using the functional-test wrapper
1010
#
1111
# Parameters:
12-
# - STACK_VERSION - that's the version of the stack to be tested. Default '8.0.0-SNAPSHOT'.
12+
# - STACK_VERSION - that's the version of the stack to be tested. Default is stored in '.stack-version'.
1313
#
1414

15-
STACK_VERSION=${1:-'8.0.0-SNAPSHOT'}
15+
STACK_VERSION=${1:-"$(cat $(pwd)/.stack-version)"}
1616
SUITE='fleet'
1717

1818
# Exclude the nightly tests in the CI.

.ci/scripts/functional-test.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ set -euxo pipefail
1212
# Parameters:
1313
# - SUITE - that's the suite to be tested. Default '' which means all of them.
1414
# - TAGS - that's the tags to be tested. Default '' which means all of them.
15-
# - STACK_VERSION - that's the version of the stack to be tested. Default '8.0.0-SNAPSHOT'.
16-
# - BEAT_VERSION - that's the version of the metricbeat to be tested. Default '8.0.0-SNAPSHOT'.
15+
# - STACK_VERSION - that's the version of the stack to be tested. Default is stored in '.stack-version'.
16+
# - BEAT_VERSION - that's the version of the metricbeat to be tested. Default is stored in '.stack-version'.
1717
#
1818

19+
BASE_VERSION="$(cat $(pwd)/.stack-version)"
20+
1921
SUITE=${1:-''}
2022
TAGS=${2:-''}
21-
STACK_VERSION=${3:-'8.0.0-SNAPSHOT'}
22-
BEAT_VERSION=${4:-'8.0.0-SNAPSHOT'}
23+
STACK_VERSION=${3:-"${BASE_VERSION}"}
24+
BEAT_VERSION=${4:-"${BASE_VERSION}"}
2325

2426
## Install the required dependencies for the given SUITE
2527
.ci/scripts/install-test-dependencies.sh "${SUITE}"

.ci/scripts/metricbeat-test.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ set -euxo pipefail
99
# Run the functional tests for metricbeat using the functional-test wrapper
1010
#
1111
# Parameters:
12-
# - STACK_VERSION - that's the version of the stack to be tested. Default '8.0.0-SNAPSHOT'.
13-
# - BEAT_VERSION - that's the version of the metricbeat to be tested. Default '8.0.0-SNAPSHOT'.
12+
# - STACK_VERSION - that's the version of the stack to be tested. Default is stored in '.stack-version'.
13+
# - BEAT_VERSION - that's the version of the metricbeat to be tested. Default is stored in '.stack-version'.
1414
#
1515

16-
STACK_VERSION=${1:-'8.0.0-SNAPSHOT'}
17-
BEAT_VERSION=${2:-'8.0.0-SNAPSHOT'}
16+
BASE_VERSION="$(cat $(pwd)/.stack-version)"
17+
18+
STACK_VERSION=${1:-"${BASE_VERSION}"}
19+
BEAT_VERSION=${2:-"${BASE_VERSION}"}
1820
SUITE='metricbeat'
1921

2022
.ci/scripts/functional-test.sh "${SUITE}" "" "${STACK_VERSION}" "${BEAT_VERSION}"

.stack-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.0.0-SNAPSHOT

e2e/_suites/fleet/fleet.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (fts *FleetTestSuite) beforeScenario() {
118118
fts.StandAlone = false
119119
fts.ElasticAgentStopped = false
120120

121-
fts.Version = common.AgentVersion
121+
fts.Version = common.BeatVersion
122122

123123
policy, err := fts.kibanaClient.GetDefaultPolicy(false)
124124
if err != nil {
@@ -183,8 +183,8 @@ func (fts *FleetTestSuite) theStandaloneAgentIsListedInFleetWithStatus(desiredSt
183183

184184
return theAgentIsListedInFleetWithStatus(desiredStatus, hostname)
185185
}
186-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute * 2
187-
exp := common.GetExponentialBackOff(maxTimeout)
186+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
187+
exp := utils.GetExponentialBackOff(maxTimeout)
188188

189189
err := backoff.Retry(waitForAgents, exp)
190190
if err != nil {
@@ -218,7 +218,7 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(image, ver
218218
case "stale":
219219
version = common.AgentStaleVersion
220220
case "latest":
221-
version = common.AgentVersion
221+
version = common.BeatVersion
222222
default:
223223
version = common.AgentStaleVersion
224224
}
@@ -240,7 +240,7 @@ func (fts *FleetTestSuite) installCerts() error {
240240
log.WithFields(log.Fields{
241241
"installer": agentInstaller,
242242
"version": fts.Version,
243-
"agentVersion": common.AgentVersion,
243+
"agentVersion": common.BeatVersion,
244244
"agentStaleVersion": common.AgentStaleVersion,
245245
}).Error("No installer found")
246246
return errors.New("no installer found")
@@ -249,7 +249,7 @@ func (fts *FleetTestSuite) installCerts() error {
249249
err := agentInstaller.InstallCertsFn()
250250
if err != nil {
251251
log.WithFields(log.Fields{
252-
"agentVersion": common.AgentVersion,
252+
"agentVersion": common.BeatVersion,
253253
"agentStaleVersion": common.AgentStaleVersion,
254254
"error": err,
255255
"installer": agentInstaller,
@@ -266,9 +266,9 @@ func (fts *FleetTestSuite) anAgentIsUpgraded(desiredVersion string) error {
266266
case "stale":
267267
desiredVersion = common.AgentStaleVersion
268268
case "latest":
269-
desiredVersion = common.AgentVersion
269+
desiredVersion = common.BeatVersion
270270
default:
271-
desiredVersion = common.AgentVersion
271+
desiredVersion = common.BeatVersion
272272
}
273273

274274
return fts.kibanaClient.UpgradeAgent(fts.Hostname, desiredVersion)
@@ -279,7 +279,7 @@ func (fts *FleetTestSuite) agentInVersion(version string) error {
279279
case "stale":
280280
version = common.AgentStaleVersion
281281
case "latest":
282-
version = common.AgentVersion
282+
version = common.BeatVersion
283283
}
284284

285285
agentInVersionFn := func() error {
@@ -300,8 +300,8 @@ func (fts *FleetTestSuite) agentInVersion(version string) error {
300300
return nil
301301
}
302302

303-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute * 2
304-
exp := common.GetExponentialBackOff(maxTimeout)
303+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
304+
exp := utils.GetExponentialBackOff(maxTimeout)
305305

306306
return backoff.Retry(agentInVersionFn, exp)
307307
}
@@ -399,7 +399,7 @@ func (fts *FleetTestSuite) processStateChangedOnTheHost(process string, state st
399399
return err
400400
}
401401

402-
utils.Sleep(time.Duration(common.TimeoutFactor) * 10 * time.Second)
402+
utils.Sleep(time.Duration(utils.TimeoutFactor) * 10 * time.Second)
403403

404404
err = installer.SystemctlRun(profile, agentInstaller.Image, serviceName, "start")
405405
if err != nil {
@@ -441,7 +441,7 @@ func (fts *FleetTestSuite) processStateChangedOnTheHost(process string, state st
441441

442442
containerName := fts.getContainerName(agentInstaller, 1)
443443

444-
return CheckProcessState(fts.deployer, containerName, process, "stopped", 1, common.TimeoutFactor)
444+
return CheckProcessState(fts.deployer, containerName, process, "stopped", 1, utils.TimeoutFactor)
445445
}
446446

447447
func (fts *FleetTestSuite) setup() error {
@@ -466,10 +466,10 @@ func theAgentIsListedInFleetWithStatus(desiredStatus string, hostname string) er
466466
if err != nil {
467467
return err
468468
}
469-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute * 2
469+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
470470
retryCount := 1
471471

472-
exp := common.GetExponentialBackOff(maxTimeout)
472+
exp := utils.GetExponentialBackOff(maxTimeout)
473473

474474
agentOnlineFn := func() error {
475475
agentID, err := kibanaClient.GetAgentIDByHostname(hostname)
@@ -563,7 +563,7 @@ func (fts *FleetTestSuite) theHostIsRestarted() error {
563563
}).Error("Could not stop the service")
564564
}
565565

566-
utils.Sleep(time.Duration(common.TimeoutFactor) * 10 * time.Second)
566+
utils.Sleep(time.Duration(utils.TimeoutFactor) * 10 * time.Second)
567567

568568
_, err = shell.Execute(context.Background(), ".", "docker", "start", containerName)
569569
if err != nil {
@@ -586,10 +586,10 @@ func (fts *FleetTestSuite) systemPackageDashboardsAreListedInFleet() error {
586586
log.Trace("Checking system Package dashboards in Fleet")
587587

588588
dataStreamsCount := 0
589-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute
589+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute
590590
retryCount := 1
591591

592-
exp := common.GetExponentialBackOff(maxTimeout)
592+
exp := utils.GetExponentialBackOff(maxTimeout)
593593

594594
countDataStreamsFn := func() error {
595595
dataStreams, err := fts.kibanaClient.GetDataStreams()
@@ -730,10 +730,10 @@ func theIntegrationIsOperatedInThePolicy(client *kibana.Client, policy kibana.Po
730730
func (fts *FleetTestSuite) theHostNameIsNotShownInTheAdminViewInTheSecurityApp() error {
731731
log.Trace("Checking if the hostname is not shown in the Administration view in the Security App")
732732

733-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute
733+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute
734734
retryCount := 1
735735

736-
exp := common.GetExponentialBackOff(maxTimeout)
736+
exp := utils.GetExponentialBackOff(maxTimeout)
737737

738738
agentListedInSecurityFn := func() error {
739739
host, err := fts.kibanaClient.IsAgentListedInSecurityApp(fts.Hostname)
@@ -770,10 +770,10 @@ func (fts *FleetTestSuite) theHostNameIsNotShownInTheAdminViewInTheSecurityApp()
770770
func (fts *FleetTestSuite) theHostNameIsShownInTheAdminViewInTheSecurityApp(status string) error {
771771
log.Trace("Checking if the hostname is shown in the Admin view in the Security App")
772772

773-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute
773+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute
774774
retryCount := 1
775775

776-
exp := common.GetExponentialBackOff(maxTimeout)
776+
exp := utils.GetExponentialBackOff(maxTimeout)
777777

778778
agentListedInSecurityFn := func() error {
779779
matches, err := fts.kibanaClient.IsAgentListedInSecurityAppWithStatus(fts.Hostname, status)
@@ -825,10 +825,10 @@ func (fts *FleetTestSuite) thePolicyResponseWillBeShownInTheSecurityApp() error
825825
return err
826826
}
827827

828-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute
828+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute
829829
retryCount := 1
830830

831-
exp := common.GetExponentialBackOff(maxTimeout)
831+
exp := utils.GetExponentialBackOff(maxTimeout)
832832

833833
getEventsFn := func() error {
834834
listed, err := fts.kibanaClient.IsPolicyResponseListedInSecurityApp(agentID)
@@ -924,10 +924,10 @@ func (fts *FleetTestSuite) thePolicyWillReflectTheChangeInTheSecurityApp() error
924924
return err
925925
}
926926

927-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute * 2
927+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
928928
retryCount := 1
929929

930-
exp := common.GetExponentialBackOff(maxTimeout)
930+
exp := utils.GetExponentialBackOff(maxTimeout)
931931

932932
getEventsFn := func() error {
933933
err := fts.kibanaClient.GetAgentEvents("endpoint-security", agentID, pkgPolicy.ID, fts.PolicyUpdatedAt)

e2e/_suites/fleet/ingest_manager_test.go

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,7 @@ func setUpSuite() {
3838
log.Info("Running in Developer mode 💻: runtime dependencies between different test runs will be reused to speed up dev cycle")
3939
}
4040

41-
// check if base version is an alias
42-
v, err := utils.GetElasticArtifactVersion(common.AgentVersionBase)
43-
if err != nil {
44-
log.WithFields(log.Fields{
45-
"error": err,
46-
"version": common.AgentVersionBase,
47-
}).Fatal("Failed to get agent base version, aborting")
48-
}
49-
common.AgentVersionBase = v
50-
51-
common.AgentVersion = shell.GetEnv("BEAT_VERSION", common.AgentVersionBase)
52-
53-
// check if version is an alias
54-
v, err = utils.GetElasticArtifactVersion(common.AgentVersion)
55-
if err != nil {
56-
log.WithFields(log.Fields{
57-
"error": err,
58-
"version": common.AgentVersion,
59-
}).Fatal("Failed to get agent version, aborting")
60-
}
61-
common.AgentVersion = v
62-
63-
common.StackVersion = shell.GetEnv("STACK_VERSION", common.StackVersion)
64-
v, err = utils.GetElasticArtifactVersion(common.StackVersion)
65-
if err != nil {
66-
log.WithFields(log.Fields{
67-
"error": err,
68-
"version": common.StackVersion,
69-
}).Fatal("Failed to get stack version, aborting")
70-
}
71-
common.StackVersion = v
41+
common.InitVersions()
7242

7343
common.KibanaVersion = shell.GetEnv("KIBANA_VERSION", "")
7444
if common.KibanaVersion == "" {
@@ -119,12 +89,12 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
11989

12090
if !shell.GetEnvBool("SKIP_PULL") {
12191
images := []string{
122-
"docker.elastic.co/beats/elastic-agent:" + common.AgentVersion,
123-
"docker.elastic.co/beats/elastic-agent-ubi8:" + common.AgentVersion,
92+
"docker.elastic.co/beats/elastic-agent:" + common.BeatVersion,
93+
"docker.elastic.co/beats/elastic-agent-ubi8:" + common.BeatVersion,
12494
"docker.elastic.co/elasticsearch/elasticsearch:" + common.StackVersion,
12595
"docker.elastic.co/kibana/kibana:" + common.KibanaVersion,
126-
"docker.elastic.co/observability-ci/elastic-agent:" + common.AgentVersion,
127-
"docker.elastic.co/observability-ci/elastic-agent-ubi8:" + common.AgentVersion,
96+
"docker.elastic.co/observability-ci/elastic-agent:" + common.BeatVersion,
97+
"docker.elastic.co/observability-ci/elastic-agent-ubi8:" + common.BeatVersion,
12898
"docker.elastic.co/observability-ci/elasticsearch:" + common.StackVersion,
12999
"docker.elastic.co/observability-ci/elasticsearch-ubi8:" + common.StackVersion,
130100
"docker.elastic.co/observability-ci/kibana:" + common.KibanaVersion,
@@ -146,7 +116,7 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
146116
return nil
147117
})
148118

149-
imts.Fleet.Version = common.AgentVersionBase
119+
imts.Fleet.Version = common.BeatVersionBase
150120
imts.Fleet.RuntimeDependenciesStartDate = time.Now().UTC()
151121
})
152122

e2e/_suites/fleet/stand-alone.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (fts *FleetTestSuite) aStandaloneAgentIsDeployedWithFleetServerModeOnCloud(
4848
}
4949

5050
func (fts *FleetTestSuite) thereIsNewDataInTheIndexFromAgent() error {
51-
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute * 2
51+
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
5252
minimumHitsCount := 50
5353

5454
result, err := searchAgentData(fts.Hostname, fts.RuntimeDependenciesStartDate, minimumHitsCount, maxTimeout)
@@ -94,15 +94,15 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, composeFilename st
9494
fts.StandAlone = true
9595
log.Trace("Deploying an agent to Fleet")
9696

97-
dockerImageTag := common.AgentVersion
97+
dockerImageTag := common.BeatVersion
9898

9999
useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS")
100100
beatsLocalPath := shell.GetEnv("BEATS_LOCAL_PATH", "")
101101
if useCISnapshots || beatsLocalPath != "" {
102102
// load the docker images that were already:
103103
// a. downloaded from the GCP bucket
104104
// b. fetched from the local beats binaries
105-
dockerInstaller := installer.GetElasticAgentInstaller("docker", image, common.AgentVersion)
105+
dockerInstaller := installer.GetElasticAgentInstaller("docker", image, common.BeatVersion)
106106

107107
dockerInstaller.PreInstallFn()
108108

@@ -159,7 +159,7 @@ func (fts *FleetTestSuite) thePolicyShowsTheDatasourceAdded(packageName string)
159159
maxTimeout := time.Minute
160160
retryCount := 1
161161

162-
exp := common.GetExponentialBackOff(maxTimeout)
162+
exp := utils.GetExponentialBackOff(maxTimeout)
163163

164164
configurationIsPresentFn := func() error {
165165
packagePolicy, err := fts.kibanaClient.GetIntegrationFromAgentPolicy(packageName, fts.Policy)

e2e/_suites/fleet/world.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cenkalti/backoff/v4"
1414
"github.com/elastic/e2e-testing/internal/common"
1515
"github.com/elastic/e2e-testing/internal/deploy"
16+
"github.com/elastic/e2e-testing/internal/utils"
1617
log "github.com/sirupsen/logrus"
1718
)
1819

@@ -42,14 +43,14 @@ func (imts *IngestManagerTestSuite) thereAreInstancesOfTheProcessInTheState(ocur
4243
return err
4344
}
4445

45-
return CheckProcessState(imts.Fleet.deployer, containerName, process, state, count, common.TimeoutFactor)
46+
return CheckProcessState(imts.Fleet.deployer, containerName, process, state, count, utils.TimeoutFactor)
4647
}
4748

4849
// CheckProcessState checks if a process is in the desired state in a container
4950
// name of the container for the service:
5051
// we are using the underlying deployer to run the commands in the container/service
5152
func CheckProcessState(deployer deploy.Deployment, service string, process string, state string, occurrences int, timeoutFactor int) error {
52-
timeout := time.Duration(common.TimeoutFactor) * time.Minute
53+
timeout := time.Duration(utils.TimeoutFactor) * time.Minute
5354

5455
err := waitForProcess(deployer, service, process, state, occurrences, timeout)
5556
if err != nil {
@@ -76,7 +77,7 @@ func CheckProcessState(deployer deploy.Deployment, service string, process strin
7677
// waitForProcess polls a container executing "ps" command until the process is in the desired state (present or not),
7778
// or a timeout happens
7879
func waitForProcess(deployer deploy.Deployment, service string, process string, desiredState string, ocurrences int, maxTimeout time.Duration) error {
79-
exp := common.GetExponentialBackOff(maxTimeout)
80+
exp := utils.GetExponentialBackOff(maxTimeout)
8081

8182
mustBePresent := false
8283
if desiredState == "started" {

0 commit comments

Comments
 (0)