Skip to content

Commit

Permalink
Fixes splunk uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra committed Feb 6, 2025
1 parent a37d05d commit f139528
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tools/flakeguard/reports/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ func aggregate(reportChan <-chan *TestReport, errChan <-chan error, opts *aggreg
fullReport.SelectedTests = append(fullReport.SelectedTests, test)
}

// Get the report without any results to send to splunk
splunkReport := *fullReport

// Prepare final results
var (
aggregatedResults []TestResult
Expand All @@ -497,14 +494,16 @@ func aggregate(reportChan <-chan *TestReport, errChan <-chan error, opts *aggreg
GenerateSummaryData(fullReport)

if sendToSplunk {
err = sendDataToSplunk(opts, splunkReport, aggregatedResults...)
err = sendDataToSplunk(opts, *fullReport)
}
return fullReport, err
}

// sendDataToSplunk sends a truncated TestReport and each individual TestResults to Splunk as events
func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...TestResult) error {
func sendDataToSplunk(opts *aggregateOptions, report TestReport) error {
start := time.Now()
results := report.Results
report.Results = nil // Don't send results to Splunk, doing that individually
// Dry-run mode for example runs
isExampleRun := strings.Contains(opts.splunkURL, "splunk.example.com")

Expand All @@ -515,7 +514,7 @@ func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...Test
SetHeader("Content-Type", "application/json").
SetLogger(ZerologRestyLogger{})

log.Debug().Str("report id", report.ID).Int("results", len(results)).Msg("Sending aggregated data to Splunk")
log.Debug().Str("report id", report.ID).Int("results", len(report.Results)).Msg("Sending aggregated data to Splunk")

var (
splunkErrs = []error{}
Expand Down
2 changes: 2 additions & 0 deletions tools/flakeguard/reports/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestAggregateResultFilesSplunk(t *testing.T) {
require.Equal(t, splunkEvent, report.Event.Event, "event mismatch")
require.Equal(t, reportID, report.Event.Data.ID, "report ID mismatch")
require.False(t, report.Event.Incomplete, "report should not be incomplete")
require.NotNil(t, report.Event.Data.SummaryData, "report summary data is nil")
require.Len(t, report.Event.Data.Results, 0, "shouldn't send all result data to splunk")
reportRequestsReceived++
} else {
results, err := unBatchSplunkResults(bodyBytes)
Expand Down

0 comments on commit f139528

Please sign in to comment.