Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter support in experimentation client #35

Merged
merged 1 commit into from May 17, 2024

Conversation

mahatoankitkumar
Copy link
Collaborator

Problem

Filter prefix from experiments.

Solution

Added Filter prefix support in experimentation client.

@mahatoankitkumar mahatoankitkumar requested a review from a team as a code owner May 7, 2024 10:31
pub async fn get_satisfied_experiments(
&self,
context: &Value,
) -> Result<Experiments, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use App error here

&self,
context: &Value,
toss: i8,
) -> Result<Vec<String>, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use App error here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't use AppError here, this will be integrated in other codebases that may or may not understand the struct AppError

@@ -24,15 +30,16 @@ pub struct Client {
// DO NOT let panics show up in library

impl Client {
pub fn new(config: Config) -> Self {
Client {
pub fn new(config: Config) -> Result<Self, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use app error here also

mod utils;
use std::{
collections::{HashMap, HashSet},
convert::identity,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not getting used can you remove this

.collect::<Experiments>()
.collect::<Experiments>();

if let Some(prefix) = context.get("prefix") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use different param for prefix, since its not related to the context instead with the filter,
we also might need to change this in cac_client

format!("Prefix is not a valid string.")
})
.map_err_to_string()?
.split(",")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we expect prefix as array of strings instead of comma separated string(since this is not query params of any api),

crates/experimentation_client/src/lib.rs Show resolved Hide resolved
@@ -24,15 +30,16 @@ pub struct Client {
// DO NOT let panics show up in library

impl Client {
pub fn new(config: Config) -> Self {
Client {
pub fn new(config: Config) -> Result<Self, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for this? Will we ever get an error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to maintain consistency everywhere. Maybe in future.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not do it then? Lets add it when the error comes

&self,
context: &Value,
toss: i8,
) -> Result<Vec<String>, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't use AppError here, this will be integrated in other codebases that may or may not understand the struct AppError

crates/experimentation_client/src/interface.rs Outdated Show resolved Hide resolved
@Datron Datron self-requested a review May 9, 2024 07:47
@mahatoankitkumar mahatoankitkumar force-pushed the feat/filter-support-in-exp-client branch 2 times, most recently from ccd0976 to 71a5b45 Compare May 13, 2024 06:39
@mahatoankitkumar mahatoankitkumar force-pushed the feat/filter-support-in-exp-client branch from 71a5b45 to 77ad805 Compare May 13, 2024 08:26
Copy link
Collaborator

@Datron Datron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some questions

@mahatoankitkumar mahatoankitkumar force-pushed the feat/filter-support-in-exp-client branch 2 times, most recently from 9605a32 to 21348a3 Compare May 13, 2024 10:06
@@ -187,9 +187,11 @@ pub extern "C" fn get_applicable_variant(
let variants = local.block_on(&Runtime::new().unwrap(), unsafe {
Copy link
Collaborator

@sauraww sauraww May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this print statement ?
// println!("Fetching variantIds");

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already removed, you seeing the code on the opposite(removed) side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not removed .
This was the comment that was removed :
// println!("variantIds: {:?}", variants);

match serde_json::to_string::<Vec<String>>(&variants) {
Ok(result) => rstring_to_cstring(result).into_raw(),
match variants {
Ok(result) => match serde_json::to_string::<Vec<String>>(&result) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variants_result
    .map(|result| {
        serde_json::to_string(&result)
            .map(|json| rstring_to_cstring(json).into_raw())
            .unwrap_or_else(|err| error_block(err.to_string()))
    })
    .unwrap_or_else(|err| error_block(err.to_string()))

let experiments = match serde_json::to_value(experiments) {
Ok(value) => value,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let experiments = serde_json::to_value(experiments)
    .unwrap_or_else(|err| return error_block(err.to_string()));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this change at all the places ?
Ideally match statements should be used only for the cases where we have more than 2 conditions to match .
For these cases , we can directly leverage map .

@mahatoankitkumar mahatoankitkumar force-pushed the feat/filter-support-in-exp-client branch from 21348a3 to 8003f3a Compare May 15, 2024 14:37
@mahatoankitkumar mahatoankitkumar linked an issue May 16, 2024 that may be closed by this pull request
@@ -0,0 +1 @@
pub mod core;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just put the code of core.rs into this file

@mahatoankitkumar mahatoankitkumar force-pushed the feat/filter-support-in-exp-client branch from 8003f3a to 2c307ec Compare May 17, 2024 06:51
@mahatoankitkumar mahatoankitkumar merged commit 0c9d070 into main May 17, 2024
4 checks passed
@mahatoankitkumar mahatoankitkumar deleted the feat/filter-support-in-exp-client branch May 17, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add prefix filter to experimentation client
4 participants