Skip to content

Commit 7c45cff

Browse files
committed
Fix count log
1 parent 00d9baf commit 7c45cff

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

tools/flakeguard/reports/io.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ func aggregate(reportChan <-chan *TestReport, errChan <-chan error, opts *aggreg
387387

388388
// sendDataToSplunk sends a truncated TestReport and each individual TestResults to Splunk as events
389389
func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...TestResult) error {
390+
start := time.Now()
390391
client := resty.New().
391392
SetBaseURL(opts.splunkURL).
392393
SetAuthScheme("Splunk").
@@ -395,12 +396,12 @@ func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...Test
395396
SetLogger(ZerologRestyLogger{})
396397
client.AddRetryAfterErrorCondition().SetRetryCount(5).SetTimeout(time.Second * 10)
397398

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

400401
// Send results
401402
var (
402403
splunkErrs = []error{}
403-
resultsBatchSize = 5
404+
resultsBatchSize = 10
404405
resultsBatch = []SplunkTestResult{}
405406
successfulResultsSent = 0
406407
)
@@ -420,7 +421,6 @@ func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...Test
420421
if err != nil {
421422
return fmt.Errorf("error batching results: %w", err)
422423
}
423-
resultsBatch = []SplunkTestResult{}
424424

425425
resp, err := client.R().
426426
SetBody(batchData.String()).
@@ -436,24 +436,12 @@ func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...Test
436436
)
437437
}
438438
if err == nil && !resp.IsError() {
439-
successfulResultsSent += resultsBatchSize
439+
successfulResultsSent += len(resultsBatch)
440440
}
441+
resultsBatch = []SplunkTestResult{}
441442
}
442443
}
443444

444-
if len(splunkErrs) > 0 {
445-
log.Error().
446-
Int("successfully sent", successfulResultsSent).
447-
Int("total results", len(results)).
448-
Errs("errors", splunkErrs).
449-
Msg("Errors occurred while sending test results to Splunk")
450-
} else {
451-
log.Debug().
452-
Int("successfully sent", successfulResultsSent).
453-
Int("total results", len(results)).
454-
Msg("All results sent successfully")
455-
}
456-
457445
// Check if errors occurred while uploading results and send report with incomplete flag
458446
resp, err := client.R().
459447
SetBody(SplunkTestReport{
@@ -474,6 +462,20 @@ func sendDataToSplunk(opts *aggregateOptions, report TestReport, results ...Test
474462
if resp.IsError() {
475463
splunkErrs = append(splunkErrs, fmt.Errorf("error sending flakeguard report '%s' to Splunk: %s", report.ID, resp.String()))
476464
}
465+
if len(splunkErrs) > 0 {
466+
log.Error().
467+
Int("successfully sent", successfulResultsSent).
468+
Int("total results", len(results)).
469+
Errs("errors", splunkErrs).
470+
Str("duration", time.Since(start).String()).
471+
Msg("Errors occurred while sending test results to Splunk")
472+
} else {
473+
log.Debug().
474+
Int("successfully sent", successfulResultsSent).
475+
Int("total results", len(results)).
476+
Str("duration", time.Since(start).String()).
477+
Msg("All results sent successfully")
478+
}
477479
return errors.Join(splunkErrs...)
478480
}
479481

tools/flakeguard/reports/io_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func TestAggregateResultFilesSplunk(t *testing.T) {
4343
require.Equal(t, SplunkSourceType, report.SourceType, "source type mismatch")
4444
require.Equal(t, Report, report.Event.Type, "event type mismatch")
4545
require.Equal(t, splunkEvent, report.Event.Event, "event mismatch")
46+
require.Equal(t, reportID, report.Event.Data.ID, "report ID mismatch")
47+
require.False(t, report.Event.Incomplete, "report should not be incomplete")
4648
reportRequestsReceived++
4749
} else {
4850
results, err := unBatchSplunkResults(bodyBytes)

0 commit comments

Comments
 (0)