@@ -56,7 +56,7 @@ func (tl testLogger) Errorf(_ context.Context, format string, args ...any) {
56
56
}
57
57
58
58
func defaultConnectingHandler (connectionCallbacks server.ConnectionCallbacksStruct ) func (request * http.Request ) types.ConnectionResponse {
59
- return func (request * http.Request ) types.ConnectionResponse {
59
+ return func (_ * http.Request ) types.ConnectionResponse {
60
60
return types.ConnectionResponse {
61
61
Accept : true ,
62
62
ConnectionCallbacks : connectionCallbacks ,
@@ -125,7 +125,8 @@ func newOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, ca
125
125
require .Fail (t , "Agent connection has not been established" )
126
126
}
127
127
128
- agentConn .Load ().(types.Connection ).Send (context .Background (), msg )
128
+ err = agentConn .Load ().(types.Connection ).Send (context .Background (), msg )
129
+ require .NoError (t , err )
129
130
}
130
131
t .Cleanup (func () {
131
132
shutdown ()
@@ -217,8 +218,9 @@ func TestSupervisorStartsCollectorWithRemoteConfig(t *testing.T) {
217
218
cfg , ok := agentConfig .Load ().(string )
218
219
if ok {
219
220
// The effective config may be structurally different compared to what was sent,
220
- // so just check that it includes some strings we know to be unique to the remote config.
221
- return strings .Contains (cfg , inputFile .Name ()) && strings .Contains (cfg , outputFile .Name ())
221
+ // and will also have some data redacted,
222
+ // so just check that it includes the filelog receiver
223
+ return strings .Contains (cfg , "filelog" )
222
224
}
223
225
224
226
return false
@@ -340,9 +342,9 @@ func TestSupervisorConfiguresCapabilities(t *testing.T) {
340
342
waitForSupervisorConnection (server .supervisorConnected , true )
341
343
342
344
require .Eventually (t , func () bool {
343
- cap := capabilities .Load ()
345
+ caps := capabilities .Load ()
344
346
345
- return cap == uint64 (protobufs .AgentCapabilities_AgentCapabilities_ReportsStatus )
347
+ return caps == uint64 (protobufs .AgentCapabilities_AgentCapabilities_ReportsStatus )
346
348
}, 5 * time .Second , 250 * time .Millisecond )
347
349
}
348
350
@@ -418,6 +420,82 @@ func TestSupervisorBootstrapsCollector(t *testing.T) {
418
420
}, 5 * time .Second , 250 * time .Millisecond )
419
421
}
420
422
423
+ func TestSupervisorReportsEffectiveConfig (t * testing.T ) {
424
+ var agentConfig atomic.Value
425
+ server := newOpAMPServer (
426
+ t ,
427
+ defaultConnectingHandler ,
428
+ server.ConnectionCallbacksStruct {
429
+ OnMessageFunc : func (_ context.Context , _ types.Connection , message * protobufs.AgentToServer ) * protobufs.ServerToAgent {
430
+ if message .EffectiveConfig != nil {
431
+ config := message .EffectiveConfig .ConfigMap .ConfigMap ["" ]
432
+ if config != nil {
433
+ agentConfig .Store (string (config .Body ))
434
+ }
435
+ }
436
+
437
+ return & protobufs.ServerToAgent {}
438
+ },
439
+ })
440
+
441
+ s := newSupervisor (t , "basic" , map [string ]string {"url" : server .addr })
442
+ defer s .Shutdown ()
443
+
444
+ waitForSupervisorConnection (server .supervisorConnected , true )
445
+
446
+ // Create input and output files so we can "communicate" with a Collector binary.
447
+ // The testing package will automatically clean these up after each test.
448
+ tempDir := t .TempDir ()
449
+ testKeyFile , err := os .CreateTemp (tempDir , "confKey" )
450
+ require .NoError (t , err )
451
+ n , err := testKeyFile .Write ([]byte (testKeyFile .Name ()))
452
+ require .NoError (t , err )
453
+ require .NotZero (t , n )
454
+
455
+ colCfgTpl , err := os .ReadFile (path .Join ("testdata" , "collector" , "split_config.yaml" ))
456
+ require .NoError (t , err )
457
+
458
+ templ , err := template .New ("" ).Parse (string (colCfgTpl ))
459
+ require .NoError (t , err )
460
+
461
+ var cfg bytes.Buffer
462
+ err = templ .Execute (
463
+ & cfg ,
464
+ map [string ]string {
465
+ "TestKeyFile" : testKeyFile .Name (),
466
+ },
467
+ )
468
+ require .NoError (t , err )
469
+
470
+ h := sha256 .New ()
471
+ if _ , err := io .Copy (h , bytes .NewBuffer (cfg .Bytes ())); err != nil {
472
+ t .Fatal (err )
473
+ }
474
+
475
+ server .sendToSupervisor (& protobufs.ServerToAgent {
476
+ RemoteConfig : & protobufs.AgentRemoteConfig {
477
+ Config : & protobufs.AgentConfigMap {
478
+ ConfigMap : map [string ]* protobufs.AgentConfigFile {
479
+ "" : {Body : cfg .Bytes ()},
480
+ },
481
+ },
482
+ ConfigHash : h .Sum (nil ),
483
+ },
484
+ })
485
+
486
+ require .Eventually (t , func () bool {
487
+ cfg , ok := agentConfig .Load ().(string )
488
+ if ok {
489
+ // The effective config may be structurally different compared to what was sent,
490
+ // and currently has most values redacted,
491
+ // so just check that it includes some strings we know to be unique to the remote config.
492
+ return strings .Contains (cfg , "test_key:" )
493
+ }
494
+
495
+ return false
496
+ }, 5 * time .Second , 500 * time .Millisecond , "Collector never reported effective config" )
497
+ }
498
+
421
499
func TestSupervisorAgentDescriptionConfigApplies (t * testing.T ) {
422
500
// Load the Supervisor config so we can get the location of
423
501
// the Collector that will be run.
@@ -673,7 +751,7 @@ func TestSupervisorOpAMPConnectionSettings(t *testing.T) {
673
751
OnConnectedFunc : func (_ context.Context , _ types.Connection ) {
674
752
connectedToNewServer .Store (true )
675
753
},
676
- OnMessageFunc : func (_ context.Context , _ types.Connection , message * protobufs.AgentToServer ) * protobufs.ServerToAgent {
754
+ OnMessageFunc : func (_ context.Context , _ types.Connection , _ * protobufs.AgentToServer ) * protobufs.ServerToAgent {
677
755
return & protobufs.ServerToAgent {}
678
756
},
679
757
})
0 commit comments