From 00a568dcad6eaeb49af6c78098366444d27a1b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 13 Apr 2021 15:39:55 +0200 Subject: [PATCH] fix: delay checking stale agent version until it's used (#1016) * fix: delay checking stale agent version until it's used * fix: use proper kibana version * chore: handle errors in the caller when the version is not found - in setup methods, we want to fail (log.Fatal) - in steps, we want to simply return the error to fail the scenario --- e2e/_suites/fleet/fleet.go | 18 +++++++++ e2e/_suites/fleet/ingest_manager_test.go | 45 +++++++++++++++-------- e2e/_suites/helm/helm_charts_test.go | 9 ++++- e2e/_suites/metricbeat/metricbeat_test.go | 18 ++++++++- e2e/utils.go | 14 +++---- 5 files changed, 76 insertions(+), 28 deletions(-) diff --git a/e2e/_suites/fleet/fleet.go b/e2e/_suites/fleet/fleet.go index 7e00ea1b8d..e3344c12a8 100644 --- a/e2e/_suites/fleet/fleet.go +++ b/e2e/_suites/fleet/fleet.go @@ -15,6 +15,7 @@ import ( "github.com/cucumber/godog" "github.com/elastic/e2e-testing/cli/services" curl "github.com/elastic/e2e-testing/cli/shell" + shell "github.com/elastic/e2e-testing/cli/shell" "github.com/elastic/e2e-testing/e2e" "github.com/elastic/e2e-testing/e2e/steps" "github.com/google/uuid" @@ -166,6 +167,23 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(image, ver agentVersionBackup := fts.Version defer func() { fts.Version = agentVersionBackup }() + agentStaleVersion = shell.GetEnv("ELASTIC_AGENT_STALE_VERSION", agentStaleVersion) + // check if stale version is an alias + v, err := e2e.GetElasticArtifactVersion(agentStaleVersion) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": agentStaleVersion, + }).Error("Failed to get stale version") + return err + } + agentStaleVersion = v + + useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS") + if useCISnapshots && !strings.HasSuffix(agentStaleVersion, "-SNAPSHOT") { + agentStaleVersion += "-SNAPSHOT" + } + switch version { case "stale": version = agentStaleVersion diff --git a/e2e/_suites/fleet/ingest_manager_test.go b/e2e/_suites/fleet/ingest_manager_test.go index 69b3844d12..105ccc1131 100644 --- a/e2e/_suites/fleet/ingest_manager_test.go +++ b/e2e/_suites/fleet/ingest_manager_test.go @@ -32,31 +32,43 @@ func setUpSuite() { } // check if base version is an alias - agentVersionBase = e2e.GetElasticArtifactVersion(agentVersionBase) + v, err := e2e.GetElasticArtifactVersion(agentVersionBase) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": agentVersionBase, + }).Fatal("Failed to get agent base version, aborting") + } + agentVersionBase = v timeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", timeoutFactor) agentVersion = shell.GetEnv("BEAT_VERSION", agentVersionBase) - agentStaleVersion = shell.GetEnv("ELASTIC_AGENT_STALE_VERSION", agentStaleVersion) - // check if stale version is an alias - agentStaleVersion = e2e.GetElasticArtifactVersion(agentStaleVersion) - - useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS") - if useCISnapshots && !strings.HasSuffix(agentStaleVersion, "-SNAPSHOT") { - agentStaleVersion += "-SNAPSHOT" - } - // check if version is an alias - agentVersion = e2e.GetElasticArtifactVersion(agentVersion) + v, err = e2e.GetElasticArtifactVersion(agentVersion) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": agentVersion, + }).Fatal("Failed to get agent version, aborting") + } + agentVersion = v stackVersion = shell.GetEnv("STACK_VERSION", stackVersion) - stackVersion = e2e.GetElasticArtifactVersion(stackVersion) + v, err = e2e.GetElasticArtifactVersion(stackVersion) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": stackVersion, + }).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 = e2e.GetElasticArtifactVersion(stackVersion) + kibanaVersion = stackVersion } imts = IngestManagerTestSuite{ @@ -107,9 +119,10 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) { "stackVersion": stackVersion, } - profileEnv["kibanaDockerNamespace"] = "observability-ci" - if kibanaVersion == "" { - profileEnv["kibanaDockerNamespace"] = "kibana" + profileEnv["kibanaDockerNamespace"] = "kibana" + if strings.HasPrefix(kibanaVersion, "pr") { + // because it comes from a PR + profileEnv["kibanaDockerNamespace"] = "observability-ci" } profile := FleetProfileName diff --git a/e2e/_suites/helm/helm_charts_test.go b/e2e/_suites/helm/helm_charts_test.go index a6c6ab7114..53eacd3fb8 100644 --- a/e2e/_suites/helm/helm_charts_test.go +++ b/e2e/_suites/helm/helm_charts_test.go @@ -81,7 +81,14 @@ func setupSuite() { timeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", timeoutFactor) stackVersion = shell.GetEnv("STACK_VERSION", stackVersion) - stackVersion = e2e.GetElasticArtifactVersion(stackVersion) + v, err := e2e.GetElasticArtifactVersion(stackVersion) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": stackVersion, + }).Fatal("Failed to get stack version, aborting") + } + stackVersion = v h, err := k8s.HelmFactory(helmVersion) if err != nil { diff --git a/e2e/_suites/metricbeat/metricbeat_test.go b/e2e/_suites/metricbeat/metricbeat_test.go index e8a3c03631..a8d14cce17 100644 --- a/e2e/_suites/metricbeat/metricbeat_test.go +++ b/e2e/_suites/metricbeat/metricbeat_test.go @@ -69,13 +69,27 @@ func setupSuite() { } // check if base version is an alias - metricbeatVersionBase = e2e.GetElasticArtifactVersion(metricbeatVersionBase) + v, err := e2e.GetElasticArtifactVersion(metricbeatVersionBase) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": metricbeatVersionBase, + }).Fatal("Failed to get metricbeat base version, aborting") + } + metricbeatVersionBase = v metricbeatVersion = shell.GetEnv("BEAT_VERSION", metricbeatVersionBase) timeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", timeoutFactor) stackVersion = shell.GetEnv("STACK_VERSION", stackVersion) - stackVersion = e2e.GetElasticArtifactVersion(stackVersion) + v, err = e2e.GetElasticArtifactVersion(stackVersion) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "version": stackVersion, + }).Fatal("Failed to get stack version, aborting") + } + stackVersion = v serviceManager = services.NewServiceManager() diff --git a/e2e/utils.go b/e2e/utils.go index 6ccfaa5c27..1d67b7ca32 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -194,7 +194,7 @@ func GetExponentialBackOff(elapsedTime time.Duration) *backoff.ExponentialBackOf // 1. Elastic's artifact repository, building the JSON path query based // If the version is a PR, then it will return the version without checking the artifacts API // i.e. GetElasticArtifactVersion("$VERSION") -func GetElasticArtifactVersion(version string) string { +func GetElasticArtifactVersion(version string) (string, error) { exp := GetExponentialBackOff(time.Minute) retryCount := 1 @@ -233,11 +233,7 @@ func GetElasticArtifactVersion(version string) string { err := backoff.Retry(apiStatus, exp) if err != nil { - log.WithFields(log.Fields{ - "error": err, - "version": version, - }).Fatal("Failed to get version, aborting") - return "" + return "", err } jsonParsed, err := gabs.ParseJSON([]byte(body)) @@ -245,8 +241,8 @@ func GetElasticArtifactVersion(version string) string { log.WithFields(log.Fields{ "error": err, "version": version, - }).Fatal("Could not parse the response body to retrieve the version, aborting") - return "" + }).Error("Could not parse the response body to retrieve the version") + return "", err } builds := jsonParsed.Path("version.builds") @@ -259,7 +255,7 @@ func GetElasticArtifactVersion(version string) string { "version": latestVersion, }).Debug("Latest version for current version obtained") - return latestVersion + return latestVersion, nil } // GetElasticArtifactURL returns the URL of a released artifact, which its full name is defined in the first argument,