Пример #1
0
        public SplitView Split(string featureName)
        {
            if (splitCache == null)
            {
                return(null);
            }

            var split = (ParsedSplit)splitCache.GetSplit(featureName);

            if (split == null)
            {
                return(null);
            }

            var condition = split.conditions.Where(x => x.conditionType == ConditionType.ROLLOUT).FirstOrDefault();

            var treatments = condition != null?condition.partitions.Select(y => y.treatment).ToList() : new List <string>();

            var lightSplit = new SplitView()
            {
                name         = split.name,
                killed       = split.killed,
                changeNumber = split.changeNumber,
                treatments   = treatments,
                trafficType  = split.trafficTypeName
            };

            return(lightSplit);
        }
Пример #2
0
        protected virtual TreatmentResult GetTreatmentForFeature(Key key, string feature, Dictionary <string, object> attributes)
        {
            try
            {
                var split = (ParsedSplit)splitCache.GetSplit(feature);

                if (split == null)
                {
                    _log.Warn($"GetTreatment: you passed {feature} that does not exist in this environment, please double check what Splits exist in the web console.");

                    return(new TreatmentResult(LabelSplitNotFound, Control, null));
                }

                var treatmentResult = GetTreatment(key, split, attributes, this);

                if (split.configurations != null && split.configurations.ContainsKey(treatmentResult.Treatment))
                {
                    treatmentResult.Config = split.configurations[treatmentResult.Treatment];
                }

                return(treatmentResult);
            }
            catch (Exception e)
            {
                _log.Error($"Exception caught getting treatment for feature: {feature}", e);

                return(new TreatmentResult(LabelException, Control, null));
            }
        }
Пример #3
0
        public TreatmentResult EvaluateFeature(Key key, string featureName, Dictionary <string, object> attributes = null)
        {
            var clock = new Stopwatch();

            clock.Start();

            try
            {
                var parsedSplit = _splitCache.GetSplit(featureName);

                return(EvaluateTreatment(key, parsedSplit, featureName, clock, attributes));
            }
            catch (Exception e)
            {
                _log.Error($"Exception caught getting treatment for feature: {featureName}", e);

                return(new TreatmentResult(Labels.Exception, Control, elapsedMilliseconds: clock.ElapsedMilliseconds));
            }
        }
Пример #4
0
        public SplitView Split(string featureName)
        {
            if (!IsSdkReady(nameof(Split)) || _splitCache == null)
            {
                return(null);
            }

            var result = _splitNameValidator.SplitNameIsValid(featureName, nameof(Split));

            if (!result.Success)
            {
                return(null);
            }

            featureName = result.Value;

            var split = _splitCache.GetSplit(featureName);

            if (split == null)
            {
                _log.Warn($"split: you passed {featureName} that does not exist in this environment, please double check what Splits exist in the web console.");

                return(null);
            }

            var condition = split.conditions.Where(x => x.conditionType == ConditionType.ROLLOUT).FirstOrDefault() ?? split.conditions.FirstOrDefault();

            var treatments = condition != null?condition.partitions.Select(y => y.treatment).ToList() : new List <string>();

            var lightSplit = new SplitView()
            {
                name         = split.name,
                killed       = split.killed,
                changeNumber = split.changeNumber,
                treatments   = treatments,
                trafficType  = split.trafficTypeName,
                configs      = split.configurations
            };

            return(lightSplit);
        }
Пример #5
0
        protected virtual string GetTreatmentForFeature(Key key, string feature, Dictionary <string, object> attributes, bool logMetricsAndImpressions = true)
        {
            long start = CurrentTimeHelper.CurrentTimeMillis();
            var  clock = new Stopwatch();

            clock.Start();

            try
            {
                var split = (ParsedSplit)splitCache.GetSplit(feature);

                if (split == null)
                {
                    if (logMetricsAndImpressions)
                    {
                        //if split definition was not found, impression label = "rules not found"
                        RecordStats(key, feature, null, LabelSplitNotFound, start, Control, SdkGetTreatment, clock);
                    }

                    Log.Warn(string.Format("Unknown or invalid feature: {0}", feature));

                    return(Control);
                }

                var treatment = GetTreatment(key, split, attributes, start, clock, this, logMetricsAndImpressions);

                return(treatment);
            }
            catch (Exception e)
            {
                if (logMetricsAndImpressions)
                {
                    //if there was an exception, impression label = "exception"
                    RecordStats(key, feature, null, LabelException, start, Control, SdkGetTreatment, clock);
                }

                Log.Error(string.Format("Exception caught getting treatment for feature: {0}", feature), e);
                return(Control);
            }
        }
Пример #6
0
        public SplitView Split(string featureName)
        {
            if (!IsSdkReady(nameof(Split)) || _splitCache == null)
            {
                return(null);
            }

            var result = _splitNameValidator.SplitNameIsValid(featureName, nameof(Split));

            if (!result.Success)
            {
                return(null);
            }

            featureName = result.Value;

            var split = (Split)_splitCache.GetSplit(featureName);

            if (split == null)
            {
                return(null);
            }

            var condition = split.conditions.Where(x => x.conditionType.ToUpper() == "ROLLOUT").FirstOrDefault();

            var treatments = condition != null?condition.partitions.Select(y => y.treatment).ToList() : new List <string>();

            var lightSplit = new SplitView()
            {
                name         = split.name,
                killed       = split.killed,
                changeNumber = split.changeNumber,
                treatments   = treatments,
                trafficType  = split.trafficTypeName,
                configs      = split.configurations
            };

            return(lightSplit);
        }