Skip to content

Commit

Permalink
[chore] Add run id to flakey test logs (#11243)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier authored Nov 9, 2023
1 parent cc05bfd commit b9bd82a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ jobs:
GITHUB_EVENT_PATH: ${{ github.event_path }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REPO: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
./runner \
-grafana_auth=$GRAFANA_CLOUD_BASIC_AUTH \
-grafana_host=$GRAFANA_CLOUD_HOST \
-gh_sha=$GITHUB_SHA \
-gh_event_path=$GITHUB_EVENT_PATH \
-gh_event_name=$GITHUB_EVENT_NAME \
-gh_run_id=$GITHUB_RUN_ID \
-gh_repo=$GITHUB_REPO \
-command=./tools/bin/go_core_tests \
`ls -R ./artifacts/go_core_tests*/output.txt`
Expand Down
3 changes: 2 additions & 1 deletion tools/flakeytests/cmd/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
ghEventPath := flag.String("gh_event_path", "", "path to associated gh event")
ghEventName := flag.String("gh_event_name", "", "type of associated gh event")
ghRepo := flag.String("gh_repo", "", "name of gh repository")
ghRunID := flag.String("gh_run_id", "", "run id of the gh workflow")
flag.Parse()

if *grafanaHost == "" {
Expand Down Expand Up @@ -47,7 +48,7 @@ func main() {
readers = append(readers, r)
}

ctx := flakeytests.GetGithubMetadata(*ghRepo, *ghEventName, *ghSHA, *ghEventPath)
ctx := flakeytests.GetGithubMetadata(*ghRepo, *ghEventName, *ghSHA, *ghEventPath, *ghRunID)
rep := flakeytests.NewLokiReporter(*grafanaHost, *grafanaAuth, *command, ctx)
r := flakeytests.NewRunner(readers, rep, numReruns)
err := r.Run()
Expand Down
1 change: 1 addition & 0 deletions tools/flakeytests/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Context struct {
PullRequestURL string `json:"pull_request_url,omitempty"`
Repository string `json:"repository"`
Type string `json:"event_type"`
RunURL string `json:"run_url,omitempty"`
}

type LokiReporter struct {
Expand Down
10 changes: 6 additions & 4 deletions tools/flakeytests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flakeytests

import (
"encoding/json"
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -29,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) Context {
func getGithubMetadata(repo string, eventName string, sha string, e io.Reader, runID string) Context {
d, err := io.ReadAll(e)
if err != nil {
log.Fatal("Error reading gh event into string")
Expand All @@ -41,7 +42,8 @@ func getGithubMetadata(repo string, eventName string, sha string, e io.Reader) C
log.Fatalf("Error unmarshaling gh event at path")
}

basicCtx := &Context{Repository: repo, CommitSHA: sha, Type: eventName}
runURL := fmt.Sprintf("%s/actions/%s", repo, runID)
basicCtx := &Context{Repository: repo, CommitSHA: sha, Type: eventName, RunURL: runURL}
switch eventName {
case "pull_request":
prURL := ""
Expand All @@ -68,10 +70,10 @@ func getGithubMetadata(repo string, eventName string, sha string, e io.Reader) C
}
}

func GetGithubMetadata(repo string, eventName string, sha string, path string) Context {
func GetGithubMetadata(repo string, eventName string, sha string, path string, runID 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)
return getGithubMetadata(repo, eventName, sha, event, runID)
}
10 changes: 5 additions & 5 deletions tools/flakeytests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ var prEventTemplate = `
`

func TestGetGithubMetadata(t *testing.T) {
repo, eventName, sha, event := "chainlink", "merge_group", "a-sha", `{}`
ctx := getGithubMetadata(repo, eventName, sha, strings.NewReader(event))
assert.Equal(t, Context{Repository: repo, CommitSHA: sha, Type: eventName}, ctx)
repo, eventName, sha, event, runID := "chainlink", "merge_group", "a-sha", `{}`, "1234"
ctx := getGithubMetadata(repo, eventName, sha, strings.NewReader(event), runID)
assert.Equal(t, Context{Repository: repo, CommitSHA: sha, Type: eventName, RunURL: fmt.Sprintf("%s/actions/%s", repo, runID)}, 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))
assert.Equal(t, Context{Repository: repo, CommitSHA: anotherSha, Type: eventName, PullRequestURL: url}, ctx)
ctx = getGithubMetadata(repo, eventName, sha, strings.NewReader(event), runID)
assert.Equal(t, Context{Repository: repo, CommitSHA: anotherSha, Type: eventName, PullRequestURL: url, RunURL: fmt.Sprintf("%s/actions/%s", repo, runID)}, ctx)
}

0 comments on commit b9bd82a

Please sign in to comment.