posthog-ruby 3.38.0 → 3.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/posthog/feature_flags.rb +221 -64
- data/lib/posthog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3d310b8c92f6b3933968050b20012090e3c1ac220346762dc9cf051ab9d82bd8
|
|
4
|
+
data.tar.gz: 50fca2bf0450dd266a6a6f516bbfef5297b4bac6e7228b2e26faf6a6771d49bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb6b5d4ce868ae8eb338ce627d7b41c46c121b1cd4b0a41a6367c2b80aa727a085cbb9a5a99bfd2cd3f6c666ccd94c902c12d8a580b0827fbf9d13ab6a67bd44
|
|
7
|
+
data.tar.gz: 65978c26cfcf66fa940e13693f8f3a2ecc6831a4f1d0be44a2724e9a4dfccab20b1384a267f7f7c5f49550ecac0a4c6396605cf699a144c47afdde80d9bfdad9
|
|
@@ -29,6 +29,13 @@ module PostHog
|
|
|
29
29
|
UnresolvedFlagReason::UNRESOLVED_DEPENDENCY,
|
|
30
30
|
UnresolvedFlagReason::MISSING_CONTEXT
|
|
31
31
|
].freeze
|
|
32
|
+
# Same bound as the other server SDKs.
|
|
33
|
+
MAX_FLAG_DEPENDENCY_DEPTH = 100
|
|
34
|
+
# Path-dependent results are not cached, so a cycle or an over-deep chain could repeat work. Past this many
|
|
35
|
+
# dependency evaluations in one flag evaluation, the remaining dependencies are inconclusive.
|
|
36
|
+
MAX_FLAG_DEPENDENCY_EVALUATIONS = 10_000
|
|
37
|
+
# Cached for a dependency that requires the server, so a later lookup requires it too without re-evaluating.
|
|
38
|
+
DEPENDENCY_REQUIRES_SERVER = Object.new.freeze
|
|
32
39
|
|
|
33
40
|
# Operator groups that share one branch in both match_property_value and assert_filter_supported,
|
|
34
41
|
# so the load-time check stays in step with evaluation.
|
|
@@ -1234,16 +1241,19 @@ module PostHog
|
|
|
1234
1241
|
group_type == 'AND'
|
|
1235
1242
|
end
|
|
1236
1243
|
|
|
1237
|
-
# Evaluates a flag dependency property
|
|
1244
|
+
# Evaluates a flag dependency property. The dependency_chain is only checked for missing definitions, not
|
|
1245
|
+
# walked: only the flag named by property[:key] is evaluated, and its value is compared with property[:value].
|
|
1238
1246
|
#
|
|
1239
1247
|
# @param property [Hash] Flag property with type="flag" and dependency_chain
|
|
1240
1248
|
# @param evaluation_cache [Hash] Cache for storing evaluation results
|
|
1241
1249
|
# @param distinct_id [String] The distinct ID being evaluated
|
|
1242
1250
|
# @param properties [Hash] Person properties for evaluation
|
|
1243
1251
|
# @param cohort_properties [Hash] Cohort properties for evaluation
|
|
1244
|
-
# @return [Boolean] True if
|
|
1252
|
+
# @return [Boolean] True if the referenced flag's value matches property[:value], false otherwise
|
|
1245
1253
|
def evaluate_flag_dependency(property, evaluation_cache, distinct_id, properties, cohort_properties,
|
|
1246
|
-
snapshot: _evaluation_snapshot
|
|
1254
|
+
person_properties: properties, snapshot: _evaluation_snapshot,
|
|
1255
|
+
dependency_evaluation: nil)
|
|
1256
|
+
dependency_evaluation ||= DependencyEvaluation.new
|
|
1247
1257
|
if snapshot[:flags_by_key].nil? || evaluation_cache.nil?
|
|
1248
1258
|
# Cannot evaluate flag dependencies without required context
|
|
1249
1259
|
raise InconclusiveMatchError.new(
|
|
@@ -1260,66 +1270,173 @@ module PostHog
|
|
|
1260
1270
|
raise InconclusiveMatchError.new(definition_error, reason: UnresolvedFlagReason::UNSUPPORTED_DEFINITION)
|
|
1261
1271
|
end
|
|
1262
1272
|
|
|
1263
|
-
|
|
1273
|
+
# Like the flags service, only the referenced flag is evaluated, with full flag evaluation. Its own
|
|
1274
|
+
# conditions evaluate the flags they depend on, so a flag it skips, such as the release conditions of an
|
|
1275
|
+
# enrollment flag, never decides the comparison.
|
|
1276
|
+
dep_flag_key = property[:key]
|
|
1277
|
+
actual_value = if evaluation_cache.key?(dep_flag_key)
|
|
1278
|
+
cached_flag_dependency_value(dep_flag_key, evaluation_cache)
|
|
1279
|
+
else
|
|
1280
|
+
evaluate_flag_dependency_value(dep_flag_key, evaluation_cache, distinct_id, properties,
|
|
1281
|
+
cohort_properties, person_properties, snapshot,
|
|
1282
|
+
dependency_evaluation)
|
|
1283
|
+
end
|
|
1264
1284
|
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
unless evaluation_cache.key?(dep_flag_key)
|
|
1268
|
-
# Need to evaluate this dependency first
|
|
1269
|
-
dep_flag = snapshot[:flags_by_key][dep_flag_key]
|
|
1270
|
-
if !dep_flag[:active]
|
|
1271
|
-
# Check if the flag is active (same check as in _compute_flag_locally)
|
|
1272
|
-
evaluation_cache[dep_flag_key] = false
|
|
1273
|
-
elsif dep_flag[:ensure_experience_continuity]
|
|
1274
|
-
evaluation_cache[dep_flag_key] = nil
|
|
1275
|
-
raise InconclusiveMatchError.new(
|
|
1276
|
-
"Cannot evaluate flag dependency '#{dep_flag_key}' - flag has experience continuity enabled",
|
|
1277
|
-
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY
|
|
1278
|
-
)
|
|
1279
|
-
else
|
|
1280
|
-
# Recursively evaluate the dependency using existing instance method
|
|
1281
|
-
begin
|
|
1282
|
-
dep_result = match_feature_flag_properties(
|
|
1283
|
-
dep_flag,
|
|
1284
|
-
distinct_id,
|
|
1285
|
-
properties,
|
|
1286
|
-
evaluation_cache,
|
|
1287
|
-
cohort_properties,
|
|
1288
|
-
snapshot: snapshot
|
|
1289
|
-
)
|
|
1290
|
-
evaluation_cache[dep_flag_key] = dep_result
|
|
1291
|
-
rescue RequiresServerEvaluation => e
|
|
1292
|
-
# The dependent flag needs the server too. Nothing is cached, so a later lookup of this
|
|
1293
|
-
# dependency also requires the server instead of reading it as merely inconclusive.
|
|
1294
|
-
raise RequiresServerEvaluation.new("Cannot evaluate flag dependency '#{dep_flag_key}': #{e.message}",
|
|
1295
|
-
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY)
|
|
1296
|
-
rescue InconclusiveMatchError => e
|
|
1297
|
-
# If we can't evaluate a dependency, store nil and propagate the error
|
|
1298
|
-
evaluation_cache[dep_flag_key] = nil
|
|
1299
|
-
raise InconclusiveMatchError.new("Cannot evaluate flag dependency '#{dep_flag_key}': #{e.message}",
|
|
1300
|
-
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY)
|
|
1301
|
-
end
|
|
1302
|
-
end
|
|
1303
|
-
end
|
|
1285
|
+
self.class.matches_dependency_value(property[:value], actual_value)
|
|
1286
|
+
end
|
|
1304
1287
|
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
raise InconclusiveMatchError.new("Flag dependency '#{dep_flag_key}' was previously inconclusive",
|
|
1288
|
+
def cached_flag_dependency_value(dep_flag_key, evaluation_cache)
|
|
1289
|
+
value = evaluation_cache[dep_flag_key]
|
|
1290
|
+
if value.equal?(DEPENDENCY_REQUIRES_SERVER)
|
|
1291
|
+
raise RequiresServerEvaluation.new("Flag dependency '#{dep_flag_key}' requires server evaluation",
|
|
1310
1292
|
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY)
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1293
|
+
end
|
|
1294
|
+
if value.nil?
|
|
1295
|
+
raise InconclusiveMatchError.new("Flag dependency '#{dep_flag_key}' was previously inconclusive",
|
|
1296
|
+
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY)
|
|
1297
|
+
end
|
|
1298
|
+
|
|
1299
|
+
value
|
|
1300
|
+
end
|
|
1301
|
+
|
|
1302
|
+
def evaluate_flag_dependency_value(dep_flag_key, evaluation_cache, distinct_id, properties, cohort_properties,
|
|
1303
|
+
person_properties, snapshot, dependency_evaluation)
|
|
1304
|
+
dep_flag = snapshot[:flags_by_key][dep_flag_key]
|
|
1305
|
+
# Same check as in _compute_flag_locally.
|
|
1306
|
+
return evaluation_cache[dep_flag_key] = false unless dep_flag[:active]
|
|
1307
|
+
|
|
1308
|
+
if dep_flag[:ensure_experience_continuity]
|
|
1309
|
+
evaluation_cache[dep_flag_key] = nil
|
|
1310
|
+
raise InconclusiveMatchError.new(
|
|
1311
|
+
"Cannot evaluate flag dependency '#{dep_flag_key}' - flag has experience continuity enabled",
|
|
1312
|
+
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY
|
|
1313
|
+
)
|
|
1314
|
+
end
|
|
1315
|
+
|
|
1316
|
+
evaluate_uncached_flag_dependency(dep_flag_key, dep_flag, evaluation_cache, distinct_id, properties,
|
|
1317
|
+
cohort_properties, person_properties, snapshot, dependency_evaluation)
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
# Per-evaluation bookkeeping for flag dependencies, kept apart from the result cache. A cycle depends on the
|
|
1321
|
+
# path to a flag, so the flags on it are not cached. A result computed while the depth limit or budget was hit
|
|
1322
|
+
# below it holds only on paths at least as deep, so it is depth-tagged instead of cached: it is reused only at
|
|
1323
|
+
# the same depth or deeper while the cache has not grown, so each flag is evaluated at most once per depth and
|
|
1324
|
+
# cache size.
|
|
1325
|
+
class DependencyEvaluation
|
|
1326
|
+
attr_reader :in_progress, :depth_tagged
|
|
1327
|
+
attr_accessor :evaluations, :cycles, :depth_limits
|
|
1328
|
+
|
|
1329
|
+
def initialize(flag_key = nil)
|
|
1330
|
+
@path = flag_key.nil? ? [] : [flag_key]
|
|
1331
|
+
@in_progress = Set.new(@path)
|
|
1332
|
+
@cycle_edges = Set.new
|
|
1333
|
+
@depth_tagged = {}
|
|
1334
|
+
@evaluations = 0
|
|
1335
|
+
@cycles = 0
|
|
1336
|
+
@depth_limits = 0
|
|
1337
|
+
end
|
|
1338
|
+
|
|
1339
|
+
# The flag whose conditions are being evaluated, or nil before the first one is entered.
|
|
1340
|
+
def current_flag
|
|
1341
|
+
@path.last
|
|
1342
|
+
end
|
|
1343
|
+
|
|
1344
|
+
def enter(flag_key)
|
|
1345
|
+
@path.push(flag_key)
|
|
1346
|
+
@in_progress.add(flag_key)
|
|
1347
|
+
end
|
|
1348
|
+
|
|
1349
|
+
def exit_flag
|
|
1350
|
+
@in_progress.delete(@path.pop)
|
|
1315
1351
|
end
|
|
1316
1352
|
|
|
1317
|
-
#
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1353
|
+
# Every flag on a cycle has a circular definition, so the flag that closes it reports unsupported_definition.
|
|
1354
|
+
def cycle!(flag_key)
|
|
1355
|
+
@cycles += 1
|
|
1356
|
+
cycle_path = @path.drop(@path.index(flag_key))
|
|
1357
|
+
cycle_path.each_cons(2) { |edge| @cycle_edges.add(edge) }
|
|
1358
|
+
raise InconclusiveMatchError.new("Circular dependency detected for flag '#{flag_key}'",
|
|
1359
|
+
reason: UnresolvedFlagReason::UNSUPPORTED_DEFINITION)
|
|
1360
|
+
end
|
|
1361
|
+
|
|
1362
|
+
def cycle_edge?(parent_key, flag_key)
|
|
1363
|
+
@cycle_edges.include?([parent_key, flag_key])
|
|
1364
|
+
end
|
|
1321
1365
|
|
|
1322
|
-
|
|
1366
|
+
def depth_limit!(message)
|
|
1367
|
+
@depth_limits += 1
|
|
1368
|
+
raise InconclusiveMatchError.new(message, reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY)
|
|
1369
|
+
end
|
|
1370
|
+
end
|
|
1371
|
+
|
|
1372
|
+
def evaluate_uncached_flag_dependency(dep_flag_key, dep_flag, evaluation_cache, distinct_id, properties,
|
|
1373
|
+
cohort_properties, person_properties, snapshot, dependency_evaluation)
|
|
1374
|
+
dependency_evaluation.cycle!(dep_flag_key) if dependency_evaluation.in_progress.include?(dep_flag_key)
|
|
1375
|
+
# The top-level flag is in progress too, so the depth is one less than the number of flags in progress.
|
|
1376
|
+
entry_depth = dependency_evaluation.in_progress.size
|
|
1377
|
+
tagged = dependency_evaluation.depth_tagged[dep_flag_key]
|
|
1378
|
+
if !tagged.nil? && entry_depth >= tagged[:depth] && evaluation_cache.size == tagged[:cache_size]
|
|
1379
|
+
# The reused result is depth-tagged, so the flags that depend on it are too.
|
|
1380
|
+
dependency_evaluation.depth_limits += 1
|
|
1381
|
+
raise tagged[:error] if tagged.key?(:error)
|
|
1382
|
+
|
|
1383
|
+
return tagged[:value]
|
|
1384
|
+
end
|
|
1385
|
+
if dependency_evaluation.evaluations >= MAX_FLAG_DEPENDENCY_EVALUATIONS
|
|
1386
|
+
dependency_evaluation.depth_limit!("Evaluated more than #{MAX_FLAG_DEPENDENCY_EVALUATIONS} flag dependencies")
|
|
1387
|
+
end
|
|
1388
|
+
# Deeper chains are inconclusive, so a long chain can't exhaust the stack.
|
|
1389
|
+
if entry_depth > MAX_FLAG_DEPENDENCY_DEPTH
|
|
1390
|
+
dependency_evaluation.depth_limit!(
|
|
1391
|
+
"Flag dependency chain for '#{dep_flag_key}' is deeper than #{MAX_FLAG_DEPENDENCY_DEPTH}"
|
|
1392
|
+
)
|
|
1393
|
+
end
|
|
1394
|
+
|
|
1395
|
+
dependency_evaluation.evaluations += 1
|
|
1396
|
+
cycles = dependency_evaluation.cycles
|
|
1397
|
+
depth_limits = dependency_evaluation.depth_limits
|
|
1398
|
+
parent_key = dependency_evaluation.current_flag
|
|
1399
|
+
# Whether a result can be cached: not when a cycle or the depth limit or budget was hit below it. A cycle's
|
|
1400
|
+
# result is dropped; a depth-limited one is depth-tagged with the depth and cache size it was computed at.
|
|
1401
|
+
cacheable = lambda do |outcome|
|
|
1402
|
+
next false unless dependency_evaluation.cycles == cycles
|
|
1403
|
+
next true if dependency_evaluation.depth_limits == depth_limits
|
|
1404
|
+
|
|
1405
|
+
dependency_evaluation.depth_tagged[dep_flag_key] = outcome.merge(depth: entry_depth,
|
|
1406
|
+
cache_size: evaluation_cache.size)
|
|
1407
|
+
false
|
|
1408
|
+
end
|
|
1409
|
+
dependency_evaluation.enter(dep_flag_key)
|
|
1410
|
+
begin
|
|
1411
|
+
dep_result = if FeatureFlagsPoller.feature_enrollment?(dep_flag)
|
|
1412
|
+
FeatureFlagsPoller.feature_enrolled?(dep_flag, person_properties || {})
|
|
1413
|
+
else
|
|
1414
|
+
match_feature_flag_properties(
|
|
1415
|
+
dep_flag, distinct_id, properties, evaluation_cache, cohort_properties,
|
|
1416
|
+
person_properties: person_properties, snapshot: snapshot,
|
|
1417
|
+
dependency_evaluation: dependency_evaluation
|
|
1418
|
+
)
|
|
1419
|
+
end
|
|
1420
|
+
rescue RequiresServerEvaluation => e
|
|
1421
|
+
error = RequiresServerEvaluation.new("Cannot evaluate flag dependency '#{dep_flag_key}': #{e.message}",
|
|
1422
|
+
reason: UnresolvedFlagReason::UNRESOLVED_DEPENDENCY)
|
|
1423
|
+
evaluation_cache[dep_flag_key] = DEPENDENCY_REQUIRES_SERVER if cacheable.call(error: error)
|
|
1424
|
+
raise error
|
|
1425
|
+
rescue InconclusiveMatchError => e
|
|
1426
|
+
# A flag whose dependency leads back to it is on the cycle, so it has a circular definition itself.
|
|
1427
|
+
on_cycle = dependency_evaluation.cycles != cycles &&
|
|
1428
|
+
dependency_evaluation.cycle_edge?(parent_key, dep_flag_key)
|
|
1429
|
+
reason = on_cycle ? UnresolvedFlagReason::UNSUPPORTED_DEFINITION : UnresolvedFlagReason::UNRESOLVED_DEPENDENCY
|
|
1430
|
+
error = InconclusiveMatchError.new("Cannot evaluate flag dependency '#{dep_flag_key}': #{e.message}",
|
|
1431
|
+
reason: reason)
|
|
1432
|
+
evaluation_cache[dep_flag_key] = nil if cacheable.call(error: error)
|
|
1433
|
+
raise error
|
|
1434
|
+
ensure
|
|
1435
|
+
dependency_evaluation.exit_flag
|
|
1436
|
+
end
|
|
1437
|
+
|
|
1438
|
+
evaluation_cache[dep_flag_key] = dep_result if cacheable.call(value: dep_result)
|
|
1439
|
+
dep_result
|
|
1323
1440
|
end
|
|
1324
1441
|
|
|
1325
1442
|
def self.matches_dependency_value(expected_value, actual_value)
|
|
@@ -1353,6 +1470,26 @@ module PostHog
|
|
|
1353
1470
|
false
|
|
1354
1471
|
end
|
|
1355
1472
|
|
|
1473
|
+
def self.feature_enrollment?(flag)
|
|
1474
|
+
(flag[:filters] || {})[:feature_enrollment] == true
|
|
1475
|
+
end
|
|
1476
|
+
|
|
1477
|
+
# An early-access feature flag resolves to the person's enrollment: only true or "true" means enrolled,
|
|
1478
|
+
# and any other present value, nil included, means opted out. Without the property only /flags knows
|
|
1479
|
+
# the stored enrollment.
|
|
1480
|
+
def self.feature_enrolled?(flag, person_properties)
|
|
1481
|
+
enrollment_key = "$feature_enrollment/#{flag[:key]}"
|
|
1482
|
+
enrollment = person_properties.fetch(enrollment_key.to_sym) do
|
|
1483
|
+
person_properties.fetch(enrollment_key) do
|
|
1484
|
+
raise InconclusiveMatchError.new(
|
|
1485
|
+
"Flag has feature enrollment and '#{enrollment_key}' was not passed",
|
|
1486
|
+
reason: UnresolvedFlagReason::MISSING_CONTEXT
|
|
1487
|
+
)
|
|
1488
|
+
end
|
|
1489
|
+
end
|
|
1490
|
+
[true, 'true'].include?(enrollment)
|
|
1491
|
+
end
|
|
1492
|
+
|
|
1356
1493
|
# The unresolved reason that comes from the flag's definition alone, so it is known when
|
|
1357
1494
|
# definitions load. Matches the reason local evaluation reports for the same cause.
|
|
1358
1495
|
def self.definition_unresolved_reason(flag, flags_by_key, cohorts, group_type_mapping)
|
|
@@ -1360,6 +1497,9 @@ module PostHog
|
|
|
1360
1497
|
return UnresolvedFlagReason::EXPERIENCE_CONTINUITY if flag[:ensure_experience_continuity]
|
|
1361
1498
|
|
|
1362
1499
|
flag_filters = flag[:filters] || {}
|
|
1500
|
+
# Enrollment decides the flag before its group aggregation and release conditions are read.
|
|
1501
|
+
return nil if feature_enrollment?(flag)
|
|
1502
|
+
|
|
1363
1503
|
aggregation = flag_filters[:aggregation_group_type_index]
|
|
1364
1504
|
if !aggregation.nil? && group_type_mapping[aggregation.to_s.to_sym].nil?
|
|
1365
1505
|
return UnresolvedFlagReason::UNSUPPORTED_DEFINITION
|
|
@@ -1389,7 +1529,11 @@ module PostHog
|
|
|
1389
1529
|
end
|
|
1390
1530
|
return "Circular dependency detected for flag '#{key}'" if dependency_chain.empty?
|
|
1391
1531
|
|
|
1392
|
-
missing_dependency =
|
|
1532
|
+
missing_dependency = if flags_by_key[property[:key]].nil?
|
|
1533
|
+
key
|
|
1534
|
+
else
|
|
1535
|
+
dependency_chain.find { |dep_flag_key| flags_by_key[dep_flag_key].nil? }
|
|
1536
|
+
end
|
|
1393
1537
|
return nil if missing_dependency.nil?
|
|
1394
1538
|
|
|
1395
1539
|
"Cannot evaluate flag dependency '#{missing_dependency}' - flag not found in local flags"
|
|
@@ -1468,6 +1612,10 @@ module PostHog
|
|
|
1468
1612
|
reason: UnresolvedFlagReason::EXPERIENCE_CONTINUITY)
|
|
1469
1613
|
end
|
|
1470
1614
|
|
|
1615
|
+
person_properties ||= {}
|
|
1616
|
+
# Enrollment is a person property, so group-aggregated flags read it from the person too.
|
|
1617
|
+
return self.class.feature_enrolled?(flag, person_properties) if self.class.feature_enrollment?(flag)
|
|
1618
|
+
|
|
1471
1619
|
# Create evaluation cache for flag dependencies
|
|
1472
1620
|
evaluation_cache = {}
|
|
1473
1621
|
|
|
@@ -1475,13 +1623,14 @@ module PostHog
|
|
|
1475
1623
|
|
|
1476
1624
|
aggregation_group_type_index = flag_filters[:aggregation_group_type_index]
|
|
1477
1625
|
if aggregation_group_type_index.nil?
|
|
1478
|
-
local_person_properties = person_properties
|
|
1626
|
+
local_person_properties = person_properties
|
|
1479
1627
|
unless local_person_properties.key?(:distinct_id) || local_person_properties.key?('distinct_id')
|
|
1480
1628
|
local_person_properties = local_person_properties.merge(distinct_id: distinct_id)
|
|
1481
1629
|
end
|
|
1482
1630
|
|
|
1483
1631
|
return match_feature_flag_properties(flag, distinct_id, local_person_properties, evaluation_cache,
|
|
1484
1632
|
snapshot[:cohorts], groups: groups, group_properties: group_properties,
|
|
1633
|
+
person_properties: person_properties,
|
|
1485
1634
|
snapshot: snapshot)
|
|
1486
1635
|
end
|
|
1487
1636
|
|
|
@@ -1508,7 +1657,7 @@ module PostHog
|
|
|
1508
1657
|
focused_group_properties = group_properties[group_name_symbol]
|
|
1509
1658
|
match_feature_flag_properties(flag, groups[group_name_symbol], focused_group_properties, evaluation_cache,
|
|
1510
1659
|
snapshot[:cohorts], groups: groups, group_properties: group_properties,
|
|
1511
|
-
snapshot: snapshot)
|
|
1660
|
+
person_properties: person_properties, snapshot: snapshot)
|
|
1512
1661
|
end
|
|
1513
1662
|
|
|
1514
1663
|
def _compute_flag_payload_locally(key, match_value, snapshot: _evaluation_snapshot)
|
|
@@ -1524,8 +1673,12 @@ module PostHog
|
|
|
1524
1673
|
response
|
|
1525
1674
|
end
|
|
1526
1675
|
|
|
1676
|
+
# person_properties defaults to properties, which hold the person's properties unless the flag is
|
|
1677
|
+
# group-aggregated. Flag dependencies read feature enrollment from them.
|
|
1527
1678
|
def match_feature_flag_properties(flag, distinct_id, properties, evaluation_cache, cohort_properties = {},
|
|
1528
|
-
groups: {}, group_properties: {},
|
|
1679
|
+
groups: {}, group_properties: {}, person_properties: properties,
|
|
1680
|
+
snapshot: _evaluation_snapshot, dependency_evaluation: nil)
|
|
1681
|
+
dependency_evaluation ||= DependencyEvaluation.new(flag[:key])
|
|
1529
1682
|
flag_filters = flag[:filters] || {}
|
|
1530
1683
|
|
|
1531
1684
|
# Holdouts precede release conditions: a held-out identifier is excluded from
|
|
@@ -1577,7 +1730,9 @@ module PostHog
|
|
|
1577
1730
|
end
|
|
1578
1731
|
|
|
1579
1732
|
case condition_match_outcome(flag, effective_bucketing, condition, effective_properties, evaluation_cache,
|
|
1580
|
-
cohort_properties,
|
|
1733
|
+
cohort_properties, person_properties: person_properties,
|
|
1734
|
+
snapshot: snapshot,
|
|
1735
|
+
dependency_evaluation: dependency_evaluation)
|
|
1581
1736
|
when :match
|
|
1582
1737
|
variant_override = condition[:variant]
|
|
1583
1738
|
flag_multivariate = flag_filters[:multivariate] || {}
|
|
@@ -1638,7 +1793,8 @@ module PostHog
|
|
|
1638
1793
|
# Distinguishing :no_match from :out_of_rollout_bound lets the caller implement the
|
|
1639
1794
|
# early_exit behavior (mirrors the server-side Rust evaluation engine).
|
|
1640
1795
|
def condition_match_outcome(flag, distinct_id, condition, properties, evaluation_cache, cohort_properties = {},
|
|
1641
|
-
snapshot: _evaluation_snapshot
|
|
1796
|
+
person_properties: properties, snapshot: _evaluation_snapshot,
|
|
1797
|
+
dependency_evaluation: nil)
|
|
1642
1798
|
rollout_percentage = condition[:rollout_percentage]
|
|
1643
1799
|
|
|
1644
1800
|
unless (condition[:properties] || []).empty?
|
|
@@ -1650,7 +1806,8 @@ module PostHog
|
|
|
1650
1806
|
matches =
|
|
1651
1807
|
if prop[:type] == 'flag'
|
|
1652
1808
|
evaluate_flag_dependency(prop, evaluation_cache, distinct_id, properties, cohort_properties,
|
|
1653
|
-
snapshot: snapshot
|
|
1809
|
+
person_properties: person_properties, snapshot: snapshot,
|
|
1810
|
+
dependency_evaluation: dependency_evaluation)
|
|
1654
1811
|
else
|
|
1655
1812
|
FeatureFlagsPoller.match_property(prop, properties, cohort_properties,
|
|
1656
1813
|
property_matching_version: snapshot[:property_matching_version])
|
data/lib/posthog/version.rb
CHANGED