@@ -56,7 +56,7 @@ func (tl testLogger) Errorf(_ context.Context, format string, args ...any) {
5656}
5757
5858func 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 {
6060 return types.ConnectionResponse {
6161 Accept : true ,
6262 ConnectionCallbacks : connectionCallbacks ,
@@ -125,7 +125,8 @@ func newOpAMPServer(t *testing.T, connectingCallback onConnectingFuncFactory, ca
125125 require .Fail (t , "Agent connection has not been established" )
126126 }
127127
128- agentConn .Load ().(types.Connection ).Send (context .Background (), msg )
128+ err = agentConn .Load ().(types.Connection ).Send (context .Background (), msg )
129+ require .NoError (t , err )
129130 }
130131 t .Cleanup (func () {
131132 shutdown ()
@@ -217,8 +218,9 @@ func TestSupervisorStartsCollectorWithRemoteConfig(t *testing.T) {
217218 cfg , ok := agentConfig .Load ().(string )
218219 if ok {
219220 // 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" )
222224 }
223225
224226 return false
@@ -340,9 +342,9 @@ func TestSupervisorConfiguresCapabilities(t *testing.T) {
340342 waitForSupervisorConnection (server .supervisorConnected , true )
341343
342344 require .Eventually (t , func () bool {
343- cap := capabilities .Load ()
345+ caps := capabilities .Load ()
344346
345- return cap == uint64 (protobufs .AgentCapabilities_AgentCapabilities_ReportsStatus )
347+ return caps == uint64 (protobufs .AgentCapabilities_AgentCapabilities_ReportsStatus )
346348 }, 5 * time .Second , 250 * time .Millisecond )
347349}
348350
@@ -418,6 +420,82 @@ func TestSupervisorBootstrapsCollector(t *testing.T) {
418420 }, 5 * time .Second , 250 * time .Millisecond )
419421}
420422
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+
421499func TestSupervisorAgentDescriptionConfigApplies (t * testing.T ) {
422500 // Load the Supervisor config so we can get the location of
423501 // the Collector that will be run.
@@ -673,7 +751,7 @@ func TestSupervisorOpAMPConnectionSettings(t *testing.T) {
673751 OnConnectedFunc : func (_ context.Context , _ types.Connection ) {
674752 connectedToNewServer .Store (true )
675753 },
676- OnMessageFunc : func (_ context.Context , _ types.Connection , message * protobufs.AgentToServer ) * protobufs.ServerToAgent {
754+ OnMessageFunc : func (_ context.Context , _ types.Connection , _ * protobufs.AgentToServer ) * protobufs.ServerToAgent {
677755 return & protobufs.ServerToAgent {}
678756 },
679757 })
0 commit comments