diff --git a/go/server/api.go b/go/server/api.go index a425bd060..9b407bedf 100644 --- a/go/server/api.go +++ b/go/server/api.go @@ -150,7 +150,7 @@ type VitessGitRefReleases struct { func (s *Server) getLatestVitessGitRef(c *gin.Context) { var response VitessGitRefReleases - allReleases, err := git.GetLatestVitessReleaseCommitHash(s.getVitessPath()) + allReleases, err := git.GetAllComparableVitessReleases(s.getVitessPath()) if err != nil { c.JSON(http.StatusInternalServerError, &ErrorAPI{Error: err.Error()}) slog.Error(err) diff --git a/go/server/cron_handlers.go b/go/server/cron_handlers.go index 330171e18..7df654359 100644 --- a/go/server/cron_handlers.go +++ b/go/server/cron_handlers.go @@ -66,7 +66,7 @@ func (s *Server) mainBranchCronHandler() ([]*executionQueueElement, error) { } // getting the latest release from local fork of Vitess - lastRelease, err := git.GetLastReleaseAndCommitHash(vitessPath) + lastRelease, err := git.GetLastestRelease(vitessPath) if err != nil { return nil, err } @@ -116,7 +116,7 @@ func (s *Server) releaseBranchesCronHandler() ([]*executionQueueElement, error) for _, release := range releases { ref := release.CommitHash source := exec.SourceReleaseBranch + release.Name - lastPatchRelease, err := git.GetLastPatchReleaseAndCommitHash(vitesLocalPath, release.Version) + lastPatchRelease, err := git.GetLastestPatchReleaseOfGivenMajorVersion(vitesLocalPath, release.Version) if err != nil && !strings.Contains(err.Error(), "could not find the latest patch release") { slog.Warn(err.Error()) continue @@ -277,7 +277,7 @@ func (s *Server) tagsCronHandler() { configs := s.getConfigFiles() - releases, err := git.GetLatestVitessReleaseCommitHash(s.getVitessPath()) + releases, err := git.GetSupportedVitessReleases(s.getVitessPath()) if err != nil { slog.Error(err) return diff --git a/go/tools/git/git.go b/go/tools/git/git.go index 37bc27b14..0d008b765 100644 --- a/go/tools/git/git.go +++ b/go/tools/git/git.go @@ -56,8 +56,8 @@ func GetPlannerVersions() []macrobench.PlannerVersion { return []macrobench.PlannerVersion{macrobench.Gen4Planner} } -// GetAllVitessReleaseCommitHash gets all the vitess releases and the commit hashes given the directory of the clone of vitess -func GetAllVitessReleaseCommitHash(repoDir string) ([]*Release, error) { +// getAllVitessReleases gets all the vitess releases and the commit hashes given the directory of the clone of vitess +func getAllVitessReleases(repoDir string) ([]*Release, error) { out, err := ExecCmd(repoDir, "git", "show-ref", "--tags", "-d") if err != nil { return nil, err @@ -132,9 +132,12 @@ func GetAllVitessReleaseCommitHash(repoDir string) ([]*Release, error) { return res, nil } -// GetLatestVitessReleaseCommitHash gets the lastest major vitess releases and the commit hashes given the directory of the clone of vitess -func GetLatestVitessReleaseCommitHash(repoDir string) ([]*Release, error) { - allReleases, err := GetAllVitessReleaseCommitHash(repoDir) +// GetSupportedVitessReleases returns a slice of all the currently supported Vitess releases. +// The last 3 releases are the currently supported releases. +// With the VEP-6 (https://github.com/vitessio/enhancements/pull/12), starting from when we EOL v20.0 +// only two major releases will be supported in Vitess. +func GetSupportedVitessReleases(repoDir string) ([]*Release, error) { + allReleases, err := getAllVitessReleases(repoDir) if err != nil || len(allReleases) == 0 { return nil, err } @@ -149,6 +152,27 @@ func GetLatestVitessReleaseCommitHash(repoDir string) ([]*Release, error) { return latestReleases, nil } +// GetAllComparableVitessReleases returns a slice of all the Vitess releases that can safely be +// compared in arewefastyet. Meaning, all the releases that have been benchmarked with a compatible +// methodology as the one currently used in arewefastyet. +func GetAllComparableVitessReleases(repoDir string) ([]*Release, error) { + allReleases, err := getAllVitessReleases(repoDir) + if err != nil || len(allReleases) == 0 { + return nil, err + } + var comparableReleases []*Release + + // This is the oldest major version of Vitess that contains up-to-date results on arewefastyet. + const firstComparableReleaseMajorVersion = 18 + for _, release := range allReleases { + if release.Version.Major >= firstComparableReleaseMajorVersion { + comparableReleases = append(comparableReleases, release) + } + } + + return comparableReleases, nil +} + // GetAllVitessReleaseBranchCommitHash gets all the vitess release branches and the commit hashes given the directory of the clone of vitess func GetAllVitessReleaseBranchCommitHash(repoDir string) ([]*Release, error) { out, err := ExecCmd(repoDir, "git", "branch", "-r", "--format", `"%(objectname) %(refname)"`) @@ -214,18 +238,18 @@ func GetLatestVitessReleaseBranchCommitHash(repoDir string) ([]*Release, error) return latestReleaseBranches, nil } -// GetLastReleaseAndCommitHash gets the last release number along with the commit hash given the directory of the clone of vitess -func GetLastReleaseAndCommitHash(repoDir string) (*Release, error) { - res, err := GetAllVitessReleaseCommitHash(repoDir) +// GetLastestRelease gets the last release number along with the commit hash given the directory of the clone of vitess +func GetLastestRelease(repoDir string) (*Release, error) { + res, err := getAllVitessReleases(repoDir) if err != nil { return nil, err } return res[0], nil } -// GetLastPatchReleaseAndCommitHash gets the last release number given the major and minor release number along with the commit hash given the directory of the clone of vitess -func GetLastPatchReleaseAndCommitHash(repoDir string, version Version) (*Release, error) { - res, err := GetAllVitessReleaseCommitHash(repoDir) +// GetLastestPatchReleaseOfGivenMajorVersion gets the last release number given the major and minor release number along with the commit hash given the directory of the clone of vitess +func GetLastestPatchReleaseOfGivenMajorVersion(repoDir string, version Version) (*Release, error) { + res, err := getAllVitessReleases(repoDir) if err != nil { return nil, err } @@ -341,7 +365,7 @@ func GetVersionForCommitSHA(repoDir, sha string) (Version, error) { matchRelease := regexp.MustCompile(`release-([0-9]+).0`) for _, branch := range branches { if strings.Contains(branch, "origin/main") { - lastRelease, err := GetLastReleaseAndCommitHash(repoDir) + lastRelease, err := GetLastestRelease(repoDir) if err != nil { return Version{}, err } @@ -356,7 +380,7 @@ func GetVersionForCommitSHA(repoDir, sha string) (Version, error) { if err != nil { return Version{}, err } - lastPatch, err := GetLastPatchReleaseAndCommitHash(repoDir, Version{Major: majorV}) + lastPatch, err := GetLastestPatchReleaseOfGivenMajorVersion(repoDir, Version{Major: majorV}) if err != nil { return Version{}, err } diff --git a/go/tools/git/git_test.go b/go/tools/git/git_test.go index 08a61532c..4a1743803 100644 --- a/go/tools/git/git_test.go +++ b/go/tools/git/git_test.go @@ -51,7 +51,7 @@ func TestGetAllVitessReleaseCommitHashOrdering(t *testing.T) { tmpDir, vitessPath, err := createTemporaryVitessClone() defer os.RemoveAll(tmpDir) qt.Assert(t, err, qt.IsNil) - s, err := GetAllVitessReleaseCommitHash(vitessPath) + s, err := getAllVitessReleases(vitessPath) qt.Assert(t, err, qt.IsNil) // ordered releases from v10.0.1 to v9.0.0-rc1 @@ -85,7 +85,7 @@ func TestGetAllVitessReleaseCommitHash(t *testing.T) { tmpDir, vitessPath, err := createTemporaryVitessClone() defer os.RemoveAll(tmpDir) qt.Assert(t, err, qt.IsNil) - s, err := GetAllVitessReleaseCommitHash(vitessPath) + s, err := getAllVitessReleases(vitessPath) qt.Assert(t, err, qt.IsNil) qt.Assert(t, s, qt.Any(qt.DeepEquals), &Release{ Name: "5.0.1", @@ -314,7 +314,7 @@ func TestGetLatestVitessReleaseCommitHash(t *testing.T) { tmpDir, vitessPath, err := createTemporaryVitessClone() defer os.RemoveAll(tmpDir) qt.Assert(t, err, qt.IsNil) - out, err := GetLatestVitessReleaseCommitHash(vitessPath) + out, err := GetSupportedVitessReleases(vitessPath) qt.Assert(t, err, qt.IsNil) for _, release := range out { qt.Assert(t, len(release.CommitHash), qt.Equals, 40)