@@ -569,15 +569,15 @@ class DynamicConfigUpdater {
569569
570570 void stopUpdateLoop () {
571571 if (_status != UpdaterStatus .running) return ;
572- log.info ('Stopping config update loop...' );
572+ log.info ('ConfigUpdater: Stopping config update loop...' );
573573 _status = UpdaterStatus .stopping;
574574 }
575575
576576 void startUpdateLoop (Config config) async {
577577 if (_status != UpdaterStatus .stopped) return ;
578578 _status = UpdaterStatus .running;
579579
580- log.info ('Starting config update loop...' );
580+ log.info ('ConfigUpdater: Starting config update loop...' );
581581
582582 // What we've decided:
583583 // 1. Each instance will **start** with a valid DynamicConfig
@@ -589,18 +589,51 @@ class DynamicConfigUpdater {
589589 _delay + Duration (milliseconds: _random.nextInt (1000 )),
590590 );
591591 if (_status != UpdaterStatus .running) {
592- log.info ('Stopped config update loop' );
592+ log.info ('ConfigUpdater: Stopped config update loop' );
593593 _status = UpdaterStatus .stopped;
594594 return ;
595595 }
596596 try {
597597 final dynamicConfig = await fetchDynamicConfig ();
598- config._dynamicConfig = dynamicConfig;
598+ final diffs = diffConfigChanges (
599+ config._dynamicConfig.toJson (),
600+ dynamicConfig.toJson (),
601+ );
602+ if (diffs.isNotEmpty) {
603+ log.info ('ConfigUpdater: ${diffs .join (',' )}' );
604+ config._dynamicConfig = dynamicConfig;
605+ }
599606 } catch (e, s) {
600- log.error ('Unable to fetch DynamicConfig!' , e, s);
607+ log.error ('ConfigUpdater: Unable to fetch DynamicConfig!' , e, s);
601608 }
602609 }
603610 }
611+
612+ /// Produce a simple diff of the changing flags.
613+ List <String > diffConfigChanges (
614+ Map <String , Object ?> oldFlags,
615+ Map <String , Object ?> newFlags, {
616+ List <String >? diffs,
617+ String chain = 'flags' ,
618+ }) {
619+ diffs ?? = < String > [];
620+
621+ for (final MapEntry (: key, : value) in oldFlags.entries) {
622+ if (value is Map ) {
623+ diffConfigChanges (
624+ value as Map <String , Object ?>,
625+ newFlags[key] as Map <String , Object ?>,
626+ diffs: diffs,
627+ chain: '$chain .$key ' ,
628+ );
629+ continue ;
630+ }
631+ if (value != newFlags[key]) {
632+ diffs.add ('$chain .$key $value -> ${newFlags [key ]}' );
633+ }
634+ }
635+ return diffs;
636+ }
604637}
605638
606639enum UpdaterStatus { stopped, running, stopping }
0 commit comments