예제 #1
0
        /// <summary>
        /// Use X-Ray client to get the sampling rules
        /// from X-Ray service.The call is proxied and signed by X-Ray Daemon.
        /// </summary>
        /// <returns></returns>
        public async Task <GetSamplingRulesResponse> GetSamplingRules()
        {
            List <SamplingRule>     newRules = new List <SamplingRule>();
            GetSamplingRulesRequest request  = new GetSamplingRulesRequest();

            Task <Model.GetSamplingRulesResponse> responseTask;

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

            foreach (var record in response.SamplingRuleRecords)
            {
                var rule = record.SamplingRule;
                if (rule.Version == Version && SamplingRule.IsValid(rule)) // We currently only handle v1 sampling rules.
                {
                    var sampleRule = new SamplingRule(rule.RuleName, rule.Priority, rule.FixedRate, rule.ReservoirSize, rule.Host, rule.ServiceName, rule.HTTPMethod, rule.URLPath, rule.ServiceType, rule.ResourceARN, rule.Attributes);
                    newRules.Add(sampleRule);
                }
            }

            GetSamplingRulesResponse result = new GetSamplingRulesResponse(newRules);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Gets sampling rules from the X-Ray service ans populates <see cref="RuleCache"/>.
        /// </summary>
        /// <returns>Task instance.</returns>
        private async Task RefreshCache()
        {
            TimeStamp time = TimeStamp.CurrentTime();
            GetSamplingRulesResponse response = await _connector.GetSamplingRules();

            if (response.IsRulePresent())
            {
                _ruleCache.LoadRules(response.Rules);
                _ruleCache.LastUpdated = time;
                _logger.InfoFormat("Successfully refreshed sampling rule cache.");
            }
        }
        /// <summary>
        /// Get the sampling rules from X-Ray service.The call is proxied and signed by X-Ray Daemon.
        /// </summary>
        /// <returns></returns>
        public async Task <GetSamplingRulesResponse> GetSamplingRules()
        {
            Task <string> responseTask;

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

            List <SamplingRule> samplingRules = UnmarshallSamplingRuleResponse(responseContent);

            GetSamplingRulesResponse result = new GetSamplingRulesResponse(samplingRules);

            return(result);
        }