@@ -8,6 +8,7 @@ package ess
8
8
9
9
import (
10
10
"archive/zip"
11
+ "bytes"
11
12
"context"
12
13
"io"
13
14
"io/fs"
@@ -16,6 +17,7 @@ import (
16
17
"path/filepath"
17
18
"strings"
18
19
"testing"
20
+ "text/template"
19
21
"time"
20
22
21
23
"github.com/stretchr/testify/assert"
@@ -295,6 +297,91 @@ func TestRedactFleetSecretPathsDiagnostics(t *testing.T) {
295
297
assert .Equal (t , "<REDACTED>" , yObj .Inputs [0 ].CustomAttr )
296
298
}
297
299
300
+ func TestBeatDiagnostics (t * testing.T ) {
301
+ define .Require (t , define.Requirements {
302
+ Group : integration .Default ,
303
+ Local : false ,
304
+ })
305
+
306
+ configTemplate := `
307
+ inputs:
308
+ - id: filestream-filebeat
309
+ type: filestream
310
+ paths:
311
+ - /var/log/system.log
312
+ prospector.scanner.fingerprint.enabled: false
313
+ file_identity.native: ~
314
+ use_output: default
315
+ _runtime_experimental: {{ .Runtime }}
316
+ outputs:
317
+ default:
318
+ type: elasticsearch
319
+ hosts: [http://localhost:9200]
320
+ api_key: placeholder
321
+ agent.monitoring.enabled: false
322
+ `
323
+
324
+ var filebeatSetup = map [string ]integrationtest.ComponentState {
325
+ "filestream-default" : {
326
+ State : integrationtest .NewClientState (client .Healthy ),
327
+ Units : map [integrationtest.ComponentUnitKey ]integrationtest.ComponentUnitState {
328
+ integrationtest.ComponentUnitKey {UnitType : client .UnitTypeOutput , UnitID : "filestream-default" }: {
329
+ State : integrationtest .NewClientState (client .Healthy ),
330
+ },
331
+ integrationtest.ComponentUnitKey {UnitType : client .UnitTypeInput , UnitID : "filestream-filebeat" }: {
332
+ State : integrationtest .NewClientState (client .Healthy ),
333
+ },
334
+ },
335
+ },
336
+ }
337
+ f , err := define .NewFixtureFromLocalBuild (t , define .Version (), integrationtest .WithAllowErrors ())
338
+ require .NoError (t , err )
339
+
340
+ ctx , cancel := testcontext .WithDeadline (t , context .Background (), time .Now ().Add (10 * time .Minute ))
341
+ defer cancel ()
342
+ err = f .Prepare (ctx )
343
+ require .NoError (t , err )
344
+
345
+ t .Run ("filebeat process" , func (t * testing.T ) {
346
+ var configBuffer bytes.Buffer
347
+ require .NoError (t ,
348
+ template .Must (template .New ("config" ).Parse (configTemplate )).Execute (& configBuffer , map [string ]any {
349
+ "Runtime" : "process" ,
350
+ }))
351
+ expectedCompDiagnosticsFiles := append (compDiagnosticsFiles ,
352
+ "registry.tar.gz" ,
353
+ "input_metrics.json" ,
354
+ "beat_metrics.json" ,
355
+ "beat-rendered-config.yml" ,
356
+ "global_processors.txt" ,
357
+ "filestream-filebeat/error.txt" ,
358
+ "filestream-default/error.txt" ,
359
+ )
360
+ err = f .Run (ctx , integrationtest.State {
361
+ Configure : configBuffer .String (),
362
+ AgentState : integrationtest .NewClientState (client .Healthy ),
363
+ After : testDiagnosticsFactory (t , filebeatSetup , diagnosticsFiles , expectedCompDiagnosticsFiles , f , []string {"diagnostics" , "collect" }),
364
+ })
365
+ assert .NoError (t , err )
366
+ })
367
+
368
+ t .Run ("filebeat receiver" , func (t * testing.T ) {
369
+ var configBuffer bytes.Buffer
370
+ require .NoError (t ,
371
+ template .Must (template .New ("config" ).Parse (configTemplate )).Execute (& configBuffer , map [string ]any {
372
+ "Runtime" : "otel" ,
373
+ }))
374
+ // currently we don't expect any diagnostics files for beats receivers
375
+ var expectedCompDiagnosticsFiles []string
376
+ err = f .Run (ctx , integrationtest.State {
377
+ Configure : configBuffer .String (),
378
+ AgentState : integrationtest .NewClientState (client .Healthy ),
379
+ After : testDiagnosticsFactory (t , filebeatSetup , diagnosticsFiles , expectedCompDiagnosticsFiles , f , []string {"diagnostics" , "collect" }),
380
+ })
381
+ assert .NoError (t , err )
382
+ })
383
+ }
384
+
298
385
func testDiagnosticsFactory (t * testing.T , compSetup map [string ]integrationtest.ComponentState , diagFiles []string , diagCompFiles []string , fix * integrationtest.Fixture , cmd []string ) func (ctx context.Context ) error {
299
386
return func (ctx context.Context ) error {
300
387
diagZip , err := fix .ExecDiagnostics (ctx , cmd ... )
0 commit comments