コード例 #1
0
 public function sendMetrics()
 {
     $metricsKeys = Di::getCache()->getKeys(MetricsCache::getCacheKeySearchLatencyPattern());
     $metricsCache = new MetricsCache();
     $cachedMetrics = array();
     foreach ($metricsKeys as $key) {
         $metricName = MetricsCache::getMetricNameFromKey($key);
         $metricBucket = MetricsCache::getBucketFromKey($key);
         if (!isset($cachedMetrics[$metricName]) || !is_array($cachedMetrics[$metricName])) {
             //initialization latency butckets
             $maxBucket = Latency::getBucketForLatencyMicros(Latency::MAX_LATENCY);
             $cachedMetrics[$metricName] = array_fill(0, $maxBucket + 1, 0);
         }
         $cachedMetrics[$metricName][$metricBucket] = $metricsCache->getLatencyAndReset($key);
     }
     $dataset = array();
     foreach ($cachedMetrics as $name => $latencies) {
         $dataset[] = array('name' => $name, 'latencies' => $latencies);
     }
     //Sending Metrics dataset.
     $response = $this->post($this->servicePath, $dataset);
     if ($response->isSuccessful()) {
         Di::getLogger()->info(count($dataset) . " Metrics sent successfuly");
     } else {
         Di::getLogger()->error("Metrics have not been sent successfully");
         Di::getLogger()->error("HTTP Code: " . $response->getStatusCode());
         Di::getLogger()->error("HTTP Body: " . $response->getBody());
     }
 }
コード例 #2
0
 public function sendTestImpressions($keyImpressionsPerTest)
 {
     $impressionKeys = Di::getCache()->getKeys(ImpressionCache::getCacheKeySearchPattern());
     $impressionCache = new ImpressionCache();
     $toDrop = array();
     $dataset = array();
     $totalImpressions = 0;
     foreach ($impressionKeys as $key) {
         $featureName = ImpressionCache::getFeatureNameFromKey($key);
         $cachedImpressions = $impressionCache->getRandomImpressions($key, $keyImpressionsPerTest);
         if (empty($cachedImpressions)) {
             continue;
         }
         $toDrop[$key] = $cachedImpressions;
         $impressions = array();
         $cachedImpressionsCount = count($cachedImpressions);
         $totalImpressions += $cachedImpressionsCount;
         for ($i = 0; $i < $cachedImpressionsCount; $i++) {
             //restoring cached impressions from JSON string to PHP Array.
             $impressions[$i] = json_decode($cachedImpressions[$i], true);
         }
         //Bulk data set
         $dataset[] = array('testName' => $featureName, 'keyImpressions' => $impressions);
     }
     //Sending Impressions dataset.
     $response = $this->post($this->servicePath, $dataset);
     //Dropping impressions
     $this->dropDataset($toDrop);
     if ($response->isSuccessful()) {
         Di::getLogger()->info($totalImpressions . " Impressions sent successfuly");
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: SplitManager.php プロジェクト: splitio/php-client
 /**
  * @return array
  */
 public function splits()
 {
     $_splits = array();
     $splitKeys = Di::getCache()->getKeys(SplitCache::getCacheKeySearchPattern());
     foreach ($splitKeys as $key) {
         $splitView = $this->getSplitByCacheKey($key);
         if ($splitView != null) {
             $_splits[] = $splitView;
         }
     }
     return $_splits;
 }
コード例 #4
0
ファイル: Split.php プロジェクト: splitio/php-client
 /**
  * @return null|\SplitIO\Component\Cache\Pool
  */
 public static function cache()
 {
     return Di::getCache();
 }
コード例 #5
0
ファイル: MetricsCache.php プロジェクト: splitio/php-client
 /**
  * @param $key
  * @return mixed|string
  */
 public function getLatencyAndReset($key)
 {
     return Di::getCache()->getSet($key, 0);
 }
コード例 #6
0
ファイル: SegmentCache.php プロジェクト: splitio/php-client
 /**
  * @param $segmentName
  * @return mixed
  */
 public function getChangeNumber($segmentName)
 {
     $since = Di::getCache()->getItem(self::getCacheKeyForSinceParameter($segmentName))->get();
     return empty($since) ? -1 : $since;
 }
コード例 #7
0
 /**
  * @param $key
  * @return mixed
  */
 private function get($key)
 {
     $item = Di::getCache()->getItem($key);
     $checkpoint = $item->get();
     return empty($checkpoint) ? -1 : (int) $checkpoint;
 }
コード例 #8
0
ファイル: SplitCache.php プロジェクト: splitio/php-client
 /**
  * @param string $splitName
  * @return string JSON representation
  */
 public function getSplit($splitName)
 {
     $cache = Di::getCache();
     $cacheItem = $cache->getItem(self::getCacheKeyForSplit($splitName));
     return $cacheItem->get();
 }
コード例 #9
0
 /**
  * @param $key
  * @param $value
  * @return mixed
  */
 public function removeImpression($key, $value)
 {
     return Di::getCache()->removeItemOnList($key, $value);
 }