Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class BatchBackfiller extends RequestHandler {
Future<void> _backfillExperimentalBranch(RepositorySlug slug) async {
final fsGrid = await _firestore.queryRecentCommitsAndTasks(
slug,
commitLimit: config.backfillerCommitLimit,
commitLimit: config.flags.backfillerCommitLimit,
branch: 'ios-experimental',
);
await _doBackfillFrom(slug, fsGrid, forceLowPriority: true);
Expand Down
43 changes: 38 additions & 5 deletions app_dart/lib/src/service/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,15 @@ class DynamicConfigUpdater {

void stopUpdateLoop() {
if (_status != UpdaterStatus.running) return;
log.info('Stopping config update loop...');
log.info('ConfigUpdater: Stopping config update loop...');
_status = UpdaterStatus.stopping;
}

void startUpdateLoop(Config config) async {
if (_status != UpdaterStatus.stopped) return;
_status = UpdaterStatus.running;

log.info('Starting config update loop...');
log.info('ConfigUpdater: Starting config update loop...');

// What we've decided:
// 1. Each instance will **start** with a valid DynamicConfig
Expand All @@ -589,18 +589,51 @@ class DynamicConfigUpdater {
_delay + Duration(milliseconds: _random.nextInt(1000)),
);
if (_status != UpdaterStatus.running) {
log.info('Stopped config update loop');
log.info('ConfigUpdater: Stopped config update loop');
_status = UpdaterStatus.stopped;
return;
}
try {
final dynamicConfig = await fetchDynamicConfig();
config._dynamicConfig = dynamicConfig;
final diffs = diffConfigChanges(
config._dynamicConfig.toJson(),
dynamicConfig.toJson(),
);
if (diffs.isNotEmpty) {
log.info('ConfigUpdater: ${diffs.join(',')}');
config._dynamicConfig = dynamicConfig;
}
} catch (e, s) {
log.error('Unable to fetch DynamicConfig!', e, s);
log.error('ConfigUpdater: Unable to fetch DynamicConfig!', e, s);
}
}
}

/// Produce a simple diff of the changing flags.
List<String> diffConfigChanges(
Map<String, Object?> oldFlags,
Map<String, Object?> newFlags, {
List<String>? diffs,
String chain = 'flags',
}) {
diffs ??= <String>[];

for (final MapEntry(:key, :value) in oldFlags.entries) {
if (value is Map) {
diffConfigChanges(
value as Map<String, Object?>,
newFlags[key] as Map<String, Object?>,
diffs: diffs,
chain: '$chain.$key',
);
continue;
}
if (value != newFlags[key]) {
diffs.add('$chain.$key $value -> ${newFlags[key]}');
}
}
return diffs;
}
}

enum UpdaterStatus { stopped, running, stopping }
38 changes: 35 additions & 3 deletions app_dart/test/service/dynamic_config_updater_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void main() {
bufferedLoggerOf(
containsOnce(
logThat(
message: equals('Starting config update loop...'),
message: equals('ConfigUpdater: Starting config update loop...'),
severity: atMostInfo,
),
),
Expand All @@ -86,7 +86,7 @@ void main() {
bufferedLoggerOf(
containsOnce(
logThat(
message: equals('Stopping config update loop...'),
message: equals('ConfigUpdater: Stopping config update loop...'),
severity: atMostInfo,
),
),
Expand All @@ -97,7 +97,7 @@ void main() {
bufferedLoggerOf(
containsOnce(
logThat(
message: equals('Stopped config update loop'),
message: equals('ConfigUpdater: Stopped config update loop'),
severity: atMostInfo,
),
),
Expand Down Expand Up @@ -131,6 +131,29 @@ void main() {
);
expect(config.flags.backfillerCommitLimit, 100);
});

test('handles updating values', () async {
updater.startUpdateLoop(config);
await Future<void>.delayed(const Duration(milliseconds: 50));
mockHttpFile = updatedConfigYaml;
await Future<void>.delayed(const Duration(milliseconds: 50));
updater.stopUpdateLoop();

expect(config.flags.backfillerCommitLimit, 200);
expect(
log,
bufferedLoggerOf(
containsOnce(
logThat(
message: equals(
'ConfigUpdater: flags.backfillerCommitLimit 100 -> 200',
),
severity: atMostInfo,
),
),
),
);
});
}

final class _FakeRandom extends Fake implements Random {
Expand All @@ -149,3 +172,12 @@ const goodConfigYaml = '''

backfillerCommitLimit: 100
''';

const updatedConfigYaml = '''
# Defines the config options for Flutter CI (Cocoon)
#
# The schema for this file is defined in DynamicConfig of
# app_dart/lib/src/service/config.dart

backfillerCommitLimit: 200
''';