@@ -26,6 +26,8 @@ import (
2626 "github.com/stretchr/testify/assert"
2727 "github.com/stretchr/testify/require"
2828
29+ "github.com/elastic/elastic-agent-libs/testing/fs"
30+
2931 "github.com/elastic/elastic-agent-libs/mapstr"
3032 "github.com/elastic/elastic-agent-libs/testing/estools"
3133 "github.com/elastic/elastic-agent-libs/transport/tlscommontest"
@@ -463,6 +465,12 @@ exporters:
463465 elasticsearch:
464466 api_key: {{.ESApiKey}}
465467 endpoint: {{.ESEndpoint}}
468+ logs_index: {{.TestId}}
469+ sending_queue:
470+ wait_for_result: true
471+ block_on_overflow: true
472+ enabled: true
473+ queue_size: 10000
466474 mapping:
467475 mode: none
468476
@@ -489,6 +497,13 @@ service:
489497 - resource/add-test-id
490498 receivers:
491499 - filelog
500+ telemetry:
501+ logs:
502+ level: DEBUG
503+ encoding: json
504+ disable_stacktrace: true
505+ output_paths:
506+ - {{.OTelLogFile}}
492507`
493508
494509func TestOtelLogsIngestion (t * testing.T ) {
@@ -506,8 +521,9 @@ func TestOtelLogsIngestion(t *testing.T) {
506521 // Prepare the OTel config.
507522 testId := info .Namespace
508523
509- tempDir := t .TempDir ()
524+ tempDir := fs .TempDir (t , ".." , ".." , ".." , "build" )
510525 inputFilePath := filepath .Join (tempDir , "input.log" )
526+ otelLogFilePath := filepath .Join (tempDir , "elastic-agent.ndjson" )
511527
512528 esHost , err := integration .GetESHost ()
513529 require .NoError (t , err , "failed to get ES host" )
@@ -524,6 +540,7 @@ func TestOtelLogsIngestion(t *testing.T) {
524540 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.ESEndpoint}}" , esHost )
525541 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.InputFilePath}}" , inputFilePath )
526542 logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.TestId}}" , testId )
543+ logsIngestionConfig = strings .ReplaceAll (logsIngestionConfig , "{{.OTelLogFile}}" , otelLogFilePath )
527544
528545 cfgFilePath := filepath .Join (tempDir , "otel.yml" )
529546 require .NoError (t , os .WriteFile (cfgFilePath , []byte (logsIngestionConfig ), 0o600 ))
@@ -557,26 +574,30 @@ func TestOtelLogsIngestion(t *testing.T) {
557574 require .NoError (t , err )
558575 }
559576 inputFile .Close ()
560- t .Cleanup (func () {
561- _ = os .Remove (inputFilePath )
562- })
563577
564- actualHits := & struct { Hits int }{}
565- require .Eventually (t ,
566- func () bool {
567- findCtx , findCancel := context .WithTimeout (context .Background (), 10 * time .Second )
578+ // It takes about 45s to ingest all files on local tests,
579+ // so set the timeout to 5min to be on the safe side.
580+ require .EventuallyWithT (
581+ t ,
582+ func (c * assert.CollectT ) {
583+ findCtx , findCancel := context .WithTimeout (t .Context (), 10 * time .Second )
568584 defer findCancel ()
569585
570- docs , err := estools .GetLogsForIndexWithContext (findCtx , esClient , ".ds-logs-generic-default*" , map [string ]interface {}{
571- "Resource.test.id" : testId ,
572- })
573- require .NoError (t , err )
574-
575- actualHits .Hits = docs .Hits .Total .Value
576- return actualHits .Hits == logsCount
586+ docs , err := estools .GetAllLogsForIndexWithContext (
587+ findCtx ,
588+ esClient ,
589+ testId )
590+ require .NoError (c , err )
591+ require .Equalf (
592+ c ,
593+ logsCount ,
594+ docs .Hits .Total .Value ,
595+ "expecting %d events" ,
596+ logsCount )
577597 },
578- 2 * time .Minute , 1 * time .Second ,
579- "Expected %v logs, got %v" , logsCount , actualHits )
598+ 5 * time .Minute ,
599+ time .Second ,
600+ "did not find the expected number of events" )
580601
581602 cancel ()
582603 fixtureWg .Wait ()
0 commit comments