Skip to content

Commit

Permalink
Merge pull request #220 from splitio/sdks-7438-flag-sets
Browse files Browse the repository at this point in the history
Flag Sets implementation
  • Loading branch information
sanzmauro authored Jan 23, 2024
2 parents 8b3753a + 5d9d551 commit 4d0aef5
Show file tree
Hide file tree
Showing 33 changed files with 1,188 additions and 68 deletions.
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
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 a new optional Flag Sets Filter configuration option. This allows the SDK and Split services to only synchronize the flags in the specified flag sets, avoiding unused or unwanted flags from being synced on the SDK instance, bringing all the benefits from a reduced payload.
- Note: Only applicable when the SDK is in charge of the rollout data synchronization. When not applicable, the SDK will log a warning on init.
- Updated the following SDK manager methods to expose flag sets on flag views.
- Added `defaultTreatment` property 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.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2023 Split Software, Inc.
Copyright © 2024 Split Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
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);
}
}
24 changes: 24 additions & 0 deletions src/SplitIO/Component/Cache/SplitCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class SplitCache implements SplitCacheInterface

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

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

private static function getCacheKeyForSinceParameter()
{
return self::KEY_TILL_CACHED_ITEM;
Expand All @@ -26,6 +28,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 @@ -79,6 +86,23 @@ 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;
}
$cache = Di::getCache();
foreach ($flagSets as $flagSet) {
$toReturn[$flagSet] = $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);
}
10 changes: 9 additions & 1 deletion src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace SplitIO\Component\Cache\Storage\Adapter;

use SplitIO\Component\Cache\Storage\Exception\AdapterException;
use SplitIO\Component\Cache\Item;
use SplitIO\Component\Utils as SplitIOUtils;
use SplitIO\Component\Common\Di;

Expand Down Expand Up @@ -248,6 +247,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 = '*')
{
$prefix = null;
Expand Down
19 changes: 16 additions & 3 deletions src/SplitIO/Component/Cache/Storage/Adapter/SafeRedisWrapper.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
namespace SplitIO\Component\Cache\Storage\Adapter;

use SplitIO\Component\Cache\Storage\Exception\AdapterException;
use SplitIO\Component\Cache\Item;
use SplitIO\Component\Utils as SplitIOUtils;
use SplitIO\Component\Common\Di;

/**
Expand Down Expand Up @@ -126,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) {
Di::getLogger()->critical("An error occurred performing SMEMBERS for " . $key);
Di::getLogger()->critical($e->getMessage());
Di::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

0 comments on commit 4d0aef5

Please sign in to comment.