Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string agentVersion = Version.Get();

            var    promitorUserAgent  = UserAgent.Generate("Scraper", agentVersion);
            string openApiDescription = BuildOpenApiDescription(Configuration);

            services.UseWebApi()
            .AddMemoryCache()
            .AddResourceDiscoveryClient(promitorUserAgent)
            .AddAtlassianStatuspageClient(promitorUserAgent, Configuration)
            .AddUsability()
            .AddHttpCorrelation(options => options.UpstreamService.ExtractFromRequest = true)
            .AddAutoMapper(typeof(V1MappingProfile).Assembly)
            .DefineDependencies()
            .AddValidationRules()
            .ConfigureYamlConfiguration(Configuration)
            .UseOpenApiSpecifications("Promitor - Scraper API v1", openApiDescription, 1);

            services.AddHealthChecks()
            .AddResourceDiscoveryHealthCheck(Configuration);

            services.UseMetricSinks(Configuration, _logger)
            .AddScrapingMutex(Configuration)
            .ScheduleMetricScraping();
        }
        protected override HttpRequestMessage BeforeSendingRequest(HttpRequestMessage request)
        {
            string agentVersion      = Version.Get();
            var    promitorUserAgent = UserAgent.Generate("Scraper", agentVersion);

            request.Headers.UserAgent.Clear();
            request.Headers.UserAgent.TryParseAdd(promitorUserAgent);

            return(request);
        }
Пример #3
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            string agentVersion      = Version.Get();
            var    promitorUserAgent = UserAgent.Generate("Scraper", agentVersion);

            request.Headers.UserAgent.TryParseAdd(promitorUserAgent);

            var response = await base.SendAsync(request, cancellationToken);

            await MeasureArmRateLimitingAsync(response);

            if ((int)response.StatusCode == 429)
            {
                LogArmThrottling();
            }

            return(response);
        }