Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        internal async Task RefreshTargets()
        {
            List <SamplingRule> rules = GetCandidates();

            if (rules == null || rules.Count == 0)
            {
                _logger.DebugFormat("There is no sampling rule statistics to report, skipping.");
                return;
            }
            _logger.DebugFormat("Reporting rule statistics to get new quota.");
            GetSamplingTargetsResponse response = await _connector.GetSamplingTargets(rules);

            _ruleCache.LoadTargets(response.Targets);

            if (response.RuleFreshness.IsGreaterThan(_ruleCache.LastUpdated))
            {
                _logger.InfoFormat("Performing out-of-band sampling rule polling to fetch updated rules.");
                _rulePoller.WakeUp();
            }
        }