Skip to content

Commit 9998135

Browse files
committed
fail fast on the first missing materialization info
1 parent b49a7e0 commit 9998135

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

confidence-resolver/protos/confidence/flags/resolver/v1/api.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ message ResolveFlagsRequest {
9494
// if the resolver should handle sticky assignments
9595
bool process_sticky = 6;
9696

97-
// Context about the materialization required for the resolve
97+
// Context about the materialization required for the resolve
9898
MaterializationContext materialization_context = 7;
99+
100+
// if a materialization info is missing, we want tor return to the caller immediately
101+
bool fail_fast_on_sticky = 8;
99102
}
100103

101104
message MaterializationContext {

confidence-resolver/src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,15 @@ impl<'a, H: Host> AccountResolver<'a, H> {
509509
return Err(err.message.to_string());
510510
} else {
511511
missing_materialization_items.extend(err.missing_materializations);
512+
if request.fail_fast_on_sticky {
513+
return Ok(ResolveFlagResponseResult {
514+
resolve_result: Some(ResolveResult::MissingMaterializations(
515+
MissingMaterializations {
516+
items: missing_materialization_items,
517+
},
518+
)),
519+
});
520+
}
512521
}
513522
}
514523
}
@@ -612,6 +621,7 @@ impl<'a, H: Host> AccountResolver<'a, H> {
612621
client_secret: request.client_secret.clone(),
613622
apply: request.apply.clone(),
614623
materialization_context: None,
624+
fail_fast_on_sticky: false,
615625
process_sticky: false,
616626
});
617627

@@ -838,7 +848,11 @@ impl<'a, H: Host> AccountResolver<'a, H> {
838848
}
839849
})
840850
{
841-
let variant = self.state.flags[flag.name.as_str()]
851+
let variant = self
852+
.state
853+
.flags
854+
.get(flag.name.as_str())
855+
.unwrap()
842856
.variants
843857
.iter()
844858
.find(|v| v.name == *variant_name)
@@ -1509,6 +1523,7 @@ mod tests {
15091523
let resolve_flag_req = flags_resolver::ResolveFlagsRequest {
15101524
evaluation_context: Some(Struct::default()),
15111525
client_secret: SECRET.to_string(),
1526+
fail_fast_on_sticky: false,
15121527
process_sticky: false,
15131528
materialization_context: None,
15141529
flags: vec!["flags/tutorial-feature".to_string()],
@@ -1577,7 +1592,9 @@ mod tests {
15771592
evaluation_context: Some(Struct::default()),
15781593
client_secret: SECRET.to_string(),
15791594
flags: vec!["flags/fallthrough-test-1".to_string()],
1595+
fail_fast_on_sticky: false,
15801596
process_sticky: false,
1597+
15811598
materialization_context: None,
15821599
apply: false,
15831600
sdk: Some(Sdk {
@@ -1635,7 +1652,9 @@ mod tests {
16351652
evaluation_context: Some(Struct::default()),
16361653
client_secret: SECRET.to_string(),
16371654
flags: vec!["flags/fallthrough-test-2".to_string()],
1655+
fail_fast_on_sticky: false,
16381656
process_sticky: false,
1657+
16391658
materialization_context: None,
16401659
apply: false,
16411660
sdk: Some(Sdk {
@@ -1707,7 +1726,9 @@ mod tests {
17071726
evaluation_context: Some(Struct::default()),
17081727
client_secret: SECRET.to_string(),
17091728
flags: vec!["flags/tutorial-feature".to_string()],
1729+
fail_fast_on_sticky: false,
17101730
process_sticky: false,
1731+
17111732
materialization_context: None,
17121733
apply: false,
17131734
sdk: Some(Sdk {
@@ -1803,7 +1824,9 @@ mod tests {
18031824
evaluation_context: Some(Struct::default()),
18041825
client_secret: SECRET.to_string(),
18051826
flags: vec!["flags/tutorial-feature".to_string()],
1827+
fail_fast_on_sticky: false,
18061828
process_sticky: false,
1829+
18071830
materialization_context: None,
18081831
apply: true,
18091832
sdk: Some(Sdk {
@@ -1838,7 +1861,9 @@ mod tests {
18381861
evaluation_context: Some(Struct::default()),
18391862
client_secret: SECRET.to_string(),
18401863
flags: vec!["flags/tutorial-feature".to_string()],
1864+
fail_fast_on_sticky: false,
18411865
process_sticky: false,
1866+
18421867
materialization_context: None,
18431868
apply: true,
18441869
sdk: Some(Sdk {

wasm/proto/resolver/api.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ message ResolveFlagsRequest {
4040

4141
// if the resolver should handle sticky assignments
4242
bool process_sticky = 6;
43-
4443
// Context about the materialization required for the resolve
4544
MaterializationContext materialization_context = 7;
45+
46+
// if a materialization info is missing, we want tor return to the caller immediately
47+
bool fail_fast_on_sticky = 8;
4648
}
4749

4850

0 commit comments

Comments
 (0)