Skip to content

Commit fff4fd3

Browse files
authored
feat(ffe): support serial id (#1951)
# What does this PR do? Support serial id propagation from UFC to assignment. Ported from our internal repo. Co-authored-by: oleksii.shmalko <oleksii.shmalko@datadoghq.com>
1 parent 4ae8ebe commit fff4fd3

7 files changed

Lines changed: 33 additions & 1 deletion

File tree

datadog-ffe-ffi/cbindgen.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ renaming_overrides_prefixing = true
2323
[export.rename]
2424
"Error" = "ddog_Error"
2525
"Vec_U8" = "ddog_Vec_U8"
26+
"Option_I32" = "ddog_Option_I32"
2627
"ArrayMap_BorrowedStr__BorrowedStr" = "ddog_ffe_ArrayMap_BorrowedStr"
2728
"KeyValue_BorrowedStr__BorrowedStr" = "ddog_ffe_KeyValue_BorrowedStr"
2829

datadog-ffe-ffi/src/assignment.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,23 @@ pub unsafe extern "C" fn ddog_ffe_assignment_get_error_message(
432432
}
433433
}
434434

435+
/// Get the serial_id produced by evaluation.
436+
///
437+
/// Returns `None` if the assignment has no serial_id or evaluation did not produce any value.
438+
///
439+
/// # Safety
440+
/// `assignment` must be a valid handle.
441+
#[no_mangle]
442+
pub unsafe extern "C" fn ddog_ffe_assignment_get_serial_id(
443+
assignment: Handle<ResolutionDetails>,
444+
) -> libdd_common_ffi::Option<i32> {
445+
// SAFETY: the caller must ensure that assignment handle is valid.
446+
match unsafe { assignment.as_ref() }.as_ref() {
447+
Ok(a) => a.serial_id.into(),
448+
Err(_) => libdd_common_ffi::Option::None,
449+
}
450+
}
451+
435452
/// # Safety
436453
/// `assignment` must be a valid handle.
437454
#[no_mangle]

datadog-ffe/src/rules_based/eval/eval_assignment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl Flag {
105105
variation_key: split.variation_key.clone(),
106106
allocation_key: allocation.key.clone(),
107107
reason,
108+
serial_id: split.serial_id,
108109
do_log: allocation.do_log,
109110
})
110111
}

datadog-ffe/src/rules_based/ufc/assignment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub struct Assignment {
3030
pub allocation_key: Str,
3131
/// The reason for this assignment.
3232
pub reason: AssignmentReason,
33-
33+
/// Serial id for the selected split.
34+
pub serial_id: Option<i32>,
3435
/// Whether this assignment is part of an experiment and should be logged.
3536
pub do_log: bool,
3637
}

datadog-ffe/src/rules_based/ufc/compiled_flag_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub(crate) struct Split {
5353
pub shards: Vec<Shard>,
5454
pub variation_key: Str,
5555
pub value: AssignmentValue,
56+
pub serial_id: Option<i32>,
5657
}
5758

5859
#[derive(Debug, Clone)]
@@ -168,6 +169,7 @@ fn compile_split(
168169
shards,
169170
variation_key: split.variation_key,
170171
value: result,
172+
serial_id: split.serial_id,
171173
})
172174
}
173175

datadog-ffe/src/rules_based/ufc/models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ impl From<Vec<String>> for ConditionValue {
528528
pub(crate) struct SplitWire {
529529
pub shards: Vec<ShardWire>,
530530
pub variation_key: Str,
531+
#[serde(default)]
532+
pub serial_id: Option<i32>,
531533
}
532534

533535
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

examples/ffi/ffe.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ void evaluate_and_print_flag(
154154
bool do_log = ddog_ffe_assignment_get_do_log(assignment);
155155
printf(" Do Log: %s\n", do_log ? "true" : "false");
156156

157+
// Get and print serial_id
158+
struct ddog_Option_I32 serial_id = ddog_ffe_assignment_get_serial_id(assignment);
159+
if (serial_id.tag == DDOG_OPTION_I32_SOME_I32) {
160+
printf(" Serial ID: %d\n", serial_id.some);
161+
} else {
162+
printf(" Serial ID: (none)\n");
163+
}
164+
157165
// Get and print flag metadata
158166
struct ddog_ffe_ArrayMap_BorrowedStr metadata = ddog_ffe_assignnment_get_flag_metadata(assignment);
159167
if (metadata.count > 0) {

0 commit comments

Comments
 (0)