Skip to content

Commit

Permalink
feat(flags): add group property overrides (#24589)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarticus authored Sep 13, 2024
1 parent de3d95a commit 7172752
Show file tree
Hide file tree
Showing 12 changed files with 1,943 additions and 344 deletions.
19 changes: 8 additions & 11 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rust/feature-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ regex = "1.10.4"
maxminddb = "0.17"
sqlx = { workspace = true }
uuid = { workspace = true }
base64.workspace = true
flate2.workspace = true
common-alloc = { path = "../common/alloc" }

[lints]
Expand All @@ -39,4 +41,4 @@ workspace = true
[dev-dependencies]
assert-json-diff = { workspace = true }
reqwest = { workspace = true }

futures = "0.3.30"
9 changes: 9 additions & 0 deletions rust/feature-flags/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub enum FlagError {
DatabaseUnavailable,
#[error("Timed out while fetching data")]
TimeoutError,
#[error("No group type mappings")]
NoGroupTypeMappings,
}

impl IntoResponse for FlagError {
Expand Down Expand Up @@ -167,6 +169,13 @@ impl IntoResponse for FlagError {
"The request timed out. This could be due to high load or network issues. Please try again later.".to_string(),
)
}
FlagError::NoGroupTypeMappings => {
tracing::error!("No group type mappings: {:?}", self);
(
StatusCode::INTERNAL_SERVER_ERROR,
"No group type mappings found. This is likely a configuration issue. Please contact support.".to_string(),
)
}
}
.into_response()
}
Expand Down
11 changes: 3 additions & 8 deletions rust/feature-flags/src/flag_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ use tracing::instrument;
// TODO: Add integration tests across repos to ensure this doesn't happen.
pub const TEAM_FLAGS_CACHE_PREFIX: &str = "posthog:1:team_feature_flags_";

// TODO: Hmm, revisit when dealing with groups, but seems like
// ideal to just treat it as a u8 and do our own validation on top
#[derive(Debug, Deserialize)]
pub enum GroupTypeIndex {}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum OperatorType {
Expand Down Expand Up @@ -42,7 +37,7 @@ pub struct PropertyFilter {
pub operator: Option<OperatorType>,
#[serde(rename = "type")]
pub prop_type: String,
pub group_type_index: Option<i8>,
pub group_type_index: Option<i32>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand All @@ -68,7 +63,7 @@ pub struct MultivariateFlagOptions {
pub struct FlagFilters {
pub groups: Vec<FlagGroupType>,
pub multivariate: Option<MultivariateFlagOptions>,
pub aggregation_group_type_index: Option<i8>,
pub aggregation_group_type_index: Option<i32>,
pub payloads: Option<serde_json::Value>,
pub super_groups: Option<Vec<FlagGroupType>>,
}
Expand Down Expand Up @@ -101,7 +96,7 @@ pub struct FeatureFlagRow {
}

impl FeatureFlag {
pub fn get_group_type_index(&self) -> Option<i8> {
pub fn get_group_type_index(&self) -> Option<i32> {
self.filters.aggregation_group_type_index
}

Expand Down
Loading

0 comments on commit 7172752

Please sign in to comment.