Skip to content

Commit 85385e6

Browse files
authored
Be clearer about what property values workers are missing (#2121)
1 parent 67a5f9e commit 85385e6

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

nativelink-scheduler/src/worker_capability_index.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,18 @@ impl WorkerCapabilityIndex {
134134
action_properties: &PlatformProperties,
135135
full_worker_logging: bool,
136136
) -> HashSet<WorkerId> {
137-
if action_properties.properties.is_empty() {
138-
// No properties required, all workers match
139-
return self.all_workers.clone();
140-
}
141-
142137
if self.all_workers.is_empty() {
143138
if full_worker_logging {
144139
info!("No workers available to match!");
145140
}
146141
return HashSet::new();
147142
}
148143

144+
if action_properties.properties.is_empty() {
145+
// No properties required, all workers match
146+
return self.all_workers.clone();
147+
}
148+
149149
let mut candidates: Option<HashSet<WorkerId>> = None;
150150

151151
for (name, value) in &action_properties.properties {
@@ -167,8 +167,14 @@ impl WorkerCapabilityIndex {
167167
// Early exit if no candidates
168168
if internal_candidates.is_empty() {
169169
if full_worker_logging {
170+
let values: Vec<_> = self
171+
.exact_index
172+
.iter()
173+
.filter(|pk| &pk.0.name == name)
174+
.map(|pk| pk.0.value.clone())
175+
.collect();
170176
info!(
171-
"No candidate workers due to a lack of matching {name} = {value:?}"
177+
"No candidate workers due to a lack of matching '{name}' = {value:?}. Workers have: {values:?}"
172178
);
173179
}
174180
return HashSet::new();
@@ -196,7 +202,9 @@ impl WorkerCapabilityIndex {
196202

197203
if internal_candidates.is_empty() {
198204
if full_worker_logging {
199-
info!("No candidate workers due to a lack of key {name}");
205+
info!(
206+
"No candidate workers due to a lack of key '{name}'. Job asked for {value:?}"
207+
);
200208
}
201209
return HashSet::new();
202210
}

nativelink-scheduler/tests/worker_capability_index_test.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ fn make_properties(props: &[(&str, PlatformPropertyValue)]) -> PlatformPropertie
3333
}
3434

3535
#[test]
36+
#[tracing_test::traced_test]
3637
fn test_empty_index() {
3738
let index = WorkerCapabilityIndex::new();
3839
let props = make_properties(&[]);
3940
let result = index.find_matching_workers(&props, true);
4041
assert!(result.is_empty());
42+
43+
assert!(logs_contain("No workers available to match!"));
4144
}
4245

4346
#[test]
@@ -236,3 +239,38 @@ fn test_ignore_property() {
236239
let result = index.find_matching_workers(&props, true);
237240
assert_eq!(result.len(), 2);
238241
}
242+
243+
#[test]
244+
#[tracing_test::traced_test]
245+
fn test_no_exact_property_match() {
246+
let mut index = WorkerCapabilityIndex::new();
247+
let worker1 = make_worker_id("worker1");
248+
index.add_worker(
249+
&worker1,
250+
&make_properties(&[("os", PlatformPropertyValue::Exact("windows".to_string()))]),
251+
);
252+
253+
let props = make_properties(&[("os", PlatformPropertyValue::Exact("linux".to_string()))]);
254+
let result = index.find_matching_workers(&props, true);
255+
assert_eq!(result.len(), 0);
256+
257+
assert!(logs_contain(
258+
"No candidate workers due to a lack of matching 'os' = Exact(\"linux\"). Workers have: [Exact(\"windows\")]"
259+
));
260+
}
261+
262+
#[test]
263+
#[tracing_test::traced_test]
264+
fn test_no_priority_property_match() {
265+
let mut index = WorkerCapabilityIndex::new();
266+
let worker1 = make_worker_id("worker1");
267+
index.add_worker(&worker1, &make_properties(&[]));
268+
269+
let props = make_properties(&[("os", PlatformPropertyValue::Priority("linux".to_string()))]);
270+
let result = index.find_matching_workers(&props, true);
271+
assert_eq!(result.len(), 0);
272+
273+
assert!(logs_contain(
274+
"No candidate workers due to a lack of key 'os'. Job asked for Priority(\"linux\")"
275+
));
276+
}

0 commit comments

Comments
 (0)