Skip to content

Task/flagsetsinto mf #222

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

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
- BREAKING CHANGE: Removed support from versions older than PHP 7.4.
- BREAKING CHANGE: Added support for Multiple Factory Instantiation.

7.2.0 (Jan 24, 2024)
- Added support for Flag Sets on the SDK, which enables grouping feature flags and interacting with the group rather than individually (more details in our documentation):
- Added new variations of the get treatment methods to support evaluating flags in given flag set/s.
- getTreatmentsByFlagSet and getTreatmentsByFlagSets
- getTreatmentWithConfigByFlagSets and getTreatmentsWithConfigByFlagSets
- Added `defaultTreatment` and `sets` properties to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager.

7.1.8 (Jul 24, 2023)
- Fixed input validation for empty keys.

7.1.7 (May 16, 2023)
- Updated terminology on the SDKs codebase to be more aligned with current standard without causing a breaking change. The core change is the term split for feature flag on things like logs and phpdoc comments.
- Fixed php 8.2 warnings in code.
Expand Down
5 changes: 5 additions & 0 deletions src/SplitIO/Component/Cache/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public function expireKey($key, $ttl)
{
return $this->adapter->expireKey($key, $ttl);
}

public function sMembers($key)
{
return $this->adapter->sMembers($key);
}
}
23 changes: 23 additions & 0 deletions src/SplitIO/Component/Cache/SplitCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class SplitCache implements SplitCacheInterface

const KEY_TRAFFIC_TYPE_CACHED = 'SPLITIO.trafficType.{trafficTypeName}';

const KEY_FLAG_SET_CACHED = 'SPLITIO.flagSet.{set}';

/**
* @var \SplitIO\Component\Cache\Pool
*/
Expand Down Expand Up @@ -37,6 +39,11 @@ private static function getCacheKeyForSplit($splitName)
return str_replace('{splitName}', $splitName, self::KEY_SPLIT_CACHED_ITEM);
}

private static function getCacheKeyForFlagSet($flagSet)
{
return str_replace('{set}', $flagSet, self::KEY_FLAG_SET_CACHED);
}

private static function getSplitNameFromCacheKey($key)
{
$cacheKeyPrefix = self::getCacheKeyForSplit('');
Expand Down Expand Up @@ -87,6 +94,22 @@ public function getSplitNames()
return array_map([self::class, 'getSplitNameFromCacheKey'], $splitKeys);
}

/**
* @param array(string) List of flag set names
* @return array(string) List of all feature flag names by flag sets
*/
public function getNamesByFlagSets($flagSets)
{
$toReturn = array();
if (empty($flagSets)) {
return $toReturn;
}
foreach ($flagSets as $flagSet) {
$toReturn[$flagSet] = $this->cache->sMembers(self::getCacheKeyForFlagSet($flagSet));
}
return $toReturn;
}

/**
* @return array(string) List of all split JSON strings
*/
Expand Down
6 changes: 6 additions & 0 deletions src/SplitIO/Component/Cache/SplitCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ public function getChangeNumber();
* @return string JSON representation
*/
public function getSplit($splitName);

/**
* @param array(string) List of flag set names
* @return array(string) List of all feature flag names by flag sets
*/
public function getNamesByFlagSets($flagSets);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public function rightPushQueue($queueName, $item);
* @return boolean
*/
public function expireKey($key, $ttl);

/**
* @param string $key
* @return mixed
*/
public function sMembers($key);
}
9 changes: 9 additions & 0 deletions src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ public function isOnList($key, $value)
return $this->client->sIsMember($key, $value);
}

/**
* @param string $key
* @return mixed
*/
public function sMembers($key)
{
return $this->client->smembers($key);
}

public function getKeys($pattern = '*')
{
$keys = $this->client->keys($pattern);
Expand Down
16 changes: 16 additions & 0 deletions src/SplitIO/Component/Cache/Storage/Adapter/SafeRedisWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,20 @@ public function expireKey($key, $ttl)
return false;
}
}

/**
* @param string $key
* @return mixed
*/
public function sMembers($key)
{
try {
return $this->cacheAdapter->sMembers($key);
} catch (\Exception $e) {
Context::getLogger()->critical("An error occurred performing SMEMBERS for " . $key);
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return array();
}
}
}
10 changes: 10 additions & 0 deletions src/SplitIO/Grammar/Split.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Split
private $trafficAllocationSeed = null;

private $configurations = null;
private $sets = null;

public function __construct(array $split)
{
Expand All @@ -50,6 +51,7 @@ public function __construct(array $split)
$split['trafficAllocationSeed'] : null;
$this->configurations = isset($split['configurations']) && count($split['configurations']) > 0 ?
$split['configurations'] : null;
$this->sets = isset($split['sets']) ? $split['sets'] : array();

SplitApp::logger()->info("Constructing Feature Flag: ".$this->name);

Expand Down Expand Up @@ -167,4 +169,12 @@ public function getConfigurations()
{
return $this->configurations;
}

/**
* @return array|null
*/
public function getSets()
{
return $this->sets;
}
}
5 changes: 0 additions & 5 deletions src/SplitIO/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

class Metrics
{
const MNAME_SDK_GET_TREATMENT = 'sdk.getTreatment';
const MNAME_SDK_GET_TREATMENT_WITH_CONFIG = 'sdk.getTreatmentWithConfig';
const MNAME_SDK_GET_TREATMENTS = 'sdk.getTreatments';
const MNAME_SDK_GET_TREATMENTS_WITH_CONFIG = 'sdk.getTreatmentsWithConfig';

public static function startMeasuringLatency()
{
return Latency::startMeasuringLatency();
Expand Down
Loading