Skip to content

Commit 54f1bbd

Browse files
fix(scaler): count providers towards spread requirements
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
1 parent 1b1cb4c commit 54f1bbd

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/scaler/spreadscaler/provider.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<S: ReadStore + Send + Sync + Clone> Scaler for ProviderSpreadScaler<S> {
132132
.flat_map(|(spread, count)| {
133133
let eligible_hosts = eligible_hosts(&hosts, spread);
134134
let eligible_count = eligible_hosts.len();
135-
// Partition hosts into ones running this provider (no matter what is running it, and others
135+
// Partition hosts into ones running this provider (no matter what is running it), and others
136136
let (running, other): (HashMap<&String, &Host>, HashMap<&String, &Host>) =
137137
eligible_hosts.into_iter().partition(|(_host_id, host)| {
138138
host.providers
@@ -145,8 +145,10 @@ impl<S: ReadStore + Send + Sync + Clone> Scaler for ProviderSpreadScaler<S> {
145145
});
146146
// Get the count of all running providers
147147
let current_running = running.len();
148-
// Now get only the hosts running a provider we own
149-
let running_for_spread = running.into_iter().filter(|(_host_id, host)| {
148+
// NOTE(#120): Now partition providers into ones running for this spread, and ones running for
149+
// either other spreads or no spread at all. Hosts cannot run multiple providers with the same
150+
// link name and contract id, so wadm currently will allow these to count up to the total.
151+
let (running_for_spread, running_for_other): (HashMap<&String, &Host>, HashMap<&String, &Host>) = running.into_iter().partition(|(_host_id, host)| {
150152
host.providers
151153
.get(&ProviderInfo {
152154
contract_id: contract_id.to_string(),
@@ -166,12 +168,8 @@ impl<S: ReadStore + Send + Sync + Clone> Scaler for ProviderSpreadScaler<S> {
166168
}
167169
has_annotation
168170
})
169-
})
170-
.unwrap_or_else(|| {
171-
trace!(%provider_id, "Couldn't find matching provider in host provider list");
172-
false
173-
})
174-
}).collect::<HashMap<_, _>>();
171+
}).unwrap_or(false)
172+
});
175173
trace!(current_for_spread = %running_for_spread.len(), %current_running, expected = %count, eligible_hosts = %eligible_count, %provider_id, "Calculated running providers, reconciling with expected count");
176174
match current_running.cmp(count) {
177175
// We can only stop providers that we own, so if we have more than we need, we
@@ -195,11 +193,10 @@ impl<S: ReadStore + Send + Sync + Clone> Scaler for ProviderSpreadScaler<S> {
195193
.collect::<Vec<Command>>()
196194
}
197195
Ordering::Less => {
198-
let num_to_start = count - current_running;
199-
200-
// NOTE(brooksmtownsend): It's possible that this does not fully satisfy
201-
// the requirements if we are unable to form enough start commands. Update
202-
// status accordingly once we have a way to.
196+
// NOTE(#120): Providers running for other spreads or for no spreads can count for up to the total
197+
// number of providers to satisfy a spread. We do not count them above because we don't want to
198+
// end up in an infinite loop of stopping other managed providers.
199+
let num_to_start = count.saturating_sub(current_running).saturating_sub(running_for_other.len());
203200

204201
// Take `num_to_start` commands from this iterator
205202
let commands = other

0 commit comments

Comments
 (0)