private TreatmentResult GetTreatmentResult(Key key, string feature, string operation, string method, Dictionary <string, object> attributes = null) { if (!IsClientReady(method)) { return(new TreatmentResult(string.Empty, Control, null)); } if (!_keyValidator.IsValid(key, method)) { return(new TreatmentResult(string.Empty, Control, null)); } var splitNameResult = _splitNameValidator.SplitNameIsValid(feature, method); if (!splitNameResult.Success) { return(new TreatmentResult(string.Empty, Control, null)); } feature = splitNameResult.Value; var result = _evaluator.EvaluateFeature(key, feature, attributes); if (_metricsLog != null) { _metricsLog.Time(operation, result.ElapsedMilliseconds); } if (!Labels.SplitNotFound.Equals(result.Label)) { _impressionsManager.BuildAndTrack(key.matchingKey, feature, result.Treatment, CurrentTimeHelper.CurrentTimeMillis(), result.ChangeNumber, LabelsEnabled ? result.Label : null, key.bucketingKeyHadValue ? key.bucketingKey : null); } return(result); }
private Dictionary <string, TreatmentResult> GetTreatmentsResult(Key key, List <string> features, string operation, string method, Dictionary <string, object> attributes = null) { var treatmentsForFeatures = new Dictionary <string, TreatmentResult>(); if (!IsClientReady(method)) { foreach (var feature in features) { treatmentsForFeatures.Add(feature, new TreatmentResult(LabelClientNotReady, Control, null)); } return(treatmentsForFeatures); } var ImpressionsQueue = new List <KeyImpression>(); if (_keyValidator.IsValid(key, method)) { features = _splitNameValidator.SplitNamesAreValid(features, method); var start = CurrentTimeHelper.CurrentTimeMillis(); var clock = new Stopwatch(); clock.Start(); foreach (var feature in features) { var treatmentResult = DoGetTreatment(key, feature, attributes, true); treatmentsForFeatures.Add(feature, treatmentResult); if (!LabelSplitNotFound.Equals(treatmentResult.Label)) { ImpressionsQueue.Add(BuildImpression(key.matchingKey, feature, treatmentResult.Treatment, start, treatmentResult.ChangeNumber, LabelsEnabled ? treatmentResult.Label : null, key.bucketingKeyHadValue ? key.bucketingKey : null)); } } if (metricsLog != null) { metricsLog.Time(operation, clock.ElapsedMilliseconds); } ImpressionLog(ImpressionsQueue); } else { foreach (var feature in features) { treatmentsForFeatures.Add(feature, new TreatmentResult(LabelSplitNotFound, Control, null)); } } ClearItemsAddedToTreatmentCache(key?.matchingKey); return(treatmentsForFeatures); }
public void Time(string operation, long miliseconds) { try { var task = new Task(() => worker.Time(operation, miliseconds)); task.Start(); } catch (Exception e) { Logger.Error("Exception running time metrics task", e); } }
protected void RecordStats(Key key, string feature, long?changeNumber, string label, long start, string treatment, string operation, Stopwatch clock) { if (metricsLog != null) { metricsLog.Time(SdkGetTreatment, clock.ElapsedMilliseconds); } if (impressionListener != null) { KeyImpression impression = BuildImpression(key.matchingKey, feature, treatment, start, changeNumber, LabelsEnabled ? label : null, key.bucketingKeyHadValue ? key.bucketingKey : null); impressionListener.Log(impression); } }