@@ -472,6 +472,15 @@ exporters:
472472 elasticsearch:
473473 api_key: {{.ESApiKey}}
474474 endpoint: {{.ESEndpoint}}
475+ logs_index: {{.TestId}}
476+ sending_queue:
477+ wait_for_result: true
478+ block_on_overflow: true
479+ enabled: true
480+ batch:
481+ min_size: 2000
482+ max_size: 10000
483+ flush_timeout: 1s
475484 mapping:
476485 mode: none
477486
@@ -498,6 +507,13 @@ service:
498507 - resource/add-test-id
499508 receivers:
500509 - filelog
510+ telemetry:
511+ logs:
512+ level: DEBUG
513+ encoding: json
514+ disable_stacktrace: true
515+ output_paths:
516+ - {{.OTelLogFile}}
501517`
502518
503519func TestOtelLogsIngestion (t * testing.T ) {
@@ -515,8 +531,11 @@ func TestOtelLogsIngestion(t *testing.T) {
515531 // Prepare the OTel config.
516532 testId := info .Namespace
517533
518- tempDir := t .TempDir ()
534+ // Ensure everything is saved in case of test failure
535+ // this folder is also collected on CI.
536+ tempDir := aTesting .TempDir (t , ".." , ".." , ".." , "build" )
519537 inputFilePath := filepath .Join (tempDir , "input.log" )
538+ otelLogFilePath := filepath .Join (tempDir , "elastic-agent.ndjson" )
520539
521540 esHost , err := integration .GetESHost ()
522541 require .NoError (t , err , "failed to get ES host" )
@@ -533,6 +552,7 @@ func TestOtelLogsIngestion(t *testing.T) {
533552 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.ESEndpoint}}" , esHost )
534553 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.InputFilePath}}" , inputFilePath )
535554 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.TestId}}" , testId )
555+ logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.OTelLogFile}}" , otelLogFilePath )
536556
537557 cfgFilePath := filepath .Join (tempDir , "otel.yml" )
538558 require .NoError (t , os .WriteFile (cfgFilePath , []byte (logsIngestionConfig ), 0o600 ))
@@ -566,26 +586,30 @@ func TestOtelLogsIngestion(t *testing.T) {
566586 require .NoError (t , err )
567587 }
568588 inputFile .Close ()
569- t .Cleanup (func () {
570- _ = os .Remove (inputFilePath )
571- })
572589
573- actualHits := & struct { Hits int }{}
574- require .Eventually (t ,
575- func () bool {
576- findCtx , findCancel := context .WithTimeout (context .Background (), 10 * time .Second )
590+ // It takes about 45s to ingest all files on local tests,
591+ // so set the timeout to 5min to be on the safe side.
592+ require .EventuallyWithT (
593+ t ,
594+ func (c * assert.CollectT ) {
595+ findCtx , findCancel := context .WithTimeout (t .Context (), 10 * time .Second )
577596 defer findCancel ()
578597
579- docs , err := estools .GetLogsForIndexWithContext (findCtx , esClient , ".ds-logs-generic-default*" , map [string ]interface {}{
580- "Resource.test.id" : testId ,
581- })
582- require .NoError (t , err )
583-
584- actualHits .Hits = docs .Hits .Total .Value
585- return actualHits .Hits == logsCount
598+ docs , err := estools .GetAllLogsForIndexWithContext (
599+ findCtx ,
600+ esClient ,
601+ testId )
602+ require .NoError (c , err )
603+ require .Equalf (
604+ c ,
605+ logsCount ,
606+ docs .Hits .Total .Value ,
607+ "expecting %d events" ,
608+ logsCount )
586609 },
587- 2 * time .Minute , 1 * time .Second ,
588- "Expected %v logs, got %v" , logsCount , actualHits )
610+ 5 * time .Minute ,
611+ time .Second ,
612+ "did not find the expected number of events" )
589613
590614 cancel ()
591615 fixtureWg .Wait ()
0 commit comments