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

Commit

Permalink
[7.13.x](backport #1256) fix: use beat_version as fallback if it's pr…
Browse files Browse the repository at this point in the history
…ovided (#1261)

* fix: use beat_version as fallback if it's provided (#1256)

* fix: honour beat_version as fallback

* chore: simplify method, as the init versions already checks the beat version

* chore: simplify method even more

(cherry picked from commit 55156f1)

# Conflicts:
#	internal/utils/utils_test.go

* fix: resolve conflicts

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
  • Loading branch information
mergify[bot] and mdelapenya authored Jun 14, 2021
1 parent d752b09 commit 05a884e
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 83 deletions.
6 changes: 2 additions & 4 deletions e2e/_suites/kubernetes-autodiscover/autodiscover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ func (m *podsManager) configureDockerImage(podName string) error {
if useCISnapshots || beatsLocalPath != "" {
log.Debugf("Configuring Docker image for %s", podName)

// this method will detect if the GITHUB_CHECK_SHA1 variable is set
artifactName := utils.BuildArtifactName(podName, common.BeatVersion, common.BeatVersionBase, "linux", "amd64", "tar.gz", true)

imagePath, err := utils.FetchBeatsBinary(m.ctx, artifactName, podName, common.BeatVersion, common.BeatVersionBase, utils.TimeoutFactor, true)
artifactName := utils.BuildArtifactName(podName, common.BeatVersion, "linux", "amd64", "tar.gz", true)
imagePath, err := utils.FetchBeatsBinary(m.ctx, artifactName, podName, common.BeatVersion, utils.TimeoutFactor, true)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/_suites/metricbeat/metricbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ func (mts *MetricbeatTestSuite) runMetricbeatService() error {
beatsLocalPath := shell.GetEnv("BEATS_LOCAL_PATH", "")
if useCISnapshots || beatsLocalPath != "" {
arch := utils.GetArchitecture()
artifactName := utils.BuildArtifactName("metricbeat", mts.Version, common.BeatVersionBase, "linux", arch, "tar.gz", true)

imagePath, err := utils.FetchBeatsBinary(mts.currentContext, artifactName, "metricbeat", mts.Version, common.BeatVersionBase, utils.TimeoutFactor, true)
artifactName := utils.BuildArtifactName("metricbeat", mts.Version, "linux", arch, "tar.gz", true)
imagePath, err := utils.FetchBeatsBinary(mts.currentContext, artifactName, "metricbeat", mts.Version, utils.TimeoutFactor, true)
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion internal/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ func InitVersions() {
BeatVersion = v

// detects if the BeatVersion is set by the GITHUB_CHECK_SHA1 variable
BeatVersion = utils.CheckPRVersion(BeatVersion, BeatVersionBase)
fallbackVersion := BeatVersionBase
if BeatVersion != BeatVersionBase {
log.WithFields(log.Fields{
"BeatVersionBase": BeatVersionBase,
"BeatVersion": BeatVersion,
}).Trace("Beat Version provided: will be used as fallback")
fallbackVersion = BeatVersion
}
BeatVersion = utils.CheckPRVersion(BeatVersion, fallbackVersion)

StackVersion = shell.GetEnv("STACK_VERSION", BeatVersionBase)
v, err = utils.GetElasticArtifactVersion(StackVersion)
Expand Down
4 changes: 2 additions & 2 deletions internal/installer/elasticagent_deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func (i *elasticAgentDEBPackage) Preinstall(ctx context.Context) error {
arch := utils.GetArchitecture()
extension := "deb"

binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, common.BeatVersionBase, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, common.BeatVersionBase, utils.TimeoutFactor, true)
binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, utils.TimeoutFactor, true)
if err != nil {
log.WithFields(log.Fields{
"artifact": artifact,
Expand Down
4 changes: 2 additions & 2 deletions internal/installer/elasticagent_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (i *elasticAgentDockerPackage) Preinstall(ctx context.Context) error {
arch := utils.GetArchitecture()
extension := "tar.gz"

binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, common.BeatVersionBase, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, common.BeatVersionBase, utils.TimeoutFactor, true)
binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, utils.TimeoutFactor, true)
if err != nil {
log.WithFields(log.Fields{
"artifact": artifact,
Expand Down
4 changes: 2 additions & 2 deletions internal/installer/elasticagent_rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func (i *elasticAgentRPMPackage) Preinstall(ctx context.Context) error {
}
extension := "rpm"

binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, common.BeatVersionBase, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, common.BeatVersionBase, utils.TimeoutFactor, true)
binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, utils.TimeoutFactor, true)
if err != nil {
log.WithFields(log.Fields{
"artifact": artifact,
Expand Down
4 changes: 2 additions & 2 deletions internal/installer/elasticagent_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func (i *elasticAgentTARPackage) Preinstall(ctx context.Context) error {
}
extension := "tar.gz"

binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, common.BeatVersionBase, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, common.BeatVersionBase, utils.TimeoutFactor, true)
binaryName := utils.BuildArtifactName(artifact, common.BeatVersion, os, arch, extension, false)
binaryPath, err := utils.FetchBeatsBinary(ctx, binaryName, artifact, common.BeatVersion, utils.TimeoutFactor, true)
if err != nil {
log.WithFields(log.Fields{
"artifact": artifact,
Expand Down
13 changes: 5 additions & 8 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))

// BuildArtifactName builds the artifact name from the different coordinates for the artifact
func BuildArtifactName(artifact string, version string, fallbackVersion string, OS string, arch string, extension string, isDocker bool) string {
func BuildArtifactName(artifact string, artifactVersion string, OS string, arch string, extension string, isDocker bool) string {
dockerString := ""
if isDocker {
dockerString = ".docker"
}

artifactVersion := CheckPRVersion(version, fallbackVersion)

lowerCaseExtension := strings.ToLower(extension)

artifactName := fmt.Sprintf("%s-%s-%s-%s%s.%s", artifact, artifactVersion, OS, arch, dockerString, lowerCaseExtension)
Expand Down Expand Up @@ -91,7 +89,7 @@ func CheckPRVersion(version string, fallbackVersion string) string {
// to be used will be defined by the local snapshot produced by the local build.
// Else, if the environment variable BEATS_USE_CI_SNAPSHOTS is set, then the artifact
// to be downloaded will be defined by the latest snapshot produced by the Beats CI.
func FetchBeatsBinary(ctx context.Context, artifactName string, artifact string, version string, fallbackVersion string, timeoutFactor int, xpack bool) (string, error) {
func FetchBeatsBinary(ctx context.Context, artifactName string, artifact string, version string, timeoutFactor int, xpack bool) (string, error) {
beatsLocalPath := shell.GetEnv("BEATS_LOCAL_PATH", "")
if beatsLocalPath != "" {
span, _ := apm.StartSpanOptions(ctx, "Fetching Beats binary", "beats.local.fetch", apm.SpanOptions{
Expand Down Expand Up @@ -162,7 +160,7 @@ func FetchBeatsBinary(ctx context.Context, artifactName string, artifact string,

log.Debugf("Using CI snapshots for %s", artifact)

bucket, prefix, object := getGCPBucketCoordinates(artifactName, artifact, version, fallbackVersion)
bucket, prefix, object := getGCPBucketCoordinates(artifactName, artifact, version)

maxTimeout := time.Duration(timeoutFactor) * time.Minute

Expand Down Expand Up @@ -196,7 +194,7 @@ func GetArchitecture() string {
}

// getGCPBucketCoordinates it calculates the bucket path in GCP
func getGCPBucketCoordinates(fileName string, artifact string, version string, fallbackVersion string) (string, string, string) {
func getGCPBucketCoordinates(fileName string, artifact string, version string) (string, string, string) {
bucket := "beats-ci-artifacts"
prefix := fmt.Sprintf("snapshots/%s", artifact)
object := fileName
Expand All @@ -206,8 +204,7 @@ func getGCPBucketCoordinates(fileName string, artifact string, version string, f
if commitSHA != "" {
log.WithFields(log.Fields{
"commit": commitSHA,
"PR": version,
"version": fallbackVersion,
"version": version,
}).Debug("Using CI snapshots for a commit")
prefix = fmt.Sprintf("commits/%s", commitSHA)
object = artifact + "/" + fileName
Expand Down
Loading

0 comments on commit 05a884e

Please sign in to comment.