@@ -1198,93 +1198,66 @@ test('when profiling aggregator has duration set to default (0)', async (t) => {
11981198 } )
11991199} )
12001200
1201- test ( 'when `onConnect` is called to update profiling metrics' , async ( t ) => {
1202- t . beforeEach ( ( ctx ) => {
1203- ctx . nr = { }
1204- ctx . nr . agent = helper . loadMockedAgent ( null , false )
1205- } )
1206-
1207- t . afterEach ( ( ctx ) => {
1208- helper . unloadAgent ( ctx . nr . agent )
1209- } )
1210-
1211- await t . test ( 'should add startup profiling metrics when profiling is enabled' , ( t , end ) => {
1212- const { agent } = t . nr
1213-
1214- agent . config . profiling . enabled = true
1215- agent . config . profiling . include = [ 'heap' ]
1216-
1217- agent . onConnect ( false , ( ) => {
1218- const disabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } disabled` )
1219- const enabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } enabled` )
1220- const heap = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . HEAP } ` )
1221- const cpu = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . CPU } ` )
1222- assert . equal ( disabled , null )
1223- assert . equal ( enabled . callCount , 1 )
1224- assert . equal ( heap . callCount , 1 )
1225- assert . equal ( cpu , null )
1226- end ( )
1227- } )
1228- } )
1229-
1230- await t . test ( 'should only add profiling flag metric and not type when profiling is disabled' , ( t , end ) => {
1231- const { agent } = t . nr
1232-
1233- agent . onConnect ( false , ( ) => {
1234- const disabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } disabled` )
1235- const enabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } enabled` )
1236- const heap = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . HEAP } ` )
1237- const cpu = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . CPU } ` )
1238- assert . equal ( enabled , null )
1239- assert . equal ( disabled . callCount , 1 )
1240- assert . equal ( heap , null )
1241- assert . equal ( cpu , null )
1242- end ( )
1243- } )
1244- } )
1245- } )
1246-
1247- test ( 'when `profiling.enabled` changes' , async ( t ) => {
1248- t . beforeEach ( ( ctx ) => {
1249- ctx . nr = { }
1250- const config = {
1251- profiling : {
1252- enabled : false
1253- }
1254- }
1255- ctx . nr . agent = helper . loadMockedAgent ( config , false )
1256- } )
1201+ /**
1202+ * there is more to apply server-side configuration but it is unrelated to agent
1203+ * the flow is this:
1204+ * - collector returns a 409 which tells the agent to restart
1205+ * - stops harvester
1206+ * - shutdown the client(CollectorApi)
1207+ * - connects to collector
1208+ * - starts flow: preconnect, connect
1209+ * - connect calls `agent.reconfigure`
1210+ * - `agent.reconfigure` calls `config.onConnect` which wires up any changes from server(collector)
1211+ * - calls `agent.onConnect`
1212+ * - `agent.onConnect` calls `harvester.reconfigure` and creates profiling supportability metrics
1213+ *
1214+ * with all that being said we only have to call the important bits on agent/config manually to simulate the flow
1215+ * - `harvester.stop`
1216+ * - `config.onConnect` with the profiling.enabled change
1217+ * - `agent.onConnect`
1218+ */
1219+ test ( 'should start/stop profiling aggregator and log appropriate supportability metrics' , async ( t ) => {
1220+ const agent = helper . loadMockedAgent ( null , false )
12571221
1258- t . afterEach ( ( ctx ) => {
1259- helper . unloadAgent ( ctx . nr . agent )
1222+ t . after ( ( ) => {
1223+ helper . unloadAgent ( agent )
12601224 } )
12611225
1262- await t . test ( 'should handle changes accordingly' , ( t ) => {
1263- const { agent } = t . nr
1264- assert . equal ( agent . profilingData . enabled , false )
1265- assert . ok ( ! agent . profilingData . sendTimer )
1266- agent . config . onConnect ( { 'profiling.enabled' : true } )
1267- assert . equal ( agent . profilingData . enabled , true )
1268- assert . ok ( agent . profilingData . sendTimer )
1269- agent . config . onConnect ( { 'profiling.enabled' : false } )
1270- assert . equal ( agent . profilingData . enabled , false )
1271- assert . ok ( ! agent . profilingData . sendTimer )
1272- agent . config . onConnect ( { 'profiling.enabled' : true } )
1273- assert . equal ( agent . profilingData . enabled , true )
1274- assert . ok ( agent . profilingData . sendTimer )
1275- } )
1276-
1277- await t . test ( 'should add supportability metrics' , ( t ) => {
1278- const { agent } = t . nr
1279- assert . equal ( agent . profilingData . enabled , false )
1280- agent . config . onConnect ( { 'profiling.enabled' : true } )
1281- assert . equal ( agent . profilingData . enabled , true )
1282- const enabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } enabled` )
1283- assert . equal ( enabled . callCount , 1 )
1284- agent . config . onConnect ( { 'profiling.enabled' : false } )
1285- const disabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } disabled` )
1286- assert . equal ( disabled . callCount , 1 )
1287- } )
1226+ assert . ok ( ! agent . profilingData . sendTimer )
1227+ agent . harvester . stop ( )
1228+ // this is what would happen in server side config
1229+ agent . config . onConnect ( { 'profiling.enabled' : true } )
1230+ // not doing `onConnect` as this value isn't wired up for SSC
1231+ agent . config . profiling . include = [ 'heap' ]
1232+
1233+ await new Promise ( ( resolve ) => {
1234+ agent . onConnect ( false , resolve )
1235+ } )
1236+ let disabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } disabled` )
1237+ let enabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } enabled` )
1238+ let heap = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . HEAP } ` )
1239+ let cpu = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . CPU } ` )
1240+ assert . equal ( disabled , null )
1241+ assert . equal ( enabled . callCount , 1 )
1242+ assert . equal ( heap . callCount , 1 )
1243+ assert . equal ( cpu , null )
1244+ assert . ok ( agent . profilingData . sendTimer )
1245+ agent . harvester . stop ( )
1246+ agent . config . onConnect ( { 'profiling.enabled' : false } )
1247+ // clear out metrics so we can re-assert
1248+ agent . metrics . clear ( )
1249+ await new Promise ( ( resolve ) => {
1250+ agent . onConnect ( false , resolve )
1251+ } )
1252+ disabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } disabled` )
1253+ enabled = agent . metrics . getMetric ( `${ PROFILING . PREFIX } enabled` )
1254+ heap = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . HEAP } ` )
1255+ cpu = agent . metrics . getMetric ( `${ PROFILING . PREFIX } ${ PROFILING . CPU } ` )
1256+ assert . equal ( disabled . callCount , 1 )
1257+ assert . equal ( enabled , null )
1258+ assert . equal ( heap , null )
1259+ assert . equal ( cpu , null )
1260+ assert . ok ( ! agent . profilingData . sendTimer )
12881261} )
12891262
12901263test ( 'when event_harvest_config update on connect with a valid config' , async ( t ) => {
0 commit comments