@@ -474,6 +474,15 @@ exporters:
474474 elasticsearch:
475475 api_key: {{.ESApiKey}}
476476 endpoint: {{.ESEndpoint}}
477+ logs_index: {{.TestId}}
478+ sending_queue:
479+ wait_for_result: true
480+ block_on_overflow: true
481+ enabled: true
482+ batch:
483+ min_size: 2000
484+ max_size: 10000
485+ flush_timeout: 1s
477486 mapping:
478487 mode: none
479488
@@ -500,6 +509,13 @@ service:
500509 - resource/add-test-id
501510 receivers:
502511 - filelog
512+ telemetry:
513+ logs:
514+ level: DEBUG
515+ encoding: json
516+ disable_stacktrace: true
517+ output_paths:
518+ - {{.OTelLogFile}}
503519`
504520
505521func TestOtelLogsIngestion (t * testing.T ) {
@@ -517,8 +533,11 @@ func TestOtelLogsIngestion(t *testing.T) {
517533 // Prepare the OTel config.
518534 testId := info .Namespace
519535
520- tempDir := t .TempDir ()
536+ // Ensure everything is saved in case of test failure
537+ // this folder is also collected on CI.
538+ tempDir := aTesting .TempDir (t , ".." , ".." , ".." , "build" )
521539 inputFilePath := filepath .Join (tempDir , "input.log" )
540+ otelLogFilePath := filepath .Join (tempDir , "elastic-agent.ndjson" )
522541
523542 esHost , err := integration .GetESHost ()
524543 require .NoError (t , err , "failed to get ES host" )
@@ -535,6 +554,7 @@ func TestOtelLogsIngestion(t *testing.T) {
535554 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.ESEndpoint}}" , esHost )
536555 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.InputFilePath}}" , inputFilePath )
537556 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.TestId}}" , testId )
557+ logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.OTelLogFile}}" , otelLogFilePath )
538558
539559 cfgFilePath := filepath .Join (tempDir , "otel.yml" )
540560 require .NoError (t , os .WriteFile (cfgFilePath , []byte (logsIngestionConfig ), 0o600 ))
@@ -568,26 +588,30 @@ func TestOtelLogsIngestion(t *testing.T) {
568588 require .NoError (t , err )
569589 }
570590 inputFile .Close ()
571- t .Cleanup (func () {
572- _ = os .Remove (inputFilePath )
573- })
574591
575- actualHits := & struct { Hits int }{}
576- require .Eventually (t ,
577- func () bool {
578- findCtx , findCancel := context .WithTimeout (context .Background (), 10 * time .Second )
592+ // It takes about 45s to ingest all files on local tests,
593+ // so set the timeout to 5min to be on the safe side.
594+ require .EventuallyWithT (
595+ t ,
596+ func (c * assert.CollectT ) {
597+ findCtx , findCancel := context .WithTimeout (t .Context (), 10 * time .Second )
579598 defer findCancel ()
580599
581- docs , err := estools .GetLogsForIndexWithContext (findCtx , esClient , ".ds-logs-generic-default*" , map [string ]interface {}{
582- "Resource.test.id" : testId ,
583- })
584- require .NoError (t , err )
585-
586- actualHits .Hits = docs .Hits .Total .Value
587- return actualHits .Hits == logsCount
600+ docs , err := estools .GetAllLogsForIndexWithContext (
601+ findCtx ,
602+ esClient ,
603+ testId )
604+ require .NoError (c , err )
605+ require .Equalf (
606+ c ,
607+ logsCount ,
608+ docs .Hits .Total .Value ,
609+ "expecting %d events" ,
610+ logsCount )
588611 },
589- 2 * time .Minute , 1 * time .Second ,
590- "Expected %v logs, got %v" , logsCount , actualHits )
612+ 5 * time .Minute ,
613+ time .Second ,
614+ "did not find the expected number of events" )
591615
592616 cancel ()
593617 fixtureWg .Wait ()
0 commit comments