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(flags): support groups and payloads correctly in new /flags service #26817

Merged
merged 31 commits into from
Dec 11, 2024

Conversation

dmarticus
Copy link
Contributor

@dmarticus dmarticus commented Dec 10, 2024

Problem

When I was locally testing the new /flags service, I realized I'd missed 2 things:

  1. I wasn't correctly accounting for group membership in the request payload as part of evaluating group flags
  2. I totally forgot to return the flag payloads

This PR makes those changes, as well as a few other cleanups around the codebase.

@@ -46,7 +46,6 @@ pub async fn flags(
let context = RequestContext {
state,
ip,
meta: meta.0,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I never use this value in the request logic, so I can omit it.

@@ -58,7 +58,6 @@ pub struct FlagsQueryParams {
pub struct RequestContext {
pub state: State<router::State>,
pub ip: IpAddr,
pub meta: FlagsQueryParams,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above comment.

/// ## Error Handling
/// - Returns early if any step fails
/// - Maintains error context through the FlagError enum
/// - Individual flag evaluation failures don't fail the entire request
pub async fn process_request(context: RequestContext) -> Result<FlagsResponse, FlagError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this needed a comment since it's an entrypoint method

pub async fn process_request(context: RequestContext) -> Result<FlagsResponse, FlagError> {
let RequestContext {
state,
ip,
meta: _, // TODO use this
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol I don't actually use this anywhere outside of recording request metadata, so bye bye meta!

.cloned()
.unwrap_or_default();

properties.insert("$group_key".to_string(), group_key);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -738,4 +787,61 @@ mod tests {
assert!(!result.error_while_computing_flags);
assert_eq!(result.feature_flags["test_flag"], FlagValue::Boolean(true));
}

#[test]
fn test_process_group_property_overrides() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wanted to make sure I'm correctly overriding the group values with any passed in property overrides.

Comment on lines +569 to +573
feature_flags_map.insert(flag.key.clone(), flag_value);

if let Some(payload) = flag_match.payload {
feature_flag_payloads_map.insert(flag.key.clone(), payload);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

insert the payloads to the response.


let groups = request.groups.clone();
let group_property_overrides =
process_group_property_overrides(groups.clone(), request.group_properties.clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note, this means every time we have a flags request with groups, there will be a group_property_override that looks like (e.g.)

 Some({"project": {"$group_key": String("test_company_id")}})

@dmarticus dmarticus requested review from a team and oliverb123 December 10, 2024 22:49
Copy link
Contributor

@havenbarnes havenbarnes left a comment

Choose a reason for hiding this comment

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

LGTM!

@dmarticus dmarticus enabled auto-merge (squash) December 10, 2024 23:27
@dmarticus dmarticus disabled auto-merge December 11, 2024 00:48
@dmarticus dmarticus enabled auto-merge (squash) December 11, 2024 00:48
@dmarticus dmarticus merged commit be16a0d into master Dec 11, 2024
80 checks passed
@dmarticus dmarticus deleted the feat/support-groups-and-payloads branch December 11, 2024 16:39
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.

2 participants