Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove major snapshots check find oldest script #11265

Merged
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
2 changes: 2 additions & 0 deletions .buildkite/pipeline.serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ env:
ELASTIC_PACKAGE_MAXIMUM_NUMBER_PARALLEL_TESTS: "5"
# Enable/Disable the usage of wolfi images for Elastic Agent
ELASTIC_PACKAGE_DISABLE_ELASTIC_AGENT_WOLFI: "${ELASTIC_PACKAGE_DISABLE_ELASTIC_AGENT_WOLFI:-false}"
# Disable checking for newer versions
ELASTIC_PACKAGE_CHECK_UPDATE_DISABLED: "true"

steps:
- input: "Input values for the variables"
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ env:
ELASTIC_PACKAGE_MAXIMUM_NUMBER_PARALLEL_TESTS: "5"
# Enable/Disable the usage of wolfi images for Elastic Agent
ELASTIC_PACKAGE_DISABLE_ELASTIC_AGENT_WOLFI: "${ELASTIC_PACKAGE_DISABLE_ELASTIC_AGENT_WOLFI:-false}"
# Disable checking for newer versions
ELASTIC_PACKAGE_CHECK_UPDATE_DISABLED: "true"

steps:
- label: "Get reference from target branch"
Expand Down
92 changes: 15 additions & 77 deletions .buildkite/scripts/find_oldest_supported_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ def fetch_version():


def find_oldest_supported_version(kibana_version_condition: str) -> str:
# The logic of this function is copied from https://github.com/elastic/apm-pipeline-library/blob/main/vars/findOldestSupportedVersion.groovy
mrodm marked this conversation as resolved.
Show resolved Hide resolved

if "||" in kibana_version_condition and kibana_version_condition.index("||") >= 0:
return handle_or(kibana_version_condition)

Expand Down Expand Up @@ -55,65 +53,8 @@ def find_oldest_supported_version(kibana_version_condition: str) -> str:
if not next_patch_exists and (snapshot_version in available_versions):
return snapshot_version

# Use the version as is if it exists.
if version in available_versions:
return version

# Old minors may not be available in artifacts-api, if it is older
# than the others in the same major, return the version as is.
older = is_older_version(available_versions, major, minor)

# Check if there could be some version removed or missing from the
# artifacts-api response. If it is missing, return the version as is
newerPatch = exists_newer_patch(available_versions, major, minor, patch)

if older or newerPatch:
return version

# If no version has been found so far, try with the snapshot of the next version
# in the current major.
major_snapshot = f"{major}.x-SNAPSHOT"
if major_snapshot in available_aliases:
return major_snapshot

# Otherwise, return it, whatever this is.
return version

def is_older_version(available_versions: list[str], major: str, minor: str) -> bool:
older = True
for available_version in available_versions:
available_parts = available_version.split(".")
if len(available_parts) < 2:
continue

available_major = int(available_parts[0])
available_minor = int(available_parts[1])
if int(major) == available_major and int(minor) > available_minor:
older = False
break

return older

def exists_newer_patch(available_versions: list[str], major: str, minor: str, patch: str) -> bool:
newer_patch = False
for available_version in available_versions:
available_parts = available_version.split(".")
if len(available_parts) < 2:
continue

available_major = int(available_parts[0])
available_minor = int(available_parts[1])
if int(major) == available_major and int(minor) == available_minor:
available_patch = available_parts[2]
# skip prerelease tags?
if "+" in available_patch or '-' in available_patch:
continue

if int(patch) < int(available_patch):
newer_patch = True
break
return newer_patch


def remove_operator(kibana_version_condition: str) -> str:
if kibana_version_condition[0].isdigit():
Expand Down Expand Up @@ -200,7 +141,6 @@ class TestFindOldestSupportVersion(unittest.TestCase):
"8.8.0",
"8.8.1",
"8.8.2",
"8.9.0",
"8.9.1-SNAPSHOT",
"8.9.1",
"8.9.2-SNAPSHOT",
Expand All @@ -209,20 +149,21 @@ class TestFindOldestSupportVersion(unittest.TestCase):
"8.10.0-SNAPSHOT",
"8.10.0",
"8.10.1-SNAPSHOT",
"8.10.1",
"8.11.0-SNAPSHOT"
],
"aliases": [
"7.x-SNAPSHOT",
"7.17-SNAPSHOT",
"7.17",
"8.x-SNAPSHOT",
"8.7",
"8.8",
"8.9-SNAPSHOT",
"8.9",
"8.10-SNAPSHOT",
"8.10",
"8.11-SNAPSHOT",
"8.x-SNAPSHOT"
"8.11-SNAPSHOT"
],
"manifests": {
"last-update-time": "Thu, 14 Sep 2023 16:03:46 UTC",
Expand Down Expand Up @@ -260,23 +201,20 @@ def test_too_old_to_be_in_api(self):
self.assertEqual(find_oldest_supported_version("8.6.0"), "8.6.0")
self.assertEqual(find_oldest_supported_version("7.6.0"), "7.6.0")

def test_no_version_available_no_next_minor_in_current_major(self):
# returns the version as in the manifest
# no exists in available_versions or snapshots, neither the current {major}-x.SNAPSHOT
def test_newer_major_or_minor_versions_not_shown_in_api(self):
# next minor from 7.x
self.assertEqual(find_oldest_supported_version("7.19.0"), "7.19.0")
# next minor from 8.x
self.assertEqual(find_oldest_supported_version("8.12.0"), "8.12.0")
# next patch from 8.8.x
self.assertEqual(find_oldest_supported_version("8.8.3"), "8.8.3")
# next major 9.0
self.assertEqual(find_oldest_supported_version("9.0.0"), "9.0.0")

def test_available_next_minor_in_current_major(self):
self.assertEqual(find_oldest_supported_version("7.19.0"), "7.x-SNAPSHOT")

# not sure if this test case for 8.8.3 should return 8.x-SNAPSHOT stack version,
# that would test with probably a newer stack (8.11.0-SNAPSHOT).
self.assertEqual(find_oldest_supported_version("8.8.3"), "8.x-SNAPSHOT")
self.assertEqual(find_oldest_supported_version("8.12.0"), "8.x-SNAPSHOT")

def test_available_version_in_current_major_but_missing_minor(self):
# 8.9.2 and 8.9.4 versions exist in the artifacts-api response and the alias
# 8.x-SNAPSHOT too exists,
# but there is no 8.9.3 version in the artifacts-api response.
def test_missing_older_versions_in_api_response(self):
# exists 8.9.1 and 8.8.x, but not 8.9.0
self.assertEqual(find_oldest_supported_version("8.9.0"), "8.9.0")
# exists 8.9.2 and 8.9.4, but not 8.9.3
self.assertEqual(find_oldest_supported_version("8.9.3"), "8.9.3")

def test_or(self):
Expand Down