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

Allow Admin to add PR to execution queue for benchmarking and profiling #627

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions go/admin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type (
Auth string `json:"auth"`
Source string `json:"source"`
SHA string `json:"sha"`
PR string `json:"pr"`
Workloads []string `json:"workloads"`
NumberOfExecutions string `json:"number_of_executions"`
EnableProfile bool `json:"enable_profile"`
Expand Down Expand Up @@ -227,15 +228,21 @@ func (a *Admin) handleExecutionsAdd(c *gin.Context) {
requestPayload := executionRequest{
Source: c.PostForm("source"),
SHA: c.PostForm("sha"),
PR: c.PostForm("pr"),
Workloads: c.PostFormArray("workloads"),
NumberOfExecutions: c.PostForm("numberOfExecutions"),
EnableProfile: c.PostForm("enableProfiling") != "",
BinaryToProfile: c.PostForm("binaryToProfile"),
ProfileMode: c.PostForm("profileMode"),
}

if requestPayload.Source == "" || requestPayload.SHA == "" || len(requestPayload.Workloads) == 0 || requestPayload.NumberOfExecutions == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Missing required fields: Source, SHA, workflows, numberOfExecutions"})
if requestPayload.Source == "" || len(requestPayload.Workloads) == 0 || requestPayload.NumberOfExecutions == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Missing required fields: Source, workflows, numberOfExecutions"})
return
}

if requestPayload.SHA == "" && requestPayload.PR == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Please provide either a SHA or a PR number"})
return
}

Expand Down
9 changes: 9 additions & 0 deletions go/admin/templates/add_new_executions.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
name="sha"
/>
</div>
<div>
<label class="label">PR</label>
frouioui marked this conversation as resolved.
Show resolved Hide resolved
<input
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
type="number"
class="form-control"
name="pr"
/>
</div>
<br>
<label class="text-lg font-semibold mt-4">Workloads</label>
<div class="flex flex-row gap-4">
Expand Down
25 changes: 23 additions & 2 deletions go/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ type ExecutionRequest struct {
Auth string `json:"auth"`
Source string `json:"source"`
SHA string `json:"sha"`
PR string `json:"pr"`
Workloads []string `json:"workloads"`
NumberOfExecutions string `json:"number_of_executions"`
EnableProfile bool `json:"enable_profile"`
Expand All @@ -578,11 +579,31 @@ func (s *Server) addExecutions(c *gin.Context) {
return
}

if req.Source == "" || req.SHA == "" || len(req.Workloads) == 0 || req.NumberOfExecutions == "" {
if req.Source == "" || len(req.Workloads) == 0 || req.NumberOfExecutions == "" {
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: "missing argument"})
return
}

var pr int
if req.PR != "" {
var err error
pr, err = strconv.Atoi(req.PR)
if err != nil {
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: "PR must be an integer"})
return
}
url := "https://api.github.com/repos/vitessio/vitess/pulls/" + req.PR
prInfo, err := git.GetPullRequestHeadAndBase(url)
if err != nil {
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: "unable to get PR information"})
}
req.SHA = prInfo.SHA
}

if pr == 0 && req.SHA == "" {
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: "missing argument PR or SHA"})
}

if len(req.Workloads) == 1 && req.Workloads[0] == "all" {
req.Workloads = s.workloads
}
Expand All @@ -603,7 +624,7 @@ func (s *Server) addExecutions(c *gin.Context) {

for _, workload := range req.Workloads {
for i := 0; i < execs; i++ {
elem := s.createSimpleExecutionQueueElement(s.benchmarkConfig[strings.ToLower(workload)], req.Source, req.SHA, workload, string(macrobench.Gen4Planner), false, 0, git.Version{}, profileInformation)
elem := s.createSimpleExecutionQueueElement(s.benchmarkConfig[strings.ToLower(workload)], req.Source, req.SHA, workload, string(macrobench.Gen4Planner), false, pr, git.Version{}, profileInformation)
elem.identifier.UUID = uuid.NewString()
newElements = append(newElements, elem)
}
Expand Down
2 changes: 1 addition & 1 deletion go/tools/git/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetPullRequestsFromGitHub(labels []string, repo string) ([]PRInfo, error) {

prInfos := []PRInfo{}
for _, pull := range pulls {
prInfo, err := getPullRequestHeadAndBase(pull)
prInfo, err := GetPullRequestHeadAndBase(pull)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions go/tools/git/pulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (

type PRInfo struct {
Number int
Base string
SHA string
Base string
SHA string
}

func getPullRequestHeadAndBase(url string) (PRInfo, error) {
func GetPullRequestHeadAndBase(url string) (PRInfo, error) {
client := http.Client{}
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func getPullRequestHeadAndBase(url string) (PRInfo, error) {

res := struct {
Number int `json:"number"`
Head struct {
Head struct {
SHA string `json:"sha"`
} `json:"head"`
Base struct {
Expand Down
Loading