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: Identity overrides in local evaluation mode #20

Merged
merged 4 commits into from
Apr 4, 2024

Conversation

khvn26
Copy link
Member

@khvn26 khvn26 commented Apr 3, 2024

Closes #17.
Contributes to Flagsmith/flagsmith#3132.

Changes:

  • Factor out update_environment to share code between the Flagsmith.update_environment interface and the threaded routine
  • Implement identity overrides in local evaluation mode

flagsmith-flag-engine dependency spec will be changed after Flagsmith/flagsmith-rust-flag-engine#12 is merged and released.

@khvn26 khvn26 requested review from a team and zachaysan and removed request for a team April 3, 2024 21:58
@khvn26 khvn26 force-pushed the feat/local-eval-identities branch 4 times, most recently from f04ee89 to c2ab95c Compare April 4, 2024 02:37
environment_url.clone(),
)?);
for identity in &environment.as_ref().unwrap().identity_overrides {
data.identities_with_overrides_by_identifier.insert(identity.identifier.clone(), identity.clone());
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll happily accept pointers on how to stop copying around the identity structs. This shouldn't be a problem for most environments, but we need to be aware there's room for optimisation here.

Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

Added a couple of minor comments but they're likely mostly down to my limited knowledge of the Rust language.

);
let mut data = ds.lock().unwrap();
data.environment = environment;
update_environment(&client, &ds, &environment_url).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Interested to know why we use client.clone() above but directly point to the client here.

I suspect it's because we want to update the environment on the instance of the client itself, but just double checking.

Copy link
Member Author

@khvn26 khvn26 Apr 4, 2024

Choose a reason for hiding this comment

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

I'm not sure if cloning inside a loop is a good idea.

We're keeping the initial client instance for the background task, and cloning it once for the SDK client's blocking calls.

src/flagsmith/mod.rs Show resolved Hide resolved
Copy link

@zachaysan zachaysan left a comment

Choose a reason for hiding this comment

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

I don't see obvious show stoppers, but I have a few small questions. I'm going to leave the final approval up to @matthewelwell since my experience with Rust is quite limited.

src/flagsmith/mod.rs Show resolved Hide resolved
Comment on lines +408 to +409
"api_key": "B62qaMZNwfiqT76p38ggrQ",
"project": {

Choose a reason for hiding this comment

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

Feels kinda icky to have ENVIRONMENT_JSON in this rust file. Can we not load it from a json file?

Copy link
Member Author

Choose a reason for hiding this comment

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


// When
let mut _flagsmith = Flagsmith::new(environment_key.to_string(), flagsmith_options);
thread::sleep(std::time::Duration::from_millis(250));

Choose a reason for hiding this comment

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

Is this sleep necessary to allow the local evaluation document to be ready and loaded? In other words, if we don't sleep do we have an empty document? If so, we should rework the blocking logic and block on boot for the first local evaluation like we currently do in the Python client.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, fixed this!

@khvn26 khvn26 force-pushed the feat/local-eval-identities branch from 946e4e0 to 1f338a2 Compare April 4, 2024 17:24
src/flagsmith/mod.rs Show resolved Hide resolved
@khvn26 khvn26 merged commit 06150ff into main Apr 4, 2024
1 check passed
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.

Identity overrides in local evaluation mode
3 participants