Skip to content

Commit

Permalink
Merge pull request #615 from vitessio/list-all-versions
Browse files Browse the repository at this point in the history
List all compatible version of vitess that were benchmarked
  • Loading branch information
frouioui authored Nov 6, 2024
2 parents cbf0d3f + 1572e4d commit ff802c2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions go/server/cron_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 37 additions & 13 deletions go/tools/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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)"`)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions go/tools/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ff802c2

Please sign in to comment.