Module: Featurevisor::Bucketer
- Defined in:
- lib/featurevisor/bucketer.rb
Overview
Bucketer module for handling feature flag bucketing
Constant Summary collapse
- MAX_BUCKETED_NUMBER =
Maximum bucketed number (100% * 1000 to include three decimal places)
100_000- HASH_SEED =
Hash seed for consistent bucketing
1- MAX_HASH_VALUE =
Maximum hash value for 32-bit integers
2**32
- DEFAULT_BUCKET_KEY_SEPARATOR =
Default separator for bucket keys
"."
Class Method Summary collapse
-
.get_bucket_key(options) ⇒ String
Get bucket key from feature configuration and context.
-
.get_bucketed_number(bucket_key) ⇒ Integer
Get bucketed number from a bucket key.
Class Method Details
.get_bucket_key(options) ⇒ String
Get bucket key from feature configuration and context
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/featurevisor/bucketer.rb', line 36 def self.get_bucket_key() feature_key = [:feature_key] bucket_by = [:bucket_by] context = [:context] logger = [:logger] type, attribute_keys = parse_bucket_by(bucket_by, logger, feature_key) bucket_key = build_bucket_key(attribute_keys, context, type, feature_key) bucket_key.join(DEFAULT_BUCKET_KEY_SEPARATOR) end |
.get_bucketed_number(bucket_key) ⇒ Integer
Get bucketed number from a bucket key
21 22 23 24 25 26 |
# File 'lib/featurevisor/bucketer.rb', line 21 def self.get_bucketed_number(bucket_key) hash_value = Featurevisor.murmur_hash_v3(bucket_key, HASH_SEED) ratio = hash_value.to_f / MAX_HASH_VALUE (ratio * MAX_BUCKETED_NUMBER).floor end |