Skip to content

Commit

Permalink
[TT-1834] Uses Proper JSON Naming for Flakeguard (#1502)
Browse files Browse the repository at this point in the history
* Uses proper JSON for flakeguard

* Use proper JSON fields in decoding
  • Loading branch information
kalverra authored Dec 18, 2024
1 parent 64f30d9 commit 74a4a66
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
63 changes: 32 additions & 31 deletions tools/flakeguard/reports/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,44 @@ import (
"time"
)

// Data Structures

// TestReport reports on the parameters and results of one to many test runs
type TestReport struct {
GoProject string
HeadSHA string
BaseSHA string
RepoURL string
GitHubWorkflowName string
TestRunCount int
RaceDetection bool
ExcludedTests []string
SelectedTests []string
Results []TestResult
GoProject string `json:"go_project"`
HeadSHA string `json:"head_sha"`
BaseSHA string `json:"base_sha"`
RepoURL string `json:"repo_url"`
GitHubWorkflowName string `json:"github_workflow_name"`
TestRunCount int `json:"test_run_count"`
RaceDetection bool `json:"race_detection"`
ExcludedTests []string `json:"excluded_tests"`
SelectedTests []string `json:"selected_tests"`
Results []TestResult `json:"results"`
}

// TestResult contains the results and outputs of a single test
type TestResult struct {
TestName string
TestPackage string
PackagePanic bool
Panic bool
Timeout bool
Race bool
Skipped bool
PassRatio float64
Runs int
Failures int
Successes int
Skips int
Outputs map[string][]string `json:"-"` // Temporary storage for outputs during test run
PassedOutputs map[string][]string // Outputs for passed runs
FailedOutputs map[string][]string // Outputs for failed runs
Durations []time.Duration
PackageOutputs []string
TestPath string
CodeOwners []string
TestName string `json:"test_name"`
TestPackage string `json:"test_package"`
PackagePanic bool `json:"package_panic"`
Panic bool `json:"panic"`
Timeout bool `json:"timeout"`
Race bool `json:"race"`
Skipped bool `json:"skipped"`
PassRatio float64 `json:"pass_ratio"`
Runs int `json:"runs"`
Failures int `json:"failures"`
Successes int `json:"successes"`
Skips int `json:"skips"`
Outputs map[string][]string `json:"-"` // Temporary storage for outputs during test run
PassedOutputs map[string][]string `json:"passed_outputs"` // Outputs for passed runs
FailedOutputs map[string][]string `json:"failed_outputs"` // Outputs for failed runs
Durations []time.Duration `json:"durations"`
PackageOutputs []string `json:"package_outputs"`
TestPath string `json:"test_path"`
CodeOwners []string `json:"code_owners"`
}

// SummaryData contains aggregated data from a set of test results
type SummaryData struct {
TotalTests int `json:"total_tests"`
PanickedTests int `json:"panicked_tests"`
Expand Down
22 changes: 11 additions & 11 deletions tools/flakeguard/reports/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,52 +100,52 @@ func processLargeFile(filePath string, reportChan chan<- *TestReport, errChan ch
}

switch fieldName {
case "GoProject":
case "go_project":
if err := decoder.Decode(&report.GoProject); err != nil {
log.Printf("Error decoding GoProject in file: %s, Error: %v", filePath, err)
return
}
case "HeadSHA":
case "head_sha":
if err := decoder.Decode(&report.HeadSHA); err != nil {
log.Printf("Error decoding HeadSHA in file: %s, Error: %v", filePath, err)
return
}
case "BaseSHA":
case "base_sha":
if err := decoder.Decode(&report.BaseSHA); err != nil {
log.Printf("Error decoding BaseSHA in file: %s, Error: %v", filePath, err)
return
}
case "RepoURL":
case "repo_url":
if err := decoder.Decode(&report.RepoURL); err != nil {
log.Printf("Error decoding RepoURL in file: %s, Error: %v", filePath, err)
return
}
case "GitHubWorkflowName":
case "github_workflow_name":
if err := decoder.Decode(&report.GitHubWorkflowName); err != nil {
log.Printf("Error decoding GitHubWorkflowName in file: %s, Error: %v", filePath, err)
return
}
case "TestRunCount":
case "test_run_count":
if err := decoder.Decode(&report.TestRunCount); err != nil {
log.Printf("Error decoding TestRunCount in file: %s, Error: %v", filePath, err)
return
}
case "RaceDetection":
case "race_detection":
if err := decoder.Decode(&report.RaceDetection); err != nil {
log.Printf("Error decoding RaceDetection in file: %s, Error: %v", filePath, err)
return
}
case "ExcludedTests":
case "excluded_tests":
if err := decoder.Decode(&report.ExcludedTests); err != nil {
log.Printf("Error decoding ExcludedTests in file: %s, Error: %v", filePath, err)
return
}
case "SelectedTests":
case "selected_tests":
if err := decoder.Decode(&report.SelectedTests); err != nil {
log.Printf("Error decoding SelectedTests in file: %s, Error: %v", filePath, err)
return
}
case "Results":
case "results":
token, err := decoder.Token() // Read opening bracket '['
if err != nil || token != json.Delim('[') {
log.Printf("Error reading Results array start in file: %s, Error: %v", filePath, err)
Expand All @@ -172,7 +172,7 @@ func processLargeFile(filePath string, reportChan chan<- *TestReport, errChan ch
log.Printf("Error skipping unknown field: %s in file: %s, Error: %v", fieldName, filePath, err)
return
}
log.Printf("Skipped unknown field: %s in file: %s", fieldName, filePath)
log.Printf("Skipped unknown field: '%s' in file: %s", fieldName, filePath)
}
}

Expand Down
6 changes: 3 additions & 3 deletions tools/flakeguard/reports/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func GeneratePRCommentMarkdown(w io.Writer, testReport *TestReport, maxPassRatio
}

resultsTable := GenerateFlakyTestsTable(testReport.Results, maxPassRatio, true)
renderTestResultsTable(w, resultsTable, true)
renderTestResultsTable(w, resultsTable)

if artifactLink != "" {
renderArtifactSection(w, artifactName, artifactLink)
Expand Down Expand Up @@ -179,7 +179,7 @@ func RenderResults(
resultsTable := GenerateFlakyTestsTable(tests, maxPassRatio, markdown)
summary := GenerateSummaryData(tests, maxPassRatio)
renderSummaryTable(w, summary, markdown)
renderTestResultsTable(w, resultsTable, markdown)
renderTestResultsTable(w, resultsTable)
}

func renderSummaryTable(w io.Writer, summary SummaryData, markdown bool) {
Expand Down Expand Up @@ -209,7 +209,7 @@ func renderSummaryTable(w io.Writer, summary SummaryData, markdown bool) {
fmt.Fprintln(w)
}

func renderTestResultsTable(w io.Writer, table [][]string, markdown bool) {
func renderTestResultsTable(w io.Writer, table [][]string) {
if len(table) <= 1 {
fmt.Fprintln(w, "No tests found under the specified pass ratio threshold.")
return
Expand Down

0 comments on commit 74a4a66

Please sign in to comment.