/// <summary>
        /// Report the current statistics of sampling rules and
        /// get back the new assigned quota/TTL/Interval from the X-Ray service.
        /// The call is proxied and signed via X-Ray Daemon.
        /// </summary>
        /// <param name="rules">List of <see cref="SamplingRule"/>.</param>
        /// <returns>Instance of <see cref="GetSamplingRulesResponse"/>.</returns>
        public async Task <GetSamplingTargetsResponse> GetSamplingTargets(List <SamplingRule> rules)
        {
            DateTime currentTime = TimeStamp.CurrentDateTime();
            List <SamplingStatisticsDocumentModel> samplingStatisticsDocumentModels = GetSamplingStatisticsDocuments(rules, currentTime);
            var samplingStatisticsModel = new SamplingStatisticsModel();

            samplingStatisticsModel.SamplingStatisticsDocuments = samplingStatisticsDocumentModels;

            string requestContent = JsonMapper.ToJson(samplingStatisticsModel); // Marshall SamplingStatisticsDocument to json

            Task <string> responseTask;

            lock (_xrayClientLock)
            {
                RefreshEndPoint();
                responseTask = GetSamplingInfoAsync(_xrayConfig.ServiceURL + "/SamplingTargets", requestContent);
            }
            var responseContent = await responseTask;

            var samplingTargetResponse = UnmarshallSamplingTargetResponse(responseContent);

            var targetList = ConvertTargetList(samplingTargetResponse.SamplingTargetDocuments);

            GetSamplingTargetsResponse result = new GetSamplingTargetsResponse(targetList);

            result.RuleFreshness = new TimeStamp(ConvertDoubleToDateTime(samplingTargetResponse.LastRuleModification));
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Report the current statistics of sampling rules and
        /// get back the new assigned quota/TTL/Interval from the X-Ray service.
        /// The call is proxied and signed via X-Ray Daemon.
        /// </summary>
        /// <param name="rules">List of <see cref="SamplingRule"/>.</param>
        /// <returns>Instance of <see cref="GetSamplingRulesResponse"/>.</returns>
        public async Task <GetSamplingTargetsResponse> GetSamplingTargets(List <SamplingRule> rules)
        {
            GetSamplingTargetsRequest request    = new GetSamplingTargetsRequest();
            IList <Target>            newTargets = new List <Target>();
            DateTime currentTime = TimeStamp.CurrentDateTime();
            List <SamplingStatisticsDocument> samplingStatisticsDocuments = GetSamplingStatisticsDocuments(rules, currentTime);

            request.SamplingStatisticsDocuments = samplingStatisticsDocuments;
            Task <Model.GetSamplingTargetsResponse> responseTask;

            lock (_xrayClientLock)
            {
                RefreshEndPoint();
                responseTask = _xrayClient.GetSamplingTargetsAsync(request);
            }
            var response = await responseTask;

            foreach (var record in response.SamplingTargetDocuments)
            {
                Target t = new Target(record.RuleName, record.FixedRate, record.ReservoirQuota, record.ReservoirQuotaTTL, record.Interval);
                newTargets.Add(t);
            }

            GetSamplingTargetsResponse result = new GetSamplingTargetsResponse(newTargets);

            result.RuleFreshness = new TimeStamp(response.LastRuleModification);
            return(result);
        }