@@ -10,6 +10,7 @@ import (
10
10
"bufio"
11
11
"bytes"
12
12
"context"
13
+ "encoding/json"
13
14
"fmt"
14
15
"net/http"
15
16
"net/http/httputil"
@@ -37,11 +38,11 @@ outputs:
37
38
hosts:
38
39
- %s
39
40
protocol: http
40
- preset: balanced
41
-
41
+ preset: latency
42
42
inputs:
43
43
- type: filestream
44
44
id: your-input-id
45
+ log_level: debug
45
46
streams:
46
47
- id: your-filestream-stream-id
47
48
data_stream:
@@ -84,10 +85,10 @@ func TestEventLogFile(t *testing.T) {
84
85
agentFixture , err := define .NewFixtureFromLocalBuild (t , define .Version ())
85
86
require .NoError (t , err )
86
87
87
- esURL := startMockES (t )
88
+ esURL := startMockES (t , 0 , 0 , 0 , 0 )
88
89
89
90
logFilepath := path .Join (t .TempDir (), t .Name ())
90
- generateLogFile (t , logFilepath , time .Millisecond * 100 , 1 )
91
+ generateLogFile (t , logFilepath , time .Millisecond * 100 , 20 )
91
92
92
93
cfg := fmt .Sprintf (eventLogConfig , esURL , logFilepath )
93
94
@@ -126,6 +127,7 @@ func TestEventLogFile(t *testing.T) {
126
127
127
128
// Now the Elastic-Agent is running, so validate the Event log file.
128
129
requireEventLogFileExistsWithData (t , agentFixture )
130
+ requireNoCopyProcessorError (t , agentFixture )
129
131
130
132
// The diagnostics command is already tested by another test,
131
133
// here we just want to validate the events log behaviour
@@ -169,7 +171,7 @@ func TestEventLogOutputConfiguredViaFleet(t *testing.T) {
169
171
agentFixture , err := define .NewFixtureFromLocalBuild (t , define .Version ())
170
172
require .NoError (t , err )
171
173
172
- _ , outputID := createMockESOutput (t , info )
174
+ _ , outputID := createMockESOutput (t , info , 0 , 0 , 100 , 0 )
173
175
policyName := fmt .Sprintf ("%s-%s" , t .Name (), uuid .Must (uuid .NewV4 ()).String ())
174
176
policyID , enrollmentAPIKey := createPolicy (
175
177
t ,
@@ -307,7 +309,7 @@ func addOverwriteToPolicy(t *testing.T, info *define.Info, policyName, policyID
307
309
}
308
310
}
309
311
310
- func requireEventLogFileExistsWithData (t * testing.T , agentFixture * atesting.Fixture ) {
312
+ func readEventLogFile (t * testing.T , agentFixture * atesting.Fixture ) string {
311
313
// Now the Elastic-Agent is running, so validate the Event log file.
312
314
// Because the path changes based on the Elastic-Agent version, we
313
315
// use glob to find the file
@@ -338,8 +340,39 @@ func requireEventLogFileExistsWithData(t *testing.T, agentFixture *atesting.Fixt
338
340
t .Fatalf ("cannot read file '%s': %s" , logFileName , err )
339
341
}
340
342
341
- logEntry := string (logEntryBytes )
342
- expectedStr := "Cannot index event"
343
+ return string (logEntryBytes )
344
+ }
345
+
346
+ func requireNoCopyProcessorError (t * testing.T , agentFixture * atesting.Fixture ) {
347
+ data := readEventLogFile (t , agentFixture )
348
+ for _ , line := range strings .Split (data , "\n " ) {
349
+ logEntry := struct {
350
+ LogLogger string `json:"log.logger"`
351
+ Message string `json:"message"`
352
+ }{}
353
+
354
+ if len (line ) == 0 {
355
+ continue
356
+ }
357
+ if err := json .Unmarshal ([]byte (line ), & logEntry ); err != nil {
358
+ t .Fatalf ("could not parse log entry: %q" , line )
359
+ }
360
+
361
+ if logEntry .LogLogger == "copy_fields" {
362
+ if strings .Contains (logEntry .Message , "Failed to copy fields" ) {
363
+ if strings .Contains (logEntry .Message , "already exists, drop or rename this field first" ) {
364
+ t .Fatal ("copy_fields processor must not fail" )
365
+ }
366
+ }
367
+ }
368
+ }
369
+ }
370
+
371
+ func requireEventLogFileExistsWithData (t * testing.T , agentFixture * atesting.Fixture ) {
372
+ logEntry := readEventLogFile (t , agentFixture )
373
+ // That's part of the generated event that is logged by the 'processor'
374
+ // logger at level debug
375
+ expectedStr := "TestEventLogFile"
343
376
if ! strings .Contains (logEntry , expectedStr ) {
344
377
t .Errorf (
345
378
"did not find the expected log entry ('%s') in the events log file" ,
0 commit comments