Ejemplo n.º 1
0
 public override bool Match(Key key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
 {
     return(Match(key.matchingKey, attributes, splitClient));
 }
Ejemplo n.º 2
0
 public override bool Match(DateTime key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
 {
     return(false);
 }
Ejemplo n.º 3
0
        public override bool Match(DateTime key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
        {
            var date = value.ToDateTime();

            key = key.Truncate(TimeSpan.FromMinutes(1)); // Truncate to whole minute
            return(key.ToUniversalTime() <= date.ToUniversalTime());
        }
Ejemplo n.º 4
0
 public override bool Match(string key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
 {
     return(list.Contains(key));
 }
Ejemplo n.º 5
0
        private void BuildSplitClient()
        {
            _options = _options ?? new ConfigurationOptions();

            if (!_options.Ready.HasValue)
            {
                _log.Warn("no ready parameter has been set - incorrect control treatments could be logged if no ready config has been set when building factory");
            }

            _apiKeyValidator.Validate(_apiKey);

            switch (_options.Mode)
            {
            case Mode.Standalone:
                if (string.IsNullOrEmpty(_apiKey))
                {
                    throw new Exception("API Key should be set to initialize Split SDK.");
                }
                if (_apiKey == "localhost")
                {
                    _client = new LocalhostClient(_options.LocalhostFilePath, _log);
                }
                else
                {
                    _client = new SelfRefreshingClient(_apiKey, _options, _log);
                }
                break;

            case Mode.Consumer:
                if (_options.CacheAdapterConfig != null && _options.CacheAdapterConfig.Type == AdapterType.Redis)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(_options.CacheAdapterConfig.Host) || string.IsNullOrEmpty(_options.CacheAdapterConfig.Port))
                        {
                            throw new Exception("Redis Host and Port should be set to initialize Split SDK in Redis Mode.");
                        }

                        var handle = Activator.CreateInstance("Splitio.Redis", "Splitio.Redis.Services.Client.Classes.RedisClient", false, default(BindingFlags), default(Binder), new object[] { _options, _log, _apiKey }, default(CultureInfo), null);
                        _client = (ISplitClient)handle.Unwrap();
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Splitio.Redis package should be added as reference, to build split client in Redis Consumer mode.", e);
                    }
                }
                else
                {
                    throw new Exception("Redis config should be set to build split client in Consumer mode.");
                }
                break;

            case Mode.Producer:
                throw new Exception("Unsupported mode.");

            default:
                throw new Exception("Mode should be set to build split client.");
            }

            _factoryInstantiationsService.Increase(_apiKey);
        }
Ejemplo n.º 6
0
 public override bool Match(long key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
 {
     return(key <= value);
 }
Ejemplo n.º 7
0
        public override bool Match(DateTime key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
        {
            var date = value.ToDateTime();

            return(date.Date == key.Date); // Compare just date part
        }
Ejemplo n.º 8
0
        protected string GetTreatment(Key key, ParsedSplit split, Dictionary <string, object> attributes, long start, Stopwatch clock, ISplitClient splitClient, bool logMetricsAndImpressions)
        {
            if (!split.killed)
            {
                bool inRollout = false;
                // use the first matching condition
                foreach (ConditionWithLogic condition in split.conditions)
                {
                    if (!inRollout && condition.conditionType == ConditionType.ROLLOUT)
                    {
                        if (split.trafficAllocation < 100)
                        {
                            // bucket ranges from 1-100.
                            int bucket = split.algo == AlgorithmEnum.LegacyHash ? splitter.LegacyBucket(key.bucketingKey, split.trafficAllocationSeed) : splitter.Bucket(key.bucketingKey, split.trafficAllocationSeed);
                            if (bucket >= split.trafficAllocation)
                            {
                                if (logMetricsAndImpressions)
                                {
                                    // If not in traffic allocation, abort and return
                                    // default treatment
                                    RecordStats(key, split.name, split.changeNumber, LabelTrafficAllocationFailed, start, split.defaultTreatment, SdkGetTreatment, clock);
                                }

                                return(split.defaultTreatment);
                            }
                        }
                        inRollout = true;
                    }
                    var combiningMatcher = condition.matcher;
                    if (combiningMatcher.Match(key, attributes, splitClient))
                    {
                        var treatment = splitter.GetTreatment(key.bucketingKey, split.seed, condition.partitions, split.algo);

                        if (logMetricsAndImpressions)
                        {
                            //If condition matched, impression label = condition.label
                            RecordStats(key, split.name, split.changeNumber, condition.label, start, treatment, SdkGetTreatment, clock);
                        }

                        return(treatment);
                    }
                }

                if (logMetricsAndImpressions)
                {
                    //If no condition matched, impression label = "no rule matched"
                    RecordStats(key, split.name, split.changeNumber, LabelNoConditionMatched, start, split.defaultTreatment, SdkGetTreatment, clock);
                }
                return(split.defaultTreatment);
            }
            else
            {
                if (logMetricsAndImpressions)
                {
                    //If split was killed, impression label = "killed"
                    RecordStats(key, split.name, split.changeNumber, LabelKilled, start, split.defaultTreatment, SdkGetTreatment, clock);
                }

                return(split.defaultTreatment);
            }
        }
Ejemplo n.º 9
0
        public bool Match(object value, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
        {
            if (value is bool)
            {
                return(Match((bool)value, attributes, splitClient));
            }
            else if (value is string)
            {
                return(Match((string)value, attributes, splitClient));
            }
            else if (value is DateTime)
            {
                return(Match((DateTime)value, attributes, splitClient));
            }
            else if (value is long)
            {
                return(Match((long)value, attributes, splitClient));
            }
            else if (value is int)
            {
                return(Match((int)value, attributes, splitClient));
            }
            else if (value is List <string> )
            {
                return(Match((List <string>)value, attributes, splitClient));
            }
            else if (value is Key)
            {
                return(Match((Key)value, attributes, splitClient));
            }


            return(false);
        }
Ejemplo n.º 10
0
 public abstract bool Match(bool key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null);
Ejemplo n.º 11
0
 public override bool Match(Key key, Dictionary <string, object> attributes = null, ISplitClient splitClient = null)
 {
     return(segmentsCache.IsInSegment(segmentName, key.matchingKey));
 }