/** * @param $splitCacheKey * @return null|SplitView */ private function getSplitByCacheKey($splitCacheKey) { $splitCachedItem = SplitApp::cache()->getItem($splitCacheKey); if ($splitCachedItem->isHit()) { $splitRepresentation = $splitCachedItem->get(); $split = new Split(json_decode($splitRepresentation, true)); return new SplitView($split->getName(), $split->getTrafficTypeName(), $split->killed(), $split->getTreatments(), $split->getChangeNumber()); } return null; }
private function evalTreatment($matchingKey, $bucketingKey, $featureName, array $attributes = null) { $split = null; $do_evaluation = false; $cachedFeature = $this->getCachedFeature($featureName); if ($cachedFeature !== null) { $split = $cachedFeature; $do_evaluation = true; } else { $splitCacheKey = SplitCache::getCacheKeyForSplit($featureName); $splitCachedItem = SplitApp::cache()->getItem($splitCacheKey); if ($splitCachedItem->isHit()) { SplitApp::logger()->info("{$featureName} is present on cache"); $splitRepresentation = $splitCachedItem->get(); $split = new Split(json_decode($splitRepresentation, true)); $this->cacheFeature($featureName, $split); $do_evaluation = true; } } if ($do_evaluation) { //If the split was killed, log the impression and return default treatment. if ($split->killed()) { $defaultTreatment = $split->getDefaultTratment(); $chn = $split->getChangeNumber(); $this->logImpression($matchingKey, $featureName, $defaultTreatment, ImpressionLabel::KILLED, $chn); return $defaultTreatment; } $timeStart = Metrics::startMeasuringLatency(); $treatment = Engine::getTreatment($matchingKey, $bucketingKey, $split, $attributes); $latency = Metrics::calculateLatency($timeStart); //If the given key doesn't match on any condition, default treatment is returned $impressionLabel = ''; if ($treatment == null) { $treatment = $split->getDefaultTratment(); $impressionLabel = ImpressionLabel::NO_CONDITION_MATCHED; } //Registering latency value MetricsCache::addLatencyOnBucket(Metrics::MNAME_SDK_GET_TREATMENT, Metrics::getBucketForLatencyMicros($latency)); SplitApp::logger()->info("*Treatment for {$matchingKey} in {$split->getName()} is: {$treatment}"); //Logging treatment impressions $this->logImpression($matchingKey, $featureName, $treatment, $impressionLabel, $split->getChangeNumber()); //Returning treatment. return $treatment; } // Split not found impression $this->logImpression($matchingKey, $featureName, TreatmentEnum::CONTROL, ImpressionLabel::SPLIT_NOT_FOUND); SplitApp::logger()->warning("The SPLIT definition for '{$featureName}' has not been found'"); return TreatmentEnum::CONTROL; }