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()); } }
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; }
/** * @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; }
/** * @return null|\SplitIO\Component\Cache\Pool */ public static function cache() { return Di::getCache(); }
/** * @param $key * @return mixed|string */ public function getLatencyAndReset($key) { return Di::getCache()->getSet($key, 0); }
/** * @param $segmentName * @return mixed */ public function getChangeNumber($segmentName) { $since = Di::getCache()->getItem(self::getCacheKeyForSinceParameter($segmentName))->get(); return empty($since) ? -1 : $since; }
/** * @param $key * @return mixed */ private function get($key) { $item = Di::getCache()->getItem($key); $checkpoint = $item->get(); return empty($checkpoint) ? -1 : (int) $checkpoint; }
/** * @param string $splitName * @return string JSON representation */ public function getSplit($splitName) { $cache = Di::getCache(); $cacheItem = $cache->getItem(self::getCacheKeyForSplit($splitName)); return $cacheItem->get(); }
/** * @param $key * @param $value * @return mixed */ public function removeImpression($key, $value) { return Di::getCache()->removeItemOnList($key, $value); }