@@ -1023,8 +1023,9 @@ func TestCoordinatorPolicyChangeUpdatesRuntimeAndOTelManagerWithOtelComponents(t
10231023 secretMarkerFunc : testSecretMarkerFunc ,
10241024 }
10251025
1026- // Create a policy with one input and one output (no otel configuration)
1027- cfg := config .MustNewConfigFrom (`
1026+ t .Run ("mixed policy" , func (t * testing.T ) {
1027+ // Create a policy with one input and one output (no otel configuration)
1028+ cfg := config .MustNewConfigFrom (`
10281029outputs:
10291030 default:
10301031 type: elasticsearch
@@ -1051,38 +1052,87 @@ service:
10511052 - nop
10521053` )
10531054
1054- // Send the policy change and make sure it was acknowledged.
1055- cfgChange := & configChange {cfg : cfg }
1056- configChan <- cfgChange
1057- coord .runLoopIteration (ctx )
1058- assert .True (t , cfgChange .acked , "Coordinator should ACK a successful policy change" )
1055+ // Send the policy change and make sure it was acknowledged.
1056+ cfgChange := & configChange {cfg : cfg }
1057+ configChan <- cfgChange
1058+ coord .runLoopIteration (ctx )
1059+ assert .True (t , cfgChange .acked , "Coordinator should ACK a successful policy change" )
1060+
1061+ // Make sure the runtime manager received the expected component update.
1062+ // An assert.Equal on the full component model doesn't play nice with
1063+ // the embedded proto structs, so instead we verify the important fields
1064+ // manually (sorry).
1065+ assert .True (t , updated , "Runtime manager should be updated after a policy change" )
1066+ require .Equal (t , 1 , len (components ), "Test policy should generate one component" )
1067+ assert .True (t , otelUpdated , "OTel manager should be updated after a policy change" )
1068+ require .NotNil (t , otelConfig , "OTel manager should have config" )
1069+
1070+ runtimeComponent := components [0 ]
1071+ assert .Equal (t , "system/metrics-default" , runtimeComponent .ID )
1072+ require .NotNil (t , runtimeComponent .Err , "Input with no spec should produce a component error" )
1073+ assert .Equal (t , "input not supported" , runtimeComponent .Err .Error (), "Input with no spec should report 'input not supported'" )
1074+ require .Equal (t , 2 , len (runtimeComponent .Units ))
1075+
1076+ units := runtimeComponent .Units
1077+ // Verify the input unit
1078+ assert .Equal (t , "system/metrics-default-test-other-input" , units [0 ].ID )
1079+ assert .Equal (t , client .UnitTypeInput , units [0 ].Type )
1080+ assert .Equal (t , "test-other-input" , units [0 ].Config .Id )
1081+ assert .Equal (t , "system/metrics" , units [0 ].Config .Type )
1082+
1083+ // Verify the output unit
1084+ assert .Equal (t , "system/metrics-default" , units [1 ].ID )
1085+ assert .Equal (t , client .UnitTypeOutput , units [1 ].Type )
1086+ assert .Equal (t , "elasticsearch" , units [1 ].Config .Type )
1087+ })
1088+
1089+ t .Run ("unsupported otel output option" , func (t * testing.T ) {
1090+ // Create a policy with one input and one output (no otel configuration)
1091+ cfg := config .MustNewConfigFrom (`
1092+ outputs:
1093+ default:
1094+ type: elasticsearch
1095+ hosts:
1096+ - localhost:9200
1097+ indices: [] # not supported by the elasticsearch exporter
1098+ inputs:
1099+ - id: test-input
1100+ type: filestream
1101+ use_output: default
1102+ _runtime_experimental: otel
1103+ - id: test-other-input
1104+ type: system/metrics
1105+ use_output: default
1106+ receivers:
1107+ nop:
1108+ exporters:
1109+ nop:
1110+ service:
1111+ pipelines:
1112+ traces:
1113+ receivers:
1114+ - nop
1115+ exporters:
1116+ - nop
1117+ ` )
10591118
1060- // Make sure the runtime manager received the expected component update.
1061- // An assert.Equal on the full component model doesn't play nice with
1062- // the embedded proto structs, so instead we verify the important fields
1063- // manually (sorry).
1064- assert .True (t , updated , "Runtime manager should be updated after a policy change" )
1065- require .Equal (t , 1 , len (components ), "Test policy should generate one component" )
1066- assert .True (t , otelUpdated , "OTel manager should be updated after a policy change" )
1067- require .NotNil (t , otelConfig , "OTel manager should have config" )
1119+ // Send the policy change and make sure it was acknowledged.
1120+ cfgChange := & configChange {cfg : cfg }
1121+ configChan <- cfgChange
1122+ coord .runLoopIteration (ctx )
1123+ assert .True (t , cfgChange .acked , "Coordinator should ACK a successful policy change" )
10681124
1069- runtimeComponent := components [0 ]
1070- assert .Equal (t , "system/metrics-default" , runtimeComponent .ID )
1071- require .NotNil (t , runtimeComponent .Err , "Input with no spec should produce a component error" )
1072- assert .Equal (t , "input not supported" , runtimeComponent .Err .Error (), "Input with no spec should report 'input not supported'" )
1073- require .Equal (t , 2 , len (runtimeComponent .Units ))
1125+ // Make sure the runtime manager received the expected component update.
1126+ // An assert.Equal on the full component model doesn't play nice with
1127+ // the embedded proto structs, so instead we verify the important fields
1128+ // manually (sorry).
1129+ assert .True (t , updated , "Runtime manager should be updated after a policy change" )
1130+ assert .True (t , otelUpdated , "OTel manager should be updated after a policy change" )
1131+ require .NotNil (t , otelConfig , "OTel manager should have config" )
10741132
1075- units := runtimeComponent .Units
1076- // Verify the input unit
1077- assert .Equal (t , "system/metrics-default-test-other-input" , units [0 ].ID )
1078- assert .Equal (t , client .UnitTypeInput , units [0 ].Type )
1079- assert .Equal (t , "test-other-input" , units [0 ].Config .Id )
1080- assert .Equal (t , "system/metrics" , units [0 ].Config .Type )
1133+ assert .Len (t , components , 2 , "both components should be assigned to the runtime manager" )
1134+ })
10811135
1082- // Verify the output unit
1083- assert .Equal (t , "system/metrics-default" , units [1 ].ID )
1084- assert .Equal (t , client .UnitTypeOutput , units [1 ].Type )
1085- assert .Equal (t , "elasticsearch" , units [1 ].Config .Type )
10861136}
10871137
10881138func TestCoordinatorReportsRuntimeManagerUpdateFailure (t * testing.T ) {
0 commit comments