:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(flags): treat geoip subdivisions as instantly available (#117127)
Phil Haacke7892292bde2
diff --git a/docs/internal/feature-flags/rust-service-overview.md b/docs/internal/feature-flags/rust-service-overview.mdindex 194996479294..c79b78561829 100644--- a/docs/internal/feature-flags/rust-service-overview.md+++ b/docs/internal/feature-flags/rust-service-overview.md@@ -176,7 +176,7 @@ pub struct FlagRequest {Unless `geoip_disable: true` is set in the body, `handler::properties::get_person_property_overrides` looks up the request IP in MaxMind and merges the resulting `$geoip_*` properties into `person_properties` before evaluation.-The lookup also fills `$geoip_subdivision_1_code`, `$geoip_subdivision_1_name`, `$geoip_subdivision_2_code` and `$geoip_subdivision_2_name`. A team listed in `GEOIP_SUBDIVISIONS_EXCLUDED_TEAM_IDS` gets no subdivision values from the lookup.+The lookup also fills `$geoip_subdivision_1_code`, `$geoip_subdivision_1_name`, `$geoip_subdivision_2_code` and `$geoip_subdivision_2_name`.GeoIP only fills gaps. A `$geoip_*` key present in the request body is left alone, and a JSON null counts as absent, since callers clear a property with `$unset`, so a null is a gap to fill.This matters for server-side evaluation: the IP we geolocate is whoever made the HTTP request, so a call from a backend or an SSR render resolves the server's own location, not the end user's.@@ -335,12 +335,11 @@ See [Behavioral cohorts](#behavioral-cohorts) for cohort membership cache settin### Other-| Variable | Default | Purpose |-| ---------------------------------------- | -------------------------- | ------------------------------------------------------------------ |-| `MAXMIND_DB_PATH` | `share/GeoLite2-City.mmdb` | GeoIP database path |-| `GEOIP_SUBDIVISIONS_EXCLUDED_TEAM_IDS` | `none` | Teams that get no `$geoip_subdivision_*` values from the IP lookup |-| `OPTIMIZE_EXPERIENCE_CONTINUITY_LOOKUPS` | `true` | Skip DB lookups for 100%-rollout flags |-| `FLAGS_SESSION_REPLAY_QUOTA_CHECK` | `false` | Check session replay quota |+| Variable | Default | Purpose |+| ---------------------------------------- | -------------------------- | -------------------------------------- |+| `MAXMIND_DB_PATH` | `share/GeoLite2-City.mmdb` | GeoIP database path |+| `OPTIMIZE_EXPERIENCE_CONTINUITY_LOOKUPS` | `true` | Skip DB lookups for 100%-rollout flags |+| `FLAGS_SESSION_REPLAY_QUOTA_CHECK` | `false` | Check session replay quota |## Cache invalidationdiff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 9e76c4a43abf..1a1db051aeab 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -138,6 +138,10 @@ export const INSTANTLY_AVAILABLE_PROPERTIES = ['$geoip_continent_code','$geoip_postal_code','$geoip_time_zone',+ '$geoip_subdivision_1_code',+ '$geoip_subdivision_1_name',+ '$geoip_subdivision_2_code',+ '$geoip_subdivision_2_name',// Person and group identifiers'$group_key','distinct_id',diff --git a/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.tsindex bb60b1a4bfad..d42d0d81bcf1 100644--- a/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts@@ -482,6 +482,18 @@ describe('featureFlagIntentWarningLogic', () => {],expectedIssueCount: 0,},+ {+ name: 'geoip subdivision property does not trigger issue',+ properties: [+ {+ key: '$geoip_subdivision_1_code',+ type: PropertyFilterType.Person,+ operator: PropertyOperator.Exact,+ value: 'CA',+ },+ ],+ expectedIssueCount: 0,+ },])('$name', async ({ properties, expectedIssueCount }) => {enableIntentsFeatureFlag()diff --git a/rust/feature-flags/src/config.rs b/rust/feature-flags/src/config.rsindex 6b366b95fdea..333071adfd88 100644--- a/rust/feature-flags/src/config.rs+++ b/rust/feature-flags/src/config.rs@@ -628,12 +628,6 @@ pub struct Config {#[envconfig(from = "MAXMIND_DB_PATH", default = "")]pub maxmind_db_path: String,- // A server-side SDK that doesn't forward the end user's IP resolves its own server's- // region, and that value replaces the stored person property that a region flag would- // otherwise match on.- #[envconfig(from = "GEOIP_SUBDIVISIONS_EXCLUDED_TEAM_IDS", default = "none")]- pub geoip_subdivisions_excluded_team_ids: TeamIdCollection,-#[envconfig(default = "false")]pub enable_metrics: bool,@@ -1195,7 +1189,6 @@ impl Config {billing_limiter_cache_ttl_secs: 5,otel_export_timeout_secs: 3,maxmind_db_path: "".to_string(),- geoip_subdivisions_excluded_team_ids: TeamIdCollection::None,enable_metrics: false,team_ids_to_track: TeamIdCollection::All,cohort_cache_capacity_bytes: 268_435_456, // 256 MB@@ -1288,12 +1281,6 @@ impl Config {}}- pub fn geoip_subdivisions_enabled_for(&self, team_id: i32) -> bool {- !self- .geoip_subdivisions_excluded_team_ids- .includes_team(team_id)- }-pub fn get_redis_reader_url(&self) -> &str {if self.redis_reader_url.is_empty() {&self.redis_url@@ -1440,7 +1427,6 @@ mod tests {// every legacy token without a mirror row while CI stays green, because the// integration tests build their config from default_test_config() instead.assert_eq!(config.accept_team_secret_tokens, FlexBool(true));- assert!(config.geoip_subdivisions_enabled_for(1));}#[test]diff --git a/rust/feature-flags/src/handler/mod.rs b/rust/feature-flags/src/handler/mod.rsindex 4123a7de849b..6ff4be534ae5 100644--- a/rust/feature-flags/src/handler/mod.rs+++ b/rust/feature-flags/src/handler/mod.rs@@ -253,8 +253,7 @@ async fn process_request_inner(tracing::debug!("Flags filtered: {} flags found", filtered_flags.flags.len());- let property_overrides =- properties::prepare_overrides(&context, &request, team.id)?;+ let property_overrides = properties::prepare_overrides(&context, &request)?;// Evaluate flags (this will return empty if is_flags_disabled is true)let response = {diff --git a/rust/feature-flags/src/handler/properties.rs b/rust/feature-flags/src/handler/properties.rsindex 683796abc86f..d74252ea8d89 100644--- a/rust/feature-flags/src/handler/properties.rs+++ b/rust/feature-flags/src/handler/properties.rs@@ -13,18 +13,13 @@ use std::{use super::canonical_log::with_canonical_log;use super::types::{RequestContext, RequestPropertyOverrides};-const GEOIP_SUBDIVISION_PREFIX: &str = "$geoip_subdivision_";-pub fn prepare_overrides(context: &RequestContext,request: &FlagRequest,- team_id: i32,) -> Result<RequestPropertyOverrides, FlagError> {let geoip_disabled = request.geoip_disable.unwrap_or(false);- let include_subdivisions = context.state.config.geoip_subdivisions_enabled_for(team_id);let person_property_overrides = get_person_property_overrides(geoip_disabled,- include_subdivisions,request.person_properties.clone(),&context.ip,&context.state.geoip,@@ -71,7 +66,6 @@ fn record_geoip_divergence(/// is the authority for those keys.pub fn get_person_property_overrides(geoip_disabled: bool,- include_subdivisions: bool,person_properties: Option<HashMap<String, Value>>,ip: &IpAddr,geoip_service: &GeoIpClient,@@ -80,12 +74,9 @@ pub fn get_person_property_overrides(return person_properties;}- let mut geoip_props = geoip_service+ let geoip_props = geoip_service.get_geoip_properties(&ip.to_string()).unwrap_or_default();- if !include_subdivisions {- geoip_props.retain(|key, _| !key.starts_with(GEOIP_SUBDIVISION_PREFIX));- }if geoip_props.is_empty() {return person_properties;}diff --git a/rust/feature-flags/src/handler/tests.rs b/rust/feature-flags/src/handler/tests.rsindex ecae060d532d..21b903e277e1 100644--- a/rust/feature-flags/src/handler/tests.rs+++ b/rust/feature-flags/src/handler/tests.rs@@ -162,7 +162,6 @@ fn test_geoip_person_property_overrides(let result = properties::get_person_property_overrides(geoip_disabled,- true,person_properties,&ip,&geoip_service,@@ -189,55 +188,6 @@ fn test_geoip_person_property_overrides(}}-#[rstest]-#[case::included(true)]-#[case::excluded(false)]-#[tokio::test]-async fn test_geoip_subdivisions_follow_team_exclusion(#[case] include_subdivisions: bool) {- let geoip_service = create_test_geoip_service();- let ip = IpAddr::V4(Ipv4Addr::new(31, 28, 64, 3));- let lookup = geoip_service- .get_geoip_properties(&ip.to_string())- .unwrap_or_default();- assert!(- lookup.contains_key("$geoip_subdivision_1_code")- && lookup.contains_key("$geoip_subdivision_1_name"),- "the test needs an IP that resolves a subdivision"- );-- let supplied = json!("XX");- let person_properties =- HashMap::from([("$geoip_subdivision_1_code".to_string(), supplied.clone())]);-- let log = FlagsCanonicalLogLine::new(Uuid::new_v4(), ip.to_string());- let (result, final_log) = run_with_canonical_log(log, async {- properties::get_person_property_overrides(- false,- include_subdivisions,- Some(person_properties),- &ip,- &geoip_service,- )- })- .await;- let result = result.expect("expected property overrides");-- assert_eq!(result.get("$geoip_subdivision_1_code"), Some(&supplied));- // An excluded team's lookup value is dropped before the comparison, so it cannot diverge.- assert_eq!(- final_log.geoip_properties_differ_from_lookup,- include_subdivisions- );- for (key, value) in lookup- .iter()- .filter(|(key, _)| *key != "$geoip_subdivision_1_code")- {- let expected = (include_subdivisions || !key.starts_with("$geoip_subdivision_"))- .then(|| Value::String(value.clone()));- assert_eq!(result.get(key), expected.as_ref(), "{key}");- }-}-#[test]// A supplied null survives only when the IP resolves nothing: the fill loop at// properties.rs only visits keys MaxMind returns. That leftover null reads as@@ -256,7 +206,6 @@ fn test_supplied_geoip_null_survives_unresolvable_ip() {let result = properties::get_person_property_overrides(false,- true,Some(person_properties),&ip,&geoip_service,@@ -309,7 +258,6 @@ async fn test_canonical_log_records_geoip_divergence(let (result, final_log) = run_with_canonical_log(log, async {properties::get_person_property_overrides(geoip_disabled,- true,person_properties,&ip,&geoip_service,@@ -570,7 +518,6 @@ fn test_get_person_property_overrides_ipv4() {let geoip_service = create_test_geoip_service();let result = properties::get_person_property_overrides(false,- true,Some(HashMap::new()),&IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),&geoip_service,@@ -585,7 +532,6 @@ fn test_get_person_property_overrides_ipv6() {let geoip_service = create_test_geoip_service();let result = properties::get_person_property_overrides(false,- true,Some(HashMap::new()),&IpAddr::V6(Ipv6Addr::new(0x2001, 0x4860, 0x4860, 0, 0, 0, 0, 0x8888)),&geoip_service,