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

fix(flags): fixing the last* bug with new flags #28359

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

dmarticus
Copy link
Contributor

*last bug so far....

But for real this is the last one: I was running my tests a final time and realized the last discrepancy between ``/decideand/flags` was this one flag that I'd generated and I couldn't figure out why `/flags` was returning a different variant than `/decide`. I thought for sure I'd screwed up something with my hash calculation and painstakingly debugged the whole thing, and when I couldn't find any variance in that, I finally had the bright idea to take a closer look at the flag being evaluated. Here it is

image

Did you catch that little bit underneath the condition set that said "All users in this set will be in control"? Because I didn't the first time.

Anyway, turns out that I'd never actually implement variant overrides with new flags, so that was the reason I saw a different variant in my tests. Phew.

Fixed this, and everything is coming up Milhouse. Frickin stoked.

Comment on lines +777 to +795
// Check for variant override in the condition
let variant = if let Some(variant_override) = &condition.variant {
// Check if the override is a valid variant
if flag
.get_variants()
.iter()
.any(|v| &v.key == variant_override)
{
Some(variant_override.clone())
} else {
// If override isn't valid, fall back to computed variant
self.get_matching_variant(flag, hash_key_overrides.clone())
.await?
}
} else {
// No override, use computed variant
self.get_matching_variant(flag, hash_key_overrides.clone())
.await?
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here's the relevant bit of Python that does what I'm doing here

@@ -40,16 +40,11 @@ impl FlagRequest {
/// Only supports base64 encoded payloads or uncompressed utf-8 as json.
#[instrument(skip_all)]
pub fn from_bytes(bytes: Bytes) -> Result<FlagRequest, FlagError> {
tracing::debug!(len = bytes.len(), "decoding new request");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these logs were from back in the day when I was debugging request traffic

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR fixes a critical bug in the feature flag variant override functionality, focusing on aligning behavior between /decide and /flags endpoints.

  • Added variant override validation in flag_matching.rs to ensure specified variants exist before applying them
  • Fixed condition-level variant override handling in flag_matching.rs to properly respect "All users in this set will be in control" settings
  • Removed unnecessary debug logging in flag_request.rs for cleaner error output
  • Added test coverage for variant override scenarios in flag_matching.rs to prevent regressions

2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 43 to 46
let payload = String::from_utf8(bytes.to_vec()).map_err(|e| {
tracing::error!("failed to decode body: {}", e);
FlagError::RequestDecodingError(String::from("invalid body encoding"))
})?;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider using debug! instead of error! for decoding failures since they may be common with malformed requests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, fair enough

Comment on lines +779 to +786
// Check if the override is a valid variant
if flag
.get_variants()
.iter()
.any(|v| &v.key == variant_override)
{
Some(variant_override.clone())
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding early validation of variant overrides when flags are created to prevent invalid overrides at runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, good nit, but I'm not doing to do this yet.

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.

Nice catch!

@dmarticus dmarticus merged commit 5267bec into master Feb 6, 2025
84 checks passed
@dmarticus dmarticus deleted the feat/proxy-decide-requests-to-flags branch February 6, 2025 00:26
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