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

Add run attempt to uploaded flakey test metrics #13063

Merged
merged 3 commits into from
May 2, 2024
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
7 changes: 6 additions & 1 deletion tools/flakeytests/cmd/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func main() {
ghRunID := flag.String("gh_run_id", "", "run id of the gh workflow")
flag.Parse()

runAttempt := os.Getenv("GITHUB_RUN_ATTEMPT")
if runAttempt == "" {
log.Fatalf("GITHUB_RUN_ATTEMPT is required")
}

if *grafanaHost == "" {
log.Fatal("Error re-running flakey tests: `grafana_host` is required")
}
Expand Down Expand Up @@ -62,7 +67,7 @@ func main() {
readers = append(readers, r)
}

meta := flakeytests.GetGithubMetadata(*ghRepo, *ghEventName, *ghSHA, *ghEventPath, *ghRunID)
meta := flakeytests.GetGithubMetadata(*ghRepo, *ghEventName, *ghSHA, *ghEventPath, *ghRunID, runAttempt)
rep := flakeytests.NewLokiReporter(*grafanaHost, *grafanaAuth, *grafanaOrgID, *command, meta)
r := flakeytests.NewRunner(readers, rep, numReruns)
err := r.Run(ctx)
Expand Down
8 changes: 4 additions & 4 deletions tools/flakeytests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func DigString(mp map[string]interface{}, path []string) (string, error) {
return vs, nil
}

func getGithubMetadata(repo string, eventName string, sha string, e io.Reader, runID string) Context {
func getGithubMetadata(repo string, eventName string, sha string, e io.Reader, runID string, runAttempt string) Context {
d, err := io.ReadAll(e)
if err != nil {
log.Fatal("Error reading gh event into string")
Expand All @@ -42,7 +42,7 @@ func getGithubMetadata(repo string, eventName string, sha string, e io.Reader, r
log.Fatalf("Error unmarshaling gh event at path")
}

runURL := fmt.Sprintf("github.com/%s/actions/runs/%s", repo, runID)
runURL := fmt.Sprintf("github.com/%s/actions/runs/%s/attempts/%s", repo, runID, runAttempt)
basicCtx := &Context{Repository: repo, CommitSHA: sha, Type: eventName, RunURL: runURL}
switch eventName {
case "pull_request":
Expand Down Expand Up @@ -70,10 +70,10 @@ func getGithubMetadata(repo string, eventName string, sha string, e io.Reader, r
}
}

func GetGithubMetadata(repo string, eventName string, sha string, path string, runID string) Context {
func GetGithubMetadata(repo string, eventName string, sha string, path string, runID string, runAttempt string) Context {
event, err := os.Open(path)
if err != nil {
log.Fatalf("Error reading gh event at path: %s", path)
}
return getGithubMetadata(repo, eventName, sha, event, runID)
return getGithubMetadata(repo, eventName, sha, event, runID, runAttempt)
}
8 changes: 4 additions & 4 deletions tools/flakeytests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ var prEventTemplate = `
`

func TestGetGithubMetadata(t *testing.T) {
repo, eventName, sha, event, runID := "chainlink", "merge_group", "a-sha", `{}`, "1234"
expectedRunURL := fmt.Sprintf("github.com/%s/actions/runs/%s", repo, runID)
ctx := getGithubMetadata(repo, eventName, sha, strings.NewReader(event), runID)
repo, eventName, sha, event, runID, runAttempt := "chainlink", "merge_group", "a-sha", `{}`, "1234", "1"
expectedRunURL := fmt.Sprintf("github.com/%s/actions/runs/%s/attempts/%s", repo, runID, runAttempt)
ctx := getGithubMetadata(repo, eventName, sha, strings.NewReader(event), runID, runAttempt)
assert.Equal(t, Context{Repository: repo, CommitSHA: sha, Type: eventName, RunURL: expectedRunURL}, ctx)

anotherSha, eventName, url := "another-sha", "pull_request", "a-url"
event = fmt.Sprintf(prEventTemplate, anotherSha, url)
sha = "302eb05d592132309b264e316f443f1ceb81b6c3"
ctx = getGithubMetadata(repo, eventName, sha, strings.NewReader(event), runID)
ctx = getGithubMetadata(repo, eventName, sha, strings.NewReader(event), runID, runAttempt)
assert.Equal(t, Context{Repository: repo, CommitSHA: anotherSha, Type: eventName, PullRequestURL: url, RunURL: expectedRunURL}, ctx)
}
Loading